class Alluc::Requester

Public Class Methods

get(action, params={}) click to toggle source
# File lib/alluc/requester.rb, line 3
def get(action, params={})
  url = api.url_for(action, params)
  perform_request do
    parse_response(Excon.get(url, :headers => headers))
  end
end

Private Class Methods

api() click to toggle source
# File lib/alluc/requester.rb, line 11
def api
  Alluc::Api.instance
end
headers() click to toggle source
# File lib/alluc/requester.rb, line 15
def headers
  Hash.new.tap do |headers|
    headers['Accept'] = 'application/json'
    headers['Content-Type'] = 'application/json'
    headers['X-Mashape-Key'] = api.api_key if api.api_type == :mashape
  end
end
parse_response(response) click to toggle source
# File lib/alluc/requester.rb, line 31
def parse_response(response)
  begin
    JSON.parse(response.body)
  rescue JSON::ParserError => e
    puts e.message
  end
end
perform_request(&block) click to toggle source
# File lib/alluc/requester.rb, line 23
def perform_request(&block)
  begin
    block.call
  rescue Exception => e
    puts e.message
  end
end