Skip to content

Latest commit

 

History

History
147 lines (102 loc) · 3.66 KB

File metadata and controls

147 lines (102 loc) · 3.66 KB

Installation Steps

Client Setup

Install the gem or add it to your bundler's Gemfile:

gem install daylight

Require and run setup, no options are needed:

  require 'daylight'

  Daylight::API.setup!

This is the same as specifying setup! with the following defaults:

  require 'daylight'

  Daylight::API.setup!({
    namespace: 'API',
    client_id: nil,
    password:  nil,
    endpoint:  'http://localhost',
    version:   'v1',
    versions:  ['v1'],
    timeout:   60
  })

You can customize each of these options:

  • namespace is the module to which you wish ActiveResource client models to belong
  • password supplied in the X-Http-Authentication header to be used for simple authentication
  • endpoint is the URL where your server is running (a synonym for ActiveResource#site)
  • client_id appends value to the X-Request-Id to help identify a request source
  • version is the active version of your API client models
  • version the set of all versions of your API client models
  • timeout the duration in seconds in which to timeout a request

You can customize any combination of these options.

Server Setup

Install the gem or add it to your bundler's Gemfile:

gem install daylight

In an initializer add the Daylight's Rails extensions and patches:

  require 'daylight/server'

To log each Daylight client's request_id you can configure your server to use log_tags. This is part of Rails General Configuration In your appropriate environment file add or modify the following configuration to include :uuid:

  config.log_tags = [ :uuid ]

API Documentation

Daylight provides a Rails App Engine for autogenerated API documentation. All docs are created on the fly by examining your routes, controllers and ActiveRecord models.

Add this to config/application.rb:

    require 'daylight/documentation'

And mount it in your routes:

    mount Daylight::Documentation => '/docs/api'

You will also need to include and configure your client models in your application through Bundler or some other method so the version and namespace are correct in the examples. Alternatively you can configure them in an initializer:

    require 'daylight/documentation'

    Daylight::Documentation.version   = 'v3'
    Daylight::Documentation.namespace = 'MyAPI'

Rake Tasks

Add this to your Rakefile:

  require 'daylight/tasks'

This provides two rake tasks:

  rake doc:api:generate # Pre-generate the API documentation
  rake doc:api:clean    # Clear the API documentation

The doc:api:generate tasks requests every page in the documentation so it can be pre-cached. Make sure to run it in an environment where caching is turned on:

  config.action_controller.perform_caching = true
  RAILS_ENV=production rake doc:api:generate

The doc:api:clean tasks clears out the documentation cache directory.

Testing

You can use the supplied mock for testing when developing your API.

Add the following to your test_helper.rb or spec_helper.rb:

  require 'daylight/mock'

  Daylight::Mock.setup

Console

When developing your API, you will want to ensure your aliases are also updated when you reload! Add the following to an initializer on your server:

  require 'daylight/client_reloader'

More information about the client reloader is available in the development guide.