class Billomat::Gateway
This class can be used by the gem to communicate with the API
Attributes
body[R]
method[R]
path[R]
Public Class Methods
new(method, path, body = {})
click to toggle source
Creates a new Gateway
@param [Symbol] method The HTTP verb @param [String] path The path of the resource @param [Hash] body The payload for the request
@example
Billomat::Gateway.new(:get, '/invoices') Billomat::Gateway.new(:post, '/invoices', { 'invoice' => { ... } })
# File lib/billomat/gateway.rb, line 26 def initialize(method, path, body = {}) @method = method.to_sym @path = path @body = body end
Public Instance Methods
config()
click to toggle source
@return [Billomat::Configuration] The global gem configuration
:reek: UtilityFunction because it's a shorthand
# File lib/billomat/gateway.rb, line 78 def config Billomat.configuration end
headers()
click to toggle source
@return [Hash] The headers for the request.
# File lib/billomat/gateway.rb, line 65 def headers { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'X-BillomatApiKey' => config.api_key, 'X-AppId' => config.app_id, 'X-AppSecret' => config.app_secret }.reject { |_, val| val.nil? } end
response()
click to toggle source
# File lib/billomat/gateway.rb, line 44 def response RestClient::Request.execute( method: method, url: url, timeout: timeout, headers: headers, payload: body.to_json ) end
run()
click to toggle source
Executes the API call @return [Hash] The response body
# File lib/billomat/gateway.rb, line 35 def run resp = response raise GatewayError, resp.body if resp.code > 299 return nil if resp.body.empty? JSON.parse(resp.body) end
timeout()
click to toggle source
@return [Integer]
# File lib/billomat/gateway.rb, line 60 def timeout config.timeout || 5 end
url()
click to toggle source
@return [String] The complete URL for the request
# File lib/billomat/gateway.rb, line 55 def url "https://#{config.subdomain}.billomat.net/api#{path}" end