Class: BMLConnect::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/bml_connect/client.rb

Constant Summary collapse

BML_API_VERSION =
'2.0'
BML_APP_VERSION =
'bml-connect-ruby'
BML_SIGN_METHOD =
'sha1'
BML_SANDBOX_ENDPOINT =
"https://api.uat.merchants.bankofmaldives.com.mv/public/"
BML_PRODUCTION_ENDPOINT =
"https://api.merchants.bankofmaldives.com.mv/public/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key: nil, app_id: nil, mode: nil, options: {}) ⇒ Client

Returns a new instance of Client.



17
18
19
20
21
22
23
# File 'lib/bml_connect/client.rb', line 17

def initialize(api_key: nil, app_id: nil, mode: nil, options: {})
  @api_key = api_key || (defined?(BML_API_KEY) ? BML_API_KEY : 'not-set')
  @app_id = app_id || (defined?(BML_APP_ID) ? BML_APP_ID : 'not-set')
  @mode = mode || (defined?(BML_MODE) ? BML_MODE : 'production')
  @http_client = initialize_http_client(options)
  @transactions = Transactions.new(self)
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



15
16
17
# File 'lib/bml_connect/client.rb', line 15

def api_key
  @api_key
end

#http_clientObject (readonly)

Returns the value of attribute http_client.



15
16
17
# File 'lib/bml_connect/client.rb', line 15

def http_client
  @http_client
end

#transactionsObject (readonly)

Returns the value of attribute transactions.



15
16
17
# File 'lib/bml_connect/client.rb', line 15

def transactions
  @transactions
end

Instance Method Details

#base_urlObject



25
26
27
# File 'lib/bml_connect/client.rb', line 25

def base_url
  @mode == 'production' ? BML_PRODUCTION_ENDPOINT : BML_SANDBOX_ENDPOINT
end

#get(action, params = {}) ⇒ Object



42
43
44
# File 'lib/bml_connect/client.rb', line 42

def get(action, params = {})
  @http_client.get(action, params.slice(:page))
end

#post(action, params = {}) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/bml_connect/client.rb', line 33

def post(action, params = {})
  data = params.merge({
    'apiVersion' => BML_API_VERSION,
    'appVersion' => BML_APP_VERSION,
    'signMethod' => BML_SIGN_METHOD,
  })
  @http_client.post(action, data.to_json)
end

#set_http_client(client) ⇒ Object



29
30
31
# File 'lib/bml_connect/client.rb', line 29

def set_http_client(client)
  @http_client = client
end