module Profitwell::Common
Constants
- ERROR_CODES
Public Instance Methods
request(http_method, endpoint, options: {})
click to toggle source
# File lib/profitwell/common.rb, line 18 def request(http_method, endpoint, options: {}) response = HTTParty.send(http_method, endpoint, params(options).merge!(authorization_header)) if response.success? parse_success response else parse_failed response end end
resource_path(path = nil, options = "")
click to toggle source
# File lib/profitwell/common.rb, line 12 def resource_path(path = nil, options = "") return "#{base_endpoint}/#{path}/?#{options}" if options.nil? "#{base_endpoint}/#{path}/" end
Private Instance Methods
access_token()
click to toggle source
# File lib/profitwell/common.rb, line 53 def access_token raise 'Access token is missing' unless Profitwell.access_token @access_token ||= Profitwell.access_token end
base_endpoint()
click to toggle source
# File lib/profitwell/common.rb, line 63 def base_endpoint raise 'Base API endpoint is missing' unless Profitwell.base_endpoint @base_endpoint ||= Profitwell.base_endpoint end
content_type()
click to toggle source
# File lib/profitwell/common.rb, line 58 def content_type raise 'Content type is missing' unless Profitwell.content_type @content_type ||= Profitwell.content_type end
params(values)
click to toggle source
# File lib/profitwell/common.rb, line 29 def params(values) { body: values.to_json } end
parse_failed(response)
click to toggle source
# File lib/profitwell/common.rb, line 48 def parse_failed(response) error = ERROR_CODES[response.code].new(response) raise error, error.message end
parse_success(response)
click to toggle source
# File lib/profitwell/common.rb, line 44 def parse_success(response) response_hash = response end