class Montabe::Client

Public Class Methods

new(options={}) click to toggle source
# File lib/montabe/client.rb, line 9
def initialize(options={})
end

Public Instance Methods

api_url() click to toggle source

Base URL for api requests.

# File lib/montabe/client.rb, line 25
def api_url
  "http://demo.montabe.com"
end
connection() click to toggle source

Sets up the connection to be used for all requests based on options passed during initialization.

# File lib/montabe/client.rb, line 14
def connection
  params = {}
  @connection ||= Faraday::Connection.new(:url => api_url, :params => params, :headers => default_headers) do |builder|
    builder.adapter Faraday.default_adapter
    builder.use Faraday::Response::Mashify
    builder.use Faraday::Response::ParseJson
  end
end
return_error_or_body(response, response_body) click to toggle source

Helper method to return errors or desired response data as appropriate.

Added just for convenience to avoid having to traverse farther down the response just to get to returned data.

# File lib/montabe/client.rb, line 33
def return_error_or_body(response, response_body)
  response.status == 200 ? response_body : response.body
end

Private Instance Methods

default_headers() click to toggle source
# File lib/montabe/client.rb, line 40
def default_headers
  headers = {
    :accept =>  'application/json',
    :user_agent => 'Ruby gem'
  }
end