lib/billomat/gateway.rb in billomat-0.1.5 vs lib/billomat/gateway.rb in billomat-0.1.6
- old
+ new
@@ -31,22 +31,26 @@
##
# Executes the API call
# @return [Hash] The response body
def run
- resp = RestClient::Request.execute(
+ resp = response
+
+ raise GatewayError, resp.body if resp.code > 299
+ return nil if resp.body.empty?
+
+ JSON.parse(resp.body)
+ end
+
+ def response
+ 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
# @return [String] The complete URL for the request
def url
"https://#{config.subdomain}.billomat.net/api#{path}"
@@ -60,14 +64,18 @@
# @return [Hash] The headers for the request.
def headers
{
'Accept' => 'application/json',
'Content-Type' => 'application/json',
- 'X-BillomatApiKey' => config.api_key
- }
+ 'X-BillomatApiKey' => config.api_key,
+ 'X-AppId' => config.app_id,
+ 'X-AppSecret' => config.app_secret
+ }.reject { |_, val| val.nil? }
end
# @return [Billomat::Configuration] The global gem configuration
+ #
+ # :reek:UtilityFunction because it's a shorthand
def config
Billomat.configuration
end
end
end