Class: Bambora::Rest::JSONClient

Inherits:
Client
  • Object
show all
Defined in:
lib/bambora/rest/json_client.rb

Overview

The base class for making JSON requests.

Constant Summary collapse

CONTENT_TYPE =
'application/json'

Instance Attribute Summary

Attributes inherited from Client

#base_url, #merchant_id, #sub_merchant_id

Instance Method Summary collapse

Methods inherited from Client

#initialize

Constructor Details

This class inherits a constructor from Bambora::Rest::Client

Instance Method Details

#delete(path:, api_key:) ⇒ Hash

Make a DELETE Request.

Examples:


client = Bambora::Rest::JSONClient(base_url: '...', api_key: '...', merchant_id: '...')

client.delete(path: 'v1/profiles/02355E2e58Bf488EAB4EaFAD7083dB6A', api_key: '...')
# => {
#      :code => 1,
#      :message => "Operation Successful",
#      :customer_code => "02355E2e58Bf488EAB4EaFAD7083dB6A",
#    }

Parameters:

  • path (String)

    Indicating request path.

  • api_key (String)

    Indicating the API Key to be used with the request.

Returns:

  • (Hash)

    Indicating success or failure of the operation.



96
97
98
99
100
# File 'lib/bambora/rest/json_client.rb', line 96

def delete(path:, api_key:)
  parse_response_body(
    super(path: path, headers: build_headers(api_key: api_key)),
  ).to_h
end

#get(path:, api_key:, params: nil) ⇒ Hash

Make a GET Request.

Examples:


client = Bambora::Rest::JSONClient(base_url: '...', merchant_id: '...')

client.get(
  path: 'v1/profiles',
  params: '...',
  api_key: '...'
)
# => {
#      :code => 1,
#      :message => "Operation Successful",
#      :customer_code => "02355E2e58Bf488EAB4EaFAD7083dB6A",
#      :card => { ... }
#    }

Parameters:

  • path (String)

    Indicating request path.

  • params (Hash) (defaults to: nil)

    Query parameters for the request.

  • api_key (String)

    Indicating the API Key to be used with the request.

Returns:

  • (Hash)

    Indicating success or failure of the operation.



33
34
35
36
37
# File 'lib/bambora/rest/json_client.rb', line 33

def get(path:, api_key:, params: nil)
  parse_response_body(
    super(path: path, params: params, headers: build_headers(api_key: api_key)),
  ).to_h
end

#post(path:, body:, api_key:) ⇒ Hash

Make a POST Request.

Examples:


client = Bambora::Rest::JSONClient(base_url: '...', merchant_id: '...')

data = {
 language: 'en',
  card: {
    name: 'Hup Podling',
    number: '4030000010001234',
    expiry_month: '12',
    expiry_year: '23',
    cvd: '123',
  },
}

client.post(
  path: 'v1/profiles',
  body: data,
  api_key: '...'
)
# => {
#      :code => 1,
#      :message => "Operation Successful",
#      :customer_code => "02355E2e58Bf488EAB4EaFAD7083dB6A",
#    }

Parameters:

  • method (Symbol)

    Indicating request verb.

  • path (String)

    Indicating request path.

  • body (Hash)

    Data to be sent in the body of the request.

  • api_key (String)

    Indicating the API Key to be used with the request.

Returns:

  • (Hash)

    Indicating success or failure of the operation.



73
74
75
76
77
# File 'lib/bambora/rest/json_client.rb', line 73

def post(path:, body:, api_key:)
  parse_response_body(
    super(path: path, body: body.to_json.to_s, headers: build_headers(api_key: api_key)),
  ).to_h
end

#put(path:, body:, api_key:) ⇒ Hash

Make a PUT Request.

Examples:


client = Bambora::Rest::JSONClient(base_url: '...', merchant_id: '...')

data = {
  billing: {
     name: "joh doe",
     address_line1: "123 main st",
     address_line2: "111",
     city: "victoria",
     province: "bc",
     country: "ca",
     postal_code: "V8T4M3",
     phone_number: "25012312345",
     email_address: "[email protected]"
  },
  card: {
    name: 'Hup Podling',
    number: '4030000010001234',
    expiry_month: '12',
    expiry_year: '23',
    cvd: '123',
  },
}

client.put(
  path: 'v1/profiles',
  body: data,
  api_key: '...'
)
# => {
#      :code => 1,
#      :message => "Operation Successful",
#      :customer_code => "02355E2e58Bf488EAB4EaFAD7083dB6A",
#    }

Parameters:

  • path (String)

    Indicating request path.

  • body (Hash)

    Data to be sent in the body of the request.

  • api_key (String)

    Indicating the API Key to be used with the request.

Returns:

  • (Hash)

    Indicating success or failure of the operation.



145
146
147
148
149
# File 'lib/bambora/rest/json_client.rb', line 145

def put(path:, body:, api_key:)
  parse_response_body(
    super(path: path, body: body.to_json.to_s, headers: build_headers(api_key: api_key)),
  ).to_h
end