class Chairman::Holmes::Client

Attributes

body[RW]
headers[RW]

Public Class Methods

new(host) click to toggle source
# File lib/chairman/holmes.rb, line 9
def initialize(host)
  @api_client = Sawyer::Agent.new(host, {serializer: Sawyer::Serializer.yajl}) do |http|
    http.headers['content-type'] = 'application/json'
  end

  @headers = {}
  @body = ''
end

Public Instance Methods

extensions() click to toggle source
# File lib/chairman/holmes.rb, line 22
def extensions
  get '/extensions'
end
root() click to toggle source
# File lib/chairman/holmes.rb, line 18
def root
  get '/'
end

Private Instance Methods

call(api_response) click to toggle source
# File lib/chairman/holmes.rb, line 44
def call(api_response)
  api_response.headers.each do |key, value|
    if passthrough_headers.include? key
      @headers[key] = value
    end
  end

  if api_response.data.respond_to? :to_hash
    @body = api_response.data.to_attrs.to_json
  else
    @body = api_response.data
  end

  return api_response.status
end
get(path, params = {}) click to toggle source
# File lib/chairman/holmes.rb, line 36
def get(path, params = {})
  call @api_client.call :get, path, params
end
passthrough_headers() click to toggle source
# File lib/chairman/holmes.rb, line 28
def passthrough_headers
  [
    'content-type',
    'last-modified',
    'cache-control'
  ]
end
post(path, params = {}) click to toggle source
# File lib/chairman/holmes.rb, line 40
def post(path, params = {})
  call @api_client.call :post, path, params
end