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:
namespaceis the module to which you wish ActiveResource client models to belongpasswordsupplied in theX-Http-Authenticationheader to be used for simple authenticationendpointis the URL where your server is running (a synonym forActiveResource#site)client_idappends value to theX-Request-Idto help identify a request sourceversionis the active version of your API client modelsversionthe set of all versions of your API client modelstimeoutthe duration in seconds in which to timeout a request
You can customize any combination of these options.
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 ]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'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.
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.setupWhen 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.