Class: Billomat::Gateway
- Inherits:
-
Object
- Object
- Billomat::Gateway
- Defined in:
- lib/billomat/gateway.rb
Overview
This class can be used by the gem to communicate with the API
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#config ⇒ Billomat::Configuration
The global gem configuration.
-
#headers ⇒ Hash
The headers for the request.
-
#initialize(method, path, body = {}) ⇒ Gateway
constructor
Creates a new Gateway.
-
#run ⇒ Hash
Executes the API call.
- #timeout ⇒ Integer
-
#url ⇒ String
The complete URL for the request.
Constructor Details
#initialize(method, path, body = {}) ⇒ Gateway
Creates a new Gateway
26 27 28 29 30 |
# File 'lib/billomat/gateway.rb', line 26 def initialize(method, path, body = {}) @method = method.to_sym @path = path @body = body end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
14 15 16 |
# File 'lib/billomat/gateway.rb', line 14 def body @body end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
14 15 16 |
# File 'lib/billomat/gateway.rb', line 14 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/billomat/gateway.rb', line 14 def path @path end |
Instance Method Details
#config ⇒ Billomat::Configuration
Returns The global gem configuration.
70 71 72 |
# File 'lib/billomat/gateway.rb', line 70 def config Billomat.configuration end |
#headers ⇒ Hash
Returns The headers for the request.
61 62 63 64 65 66 67 |
# File 'lib/billomat/gateway.rb', line 61 def headers { 'Accept' => 'application/json', 'Content-Type' => 'application/json', 'X-BillomatApiKey' => config.api_key } end |
#run ⇒ Hash
Executes the API call
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/billomat/gateway.rb', line 35 def run resp = RestClient::Request.execute( method: method, url: url, timeout: timeout, headers: headers, payload: body.to_json ) raise GatewayError, resp.body if resp.code > 299 return nil if resp.body.empty? JSON.parse(resp.body) end |
#timeout ⇒ Integer
56 57 58 |
# File 'lib/billomat/gateway.rb', line 56 def timeout 5 end |
#url ⇒ String
Returns The complete URL for the request.
51 52 53 |
# File 'lib/billomat/gateway.rb', line 51 def url "https://#{config.subdomain}.billomat.net/api#{path}" end |