class Bambora::Rest::Client

A basic client for making REST requests.

Attributes

base_url[R]
merchant_id[R]
sub_merchant_id[R]

Public Class Methods

new(options = {}) { |self| ... } click to toggle source

Initialze a client that makes REST requests.

@example

rest_client = Bambora::Rest::Client.new(
  base_url: ENV.fetch('BAMBORA_BASE_URL'),
  merchant_id: ENV.fetch('BAMBORA_MERCHANT_ID'),
  sub_merchant_id: ENV.fetch('BAMBORA_SUB_MERCHANT_ID'),
)
# File lib/bambora/rest/client.rb, line 18
def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
  yield(self) if block_given?
end

Protected Instance Methods

build_headers(api_key:, content_type: nil) click to toggle source
# File lib/bambora/rest/client.rb, line 53
def build_headers(api_key:, content_type: nil)
  Bambora::Builders::Headers.new(
    content_type: content_type,
    api_key: api_key,
    merchant_id: merchant_id,
    sub_merchant_id: sub_merchant_id,
  ).build
end
connection() click to toggle source
# File lib/bambora/rest/client.rb, line 45
def connection
  @connection ||= Faraday.new(url: base_url) do |faraday|
    faraday.request :multipart
    faraday.request :url_encoded
    faraday.adapter :excon
  end
end
delete(path:, headers:) click to toggle source
# File lib/bambora/rest/client.rb, line 35
def delete(path:, headers:)
  connection.delete(path) do |req|
    req.headers = headers
  end
end
get(path:, params:, headers:) click to toggle source
# File lib/bambora/rest/client.rb, line 27
def get(path:, params:, headers:)
  connection.get(path, params, headers)
end
parse_response_body(response) click to toggle source
# File lib/bambora/rest/client.rb, line 62
def parse_response_body(response)
  Bambora::ResponseAdapterFactory.for(response).to_h
end
post(path:, body:, headers:) click to toggle source
# File lib/bambora/rest/client.rb, line 31
def post(path:, body:, headers:)
  connection.post(path, body, headers)
end
put(path:, body:, headers:) click to toggle source
# File lib/bambora/rest/client.rb, line 41
def put(path:, body:, headers:)
  connection.put(path, body, headers)
end