module MercuryParser::Request
Public Instance Methods
get(path, params={})
click to toggle source
Performs a HTTP Get request
# File lib/mercury_parser/request.rb, line 7 def get(path, params={}) request(:get, path, params) end
Private Instance Methods
request(method, path, params = {})
click to toggle source
Returns a Faraday::Response object
@return [Faraday::Response]
# File lib/mercury_parser/request.rb, line 17 def request(method, path, params = {}) raise MercuryParser::Error::ConfigurationError.new("Please configure MercuryParser.api_key first") if api_key.nil? connection_options = {} begin response = connection(connection_options).send(method) do |req| req.url(path, params) req.headers['Content-Type'] = 'application/json' req.headers['x-api-key'] = api_key end rescue Faraday::Error::ClientError => error if error.is_a?(Faraday::Error::ClientError) raise MercuryParser::Error::ClientError.new(error) else raise MercuryParser::Error::RequestError.new(error) end end response.body end