Shutl::Rails
Summary
A convenience gem for interacting with the Shutl API from a Rails application. Provides a JSON API within your application as a proxy to the Shutl API whilst handling OAuth token validation transparently.
Installation
Add this line to your application's Gemfile: gem 'shutl_rails'
And then execute: $ bundle
Usage
#Credentials setup
#config/initializers/shutl.rb
Shutl::Auth.config do |c|
c.client_id = "<CLIENT_ID>"
c.client_secret = "<CLIENT_SECRET>"
c.url = "http://shutl-api-url-goes-here"
end
#app/controllers/quote_collections_controller.rb
class QuoteCollectionsController < Shutl::Rails::BackendResourcesController
end
#config/routes
resources :quote_collections, only: [:create, :show]
Converters
In order to convert attributes from the API into ones that may want to be used by your application you can add any files in /app/converters and they are autoloaded based on the name of the Shutl resource
/app/converters/quote_collection_converter.rb
module QuoteCollectionConverter extend Shutl::Resource::Converter
convert :enabled, with: BooleanConverter, only: :to_back_end end
/app/converters/boolean_converter.rb
module BooleanConverter extend self
def to_front_end b; b end def to_back_end b; b == 'true' end end
## Contributing
The usual: fork, branch, commit, pull request