class EmpireAvenue::Client
Wrapper for the Empire Avenue API
Public Class Methods
new(options={})
click to toggle source
Initializes a new Client
object
@param options [Hash] @return [EmpireAvenue::Client]
# File lib/empireavenue/client.rb, line 31 def initialize(options={}) EmpireAvenue::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", options[key] || EmpireAvenue.instance_variable_get(:"@#{key}")) end end
Public Instance Methods
delete(path, params={})
click to toggle source
Perform an HTTP DELETE request
# File lib/empireavenue/client.rb, line 38 def delete(path, params={}) request(:delete, path, params) end
get(path, params={})
click to toggle source
Perform an HTTP GET request
# File lib/empireavenue/client.rb, line 43 def get(path, params={}) request(:get, path, params) end
post(path, params={})
click to toggle source
Perform an HTTP POST request
# File lib/empireavenue/client.rb, line 48 def post(path, params={}) signature_params = params.values.any?{|value| value.respond_to?(:to_io)} ? {} : params request(:post, path, params, signature_params) end
put(path, params={})
click to toggle source
Perform an HTTP PUT request
# File lib/empireavenue/client.rb, line 54 def put(path, params={}) request(:put, path, params) end
Private Instance Methods
connection()
click to toggle source
Returns a Faraday::Connection object
@return [Faraday::Connection]
# File lib/empireavenue/client.rb, line 79 def connection @connection ||= Faraday.new(@endpoint, @connection_options.merge(:builder => @middleware).merge({:params => {:client_id => @client_id, :access_token => @oauth_token}})) end
request(method, path, params={}, signature_params=params)
click to toggle source
# File lib/empireavenue/client.rb, line 60 def request(method, path, params={}, signature_params=params) #params[:client_id] ||= @client_id #params[:access_token] = params[:oauth_token] #params[:access_token] ||= @oauth_token #connection.params = params connection.send(method.to_sym, path, params) do |request| #request.params[:client_id] = params[:client_id] #request.params[:access_token] = params[:access_token] #request.headers[:authorization] = auth_header(method.to_sym, path, signature_params).to_s end.env rescue Faraday::Error::ClientError raise EmpireAvenue::Error::ClientError rescue MultiJson::DecodeError raise EmpireAvenue::Error::DecodeError end