class Echowrap::Client
Public Class Methods
new(options={})
click to toggle source
Initializes a new Client
object
@param options [Hash] @return [Echowrap::Client]
# File lib/echowrap/client.rb, line 29 def initialize(options={}) Echowrap::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", options[key] || Echowrap.instance_variable_get(:"@#{key}")) end end
Public Instance Methods
get(path, params={})
click to toggle source
Perform an HTTP GET request
# File lib/echowrap/client.rb, line 36 def get(path, params={}) request(:get, path, params) end
post(path, params={})
click to toggle source
Perform an HTTP POST request
# File lib/echowrap/client.rb, line 41 def post(path, params={}) signature_params = params.values.any?{|value| value.respond_to?(:to_io)} ? {} : params request(:post, path, params, signature_params) end
Private Instance Methods
connection()
click to toggle source
Returns a Faraday::Connection object
@return [Faraday::Connection]
# File lib/echowrap/client.rb, line 66 def connection @connection ||= begin connection_options = {:builder => @middleware} connection_options[:ssl] = {:verify => true} if @endpoint[0..4] == 'https' Faraday.new(@endpoint, @connection_options.merge(connection_options)) end end
oauth_parameters(method, path, params={})
click to toggle source
# File lib/echowrap/client.rb, line 74 def oauth_parameters(method, path, params={}) uri = URI(@endpoint + path) SimpleOAuth::Header.new(method, uri, params, credentials.merge(ignore_extra_keys: true)).signed_attributes end
request(method, path, params={}, signature_params=params)
click to toggle source
# File lib/echowrap/client.rb, line 54 def request(method, path, params={}, signature_params=params) params = setup_authentication_parameters(method, path, params) connection.send(method.to_sym, path, params).env rescue Faraday::Error::ClientError raise Echowrap::Error::ClientError rescue MultiJson::DecodeError raise Echowrap::Error::DecodeError end
setup_authentication_parameters(method, path, params)
click to toggle source
# File lib/echowrap/client.rb, line 48 def setup_authentication_parameters(method, path, params) params = params.merge(:api_key => @api_key) params = params.merge(oauth_parameters(method, path, params)) if params.delete(:oauth_request) params end