Class: UkrsibAPI::Client

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

Overview

main entry point for the gem see #balances, #transactions

Constant Summary collapse

BASE_URL =
"https://business.ukrsibbank.com/morpheus/"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(authentication: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client

Expects UkrsibAPI::Authentication tp be already authorized see documentation for UkrsibAPI::Authentication



13
14
15
16
17
# File 'lib/ukrsib_api/client.rb', line 13

def initialize(authentication: nil, adapter: Faraday.default_adapter, stubs: nil)
  @auth = authentication || UkrsibAPI::Authentication.new
  @adapter = adapter
  @stubs = stubs
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



8
9
10
# File 'lib/ukrsib_api/client.rb', line 8

def access_token
  @access_token
end

#adapterObject (readonly)

Returns the value of attribute adapter.



8
9
10
# File 'lib/ukrsib_api/client.rb', line 8

def adapter
  @adapter
end

#authObject (readonly)

Returns the value of attribute auth.



8
9
10
# File 'lib/ukrsib_api/client.rb', line 8

def auth
  @auth
end

#stubsObject (readonly)

Returns the value of attribute stubs.



8
9
10
# File 'lib/ukrsib_api/client.rb', line 8

def stubs
  @stubs
end

Instance Method Details

#balancesUkrsibAPI::Resources::BalanceResource

Returns a new instance of UkrsibAPI::Resources::BalanceResource for handling balance-related API operations.



35
36
37
# File 'lib/ukrsib_api/client.rb', line 35

def balances
  UkrsibAPI::Resources::BalanceResource.new(self)
end

#connectionObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ukrsib_api/client.rb', line 19

def connection
  @auth.refresh_token_if_needed

  @connection ||= Faraday.new(BASE_URL) do |b|
    b.headers["Authorization"] = "Bearer #{@auth.access_token}"
    b.headers["Content-Type"] = "application/json;charset=utf8"
    b.ssl.verify = true
    b.request :json
    b.response :json
    b.response :logger, UkrsibAPI.logger, { headers: false, bodies: false }
    b.adapter @adapter, @stubs
  end
end

#statements_v3UkrsibAPI::Resources::TransactionResource

Returns a new instance of UkrsibAPI::Resources::TransactionResource for handling transaction-related API operations.



41
42
43
# File 'lib/ukrsib_api/client.rb', line 41

def statements_v3
  UkrsibAPI::Resources::StatementsV3Resource.new(self)
end