Class: Bambora::Builders::Headers

Inherits:
Object
  • Object
show all
Defined in:
lib/bambora/builders/headers.rb

Overview

Builds Headers for HTTP requests.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Headers

Initialize a new Headers object.

Parameters:

  • options (:api_key) (defaults to: {})
    String
  • options (:merchant_id) (defaults to: {})
    String
  • options (:sub_merchant_id) (defaults to: {})
    String

    optional.

  • options (:content_type) (defaults to: {})
    String

    optional.



17
18
19
20
21
# File 'lib/bambora/builders/headers.rb', line 17

def initialize(options = {})
  options.each do |key, value|
    instance_variable_set("@#{key}", value)
  end
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



8
9
10
# File 'lib/bambora/builders/headers.rb', line 8

def api_key
  @api_key
end

#content_typeObject (readonly)

Returns the value of attribute content_type.



8
9
10
# File 'lib/bambora/builders/headers.rb', line 8

def content_type
  @content_type
end

#merchant_idObject (readonly)

Returns the value of attribute merchant_id.



8
9
10
# File 'lib/bambora/builders/headers.rb', line 8

def merchant_id
  @merchant_id
end

#sub_merchant_idObject (readonly)

Returns the value of attribute sub_merchant_id.



8
9
10
# File 'lib/bambora/builders/headers.rb', line 8

def sub_merchant_id
  @sub_merchant_id
end

Instance Method Details

#buildHash

Builds a header object.

Returns:

  • (Hash)


27
28
29
30
31
32
33
34
# File 'lib/bambora/builders/headers.rb', line 27

def build
  headers = {
    'Authorization' => "Passcode #{passcode}",
  }
  headers['Content-Type'] = content_type if content_type
  headers['Sub-Merchant-Id'] = sub_merchant_id if sub_merchant_id
  headers
end