module Eyeson

Eyeson API

Provides REST methods

Constants

VERSION

Attributes

configuration[W]

Public Class Methods

configuration() click to toggle source
# File lib/eyeson.rb, line 9
def self.configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/eyeson.rb, line 13
def self.configure
  yield(configuration)
end
delete(path, params = {}) click to toggle source
# File lib/eyeson/requests.rb, line 15
def delete(path, params = {})
  request(:delete, path, params)
end
get(path, params = {}) click to toggle source
# File lib/eyeson/requests.rb, line 5
def get(path, params = {})
  request(:get, path, params)
end
post(path, params = {}) click to toggle source
# File lib/eyeson/requests.rb, line 10
def post(path, params = {})
  request(:post, path, params)
end
request(method, path, params) click to toggle source
# File lib/eyeson/requests.rb, line 20
def request(method, path, params)
  response_for RestClient::Request.new(
    method: method,
    url: configuration.api_endpoint + path,
    payload: params.compact,
    headers: {
      authorization: configuration.api_key,
      accept: 'application/json',
      user_agent: 'eyeson-ruby'
    }
  )
end
response_for(req) click to toggle source
# File lib/eyeson/requests.rb, line 34
def response_for(req)
  res = begin
    req.execute
  rescue RestClient::ExceptionWithResponse => e
    e.response
  end
  return {} if !res.body || res.body.empty?
  JSON.parse(res.body)
end

Private Instance Methods

delete(path, params = {}) click to toggle source
# File lib/eyeson/requests.rb, line 15
def delete(path, params = {})
  request(:delete, path, params)
end
get(path, params = {}) click to toggle source
# File lib/eyeson/requests.rb, line 5
def get(path, params = {})
  request(:get, path, params)
end
post(path, params = {}) click to toggle source
# File lib/eyeson/requests.rb, line 10
def post(path, params = {})
  request(:post, path, params)
end
request(method, path, params) click to toggle source
# File lib/eyeson/requests.rb, line 20
def request(method, path, params)
  response_for RestClient::Request.new(
    method: method,
    url: configuration.api_endpoint + path,
    payload: params.compact,
    headers: {
      authorization: configuration.api_key,
      accept: 'application/json',
      user_agent: 'eyeson-ruby'
    }
  )
end
response_for(req) click to toggle source
# File lib/eyeson/requests.rb, line 34
def response_for(req)
  res = begin
    req.execute
  rescue RestClient::ExceptionWithResponse => e
    e.response
  end
  return {} if !res.body || res.body.empty?
  JSON.parse(res.body)
end