Litmus::Infrastructure
A gem that provides an interface between a Ruby application and the Litmus
infrastructure API.
Installation
If your production environment will have access to this repo (a user on your production server must have an ssh key that corresponds to a user with access to this repo), you can declare the gem in your gemfile using the github
parameter:
gem 'litmus-infrastructure', github: 'litmus/litmus-infrastructure-client'
If you do not have access to the SSH keys in your production environment, when using Heroku for example, you'll need to use a repo URL that includes the API key for a user with access to this repo:
gem 'litmus-infrastructure', git: 'https://GITHUB_API_KEY_XXXXXX@github.com/litmus/litmus-infrastructure-client.git'
Usage
Rails
Include Litmus::Infrastructure
in a module that you'd like to have interact
with the infrastructure API:
module Checklist
include Litmus::Infrastructure
end
Your integration should be configured by creating an initializer:
Checklist.configure do |config|
config.timeout_connect = 5.seconds
config.timeout_receive = 1.minute
config.username = ENV['INFRASTRUCTURE_USERNAME']
config.password = ENV['INFRASTRUCTURE_PASSWORD']
config.url = ENV['INFRASTRUCTURE_API_BASE_URL']
config.logger = Rails.logger
end
Any objects that should act as models for data from the infrastructure API
should extend Litmus::Infrastructure::Model
:
module Checklist
class Result < Litmus::Infrastructure::Model
end
end
Your models can define attributes to read from the API using the attributes
class method:
module Checklist
class Result < Litmus::Infrastructure::Model
attributes :content, :encoding, :from, :grade, :images
end
end
Once your models are defined, you can interact with the infrastructure API using
the class methods put
, post
, and get
, passing the appropriate
endpoint/action to these methods as the first parameter, and the JSON payload as
the second:
Checklist::Result.post('Checklist', { subject: 'Example' }.to_json)