module RSqoot::Request
Public Instance Methods
get(path, opts = {}, parse = true)
click to toggle source
# File lib/rsqoot/request.rb, line 8 def get(path, opts = {}, parse = true) uri = URI.parse base_api_url uri.path = '/v2/' + path headers = {read_timeout: read_timeout} query = options_parser opts endpoint = path.split('/')[0] case authentication_method when :header headers.merge! h = {"Authorization" => "api_key #{api_key(endpoint)}"} query = query + "&api_key=#{api_key(endpoint)}" if !parse when :parameter query = query + "&api_key=#{api_key(endpoint)}" end uri.query = query if parse begin json = JSON.parse uri.open(headers).read ::Hashie::Mash.new json end else uri.to_s end end
Private Instance Methods
api_key(endpoint='')
click to toggle source
# File lib/rsqoot/request.rb, line 42 def api_key(endpoint='') if private_endpoints.include? endpoint private_api_key elsif public_endpoints.include? endpoint public_api_key else raise "No such endpoint #{endpoint} available." end end
options_parser(options = {})
click to toggle source
Example: options = {per_page: 10, page: 1} Options should be parsed as http query: per_page=10&page=1
@return [String]
# File lib/rsqoot/request.rb, line 56 def options_parser(options = {}) options.map do |key, value| [key, value].map(&:to_s).join('=') end.join('&') end
private_endpoints()
click to toggle source
# File lib/rsqoot/request.rb, line 34 def private_endpoints %w(clicks commissions) end
public_endpoints()
click to toggle source
# File lib/rsqoot/request.rb, line 38 def public_endpoints %w(categories deals merchants providers) end