class Rlocu2::Client
Wrapper for the Locu
API v 2.0
Constants
- DEFAULT_CONNECTION_MIDDLEWARE
Attributes
api_key[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/rlocu2/client.rb, line 13 def initialize(options={}) @api_key = options[:api_key] || Rlocu2.api_key @connection_middleware = options[:connection_middleware] || Rlocu2.connection_middleware || [] @connection_middleware += DEFAULT_CONNECTION_MIDDLEWARE end
Public Instance Methods
api_url()
click to toggle source
# File lib/rlocu2/client.rb, line 28 def api_url 'https://api.locu.com/v2/' end
connection()
click to toggle source
# File lib/rlocu2/client.rb, line 19 def connection @connection ||= Faraday::Connection.new(:url => api_url, :headers => default_headers) do |builder| @connection_middleware.each do |middleware| builder.use *middleware end builder.adapter Faraday.default_adapter end end
return_error_or_body(response, response_body, type)
click to toggle source
# File lib/rlocu2/client.rb, line 32 def return_error_or_body(response, response_body, type) if response.status == 200 # REMAP & PARSE Objects output = Hash.new output['status'] = response_body['status'] output['http_status'] = response_body['http_status'] if type == 'venues' output['venues'] = response_body['venues'].each.reduce([]) { |accum, venue| accum << Rlocu2::Venue.new(venue) } end if response_body.has_key? 'next_results_key' output['next_results_key'] = response_body['next_results_key'] end output else raise Rlocu2::APIError.new(response.body) end end
Private Instance Methods
default_headers()
click to toggle source
# File lib/rlocu2/client.rb, line 57 def default_headers headers = { :accept => 'application/json', :user_agent => 'Rlocu2 Ruby Gem' } end