Class: ModernTreasury::Client

Inherits:
Object
  • Object
show all
Includes:
CoreLibrary
Defined in:
lib/modern_treasury/client.rb

Overview

modern_treasury client class.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection: nil, adapter: :net_http_persistent, timeout: 30, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put],, http_callback: nil, proxy_settings: nil, logging_configuration: nil, environment: Environment::PRODUCTION, basic_auth_credentials: nil, config: nil) ⇒ Client

Returns a new instance of Client.



226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/modern_treasury/client.rb', line 226

def initialize(
  connection: nil, adapter: :net_http_persistent, timeout: 30,
  max_retries: 0, retry_interval: 1, backoff_factor: 2,
  retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
  retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
  logging_configuration: nil, environment: Environment::PRODUCTION,
  basic_auth_credentials: nil, config: nil
)
  @config = if config.nil?
              Configuration.new(
                connection: connection, adapter: adapter, timeout: timeout,
                max_retries: max_retries, retry_interval: retry_interval,
                backoff_factor: backoff_factor,
                retry_statuses: retry_statuses,
                retry_methods: retry_methods, http_callback: http_callback,
                proxy_settings: proxy_settings,
                logging_configuration: logging_configuration,
                environment: environment,
                basic_auth_credentials: basic_auth_credentials
              )
            else
              config
            end
  user_agent_params = BaseController.user_agent_parameters

  @global_configuration = GlobalConfiguration.new(client_configuration: @config)
                                             .base_uri_executor(@config.method(:get_base_uri))
                                             .global_errors(BaseController::GLOBAL_ERRORS)
                                             .user_agent(BaseController.user_agent,
                                                         agent_parameters: user_agent_params)

  initialize_auth_managers(@global_configuration)
  @global_configuration = @global_configuration.auth_managers(@auth_managers)
end

Instance Attribute Details

#auth_managersObject (readonly)

Returns the value of attribute auth_managers.



10
11
12
# File 'lib/modern_treasury/client.rb', line 10

def auth_managers
  @auth_managers
end

#configObject (readonly)

Returns the value of attribute config.



10
11
12
# File 'lib/modern_treasury/client.rb', line 10

def config
  @config
end

Class Method Details

.from_env(**overrides) ⇒ Object

Creates a client directly from environment variables.



271
272
273
274
275
# File 'lib/modern_treasury/client.rb', line 271

def self.from_env(**overrides)
  default_config = Configuration.build_default_config_from_env
  new_config = default_config.clone_with(**overrides)
  new(config: new_config)
end

Instance Method Details

#account_collection_flowAccountCollectionFlowController

Access to account_collection_flow controller.

Returns:



216
217
218
# File 'lib/modern_treasury/client.rb', line 216

def 
  @account_collection_flow ||= AccountCollectionFlowController.new @global_configuration
end

#account_detailAccountDetailController

Access to account_detail controller.

Returns:



18
19
20
# File 'lib/modern_treasury/client.rb', line 18

def 
  @account_detail ||= AccountDetailController.new @global_configuration
end

#balance_reportBalanceReportController

Access to balance_report controller.

Returns:



24
25
26
# File 'lib/modern_treasury/client.rb', line 24

def balance_report
  @balance_report ||= BalanceReportController.new @global_configuration
end

#connectionConnectionController

Access to connection controller.

Returns:



30
31
32
# File 'lib/modern_treasury/client.rb', line 30

def connection
  @connection ||= ConnectionController.new @global_configuration
end

#counterpartyCounterpartyController

Access to counterparty controller.

Returns:



36
37
38
# File 'lib/modern_treasury/client.rb', line 36

def counterparty
  @counterparty ||= CounterpartyController.new @global_configuration
end

#documentDocumentController

Access to document controller.

Returns:



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

def document
  @document ||= DocumentController.new @global_configuration
end

#eventEventController

Access to event controller.

Returns:



48
49
50
# File 'lib/modern_treasury/client.rb', line 48

def event
  @event ||= EventController.new @global_configuration
end

#expected_paymentExpectedPaymentController

Access to expected_payment controller.

Returns:



54
55
56
# File 'lib/modern_treasury/client.rb', line 54

def expected_payment
  @expected_payment ||= ExpectedPaymentController.new @global_configuration
end

#external_accountExternalAccountController

Access to external_account controller.

Returns:



60
61
62
# File 'lib/modern_treasury/client.rb', line 60

def 
  @external_account ||= ExternalAccountController.new @global_configuration
end

#incoming_payment_detailIncomingPaymentDetailController

Access to incoming_payment_detail controller.

Returns:



66
67
68
# File 'lib/modern_treasury/client.rb', line 66

def incoming_payment_detail
  @incoming_payment_detail ||= IncomingPaymentDetailController.new @global_configuration
end

#initialize_auth_managers(global_config) ⇒ Object

Initializes the auth managers hash used for authenticating API calls.

Parameters:

  • global_config (GlobalConfiguration)

    The global configuration of the SDK)



263
264
265
266
267
268
# File 'lib/modern_treasury/client.rb', line 263

def initialize_auth_managers(global_config)
  @auth_managers = {}
  http_client_config = global_config.client_configuration
  %w[basic_auth].each { |auth| @auth_managers[auth] = nil }
  @auth_managers['basic_auth'] = BasicAuth.new(http_client_config.basic_auth_credentials)
end

#internal_accountInternalAccountController

Access to internal_account controller.

Returns:



72
73
74
# File 'lib/modern_treasury/client.rb', line 72

def 
  @internal_account ||= InternalAccountController.new @global_configuration
end

#invoiceInvoiceController

Access to invoice controller.

Returns:



84
85
86
# File 'lib/modern_treasury/client.rb', line 84

def invoice
  @invoice ||= InvoiceController.new @global_configuration
end

#invoice_line_itemInvoiceLineItemController

Access to invoice_line_item controller.

Returns:



78
79
80
# File 'lib/modern_treasury/client.rb', line 78

def invoice_line_item
  @invoice_line_item ||= InvoiceLineItemController.new @global_configuration
end

#ledgerLedgerController

Access to ledger controller.

Returns:



138
139
140
# File 'lib/modern_treasury/client.rb', line 138

def ledger
  @ledger ||= LedgerController.new @global_configuration
end

#ledger_accountLedgerAccountController

Access to ledger_account controller.

Returns:



108
109
110
# File 'lib/modern_treasury/client.rb', line 108

def 
  @ledger_account ||= LedgerAccountController.new @global_configuration
end

#ledger_account_categoryLedgerAccountCategoryController

Access to ledger_account_category controller.

Returns:



90
91
92
# File 'lib/modern_treasury/client.rb', line 90

def 
  @ledger_account_category ||= LedgerAccountCategoryController.new @global_configuration
end

#ledger_account_payoutLedgerAccountPayoutController

Access to ledger_account_payout controller.

Returns:



96
97
98
# File 'lib/modern_treasury/client.rb', line 96

def 
  @ledger_account_payout ||= LedgerAccountPayoutController.new @global_configuration
end

#ledger_account_statementLedgerAccountStatementController

Access to ledger_account_statement controller.

Returns:



102
103
104
# File 'lib/modern_treasury/client.rb', line 102

def 
  @ledger_account_statement ||= LedgerAccountStatementController.new @global_configuration
end

#ledger_entryLedgerEntryController

Access to ledger_entry controller.

Returns:



114
115
116
# File 'lib/modern_treasury/client.rb', line 114

def ledger_entry
  @ledger_entry ||= LedgerEntryController.new @global_configuration
end

#ledger_event_handlerLedgerEventHandlerController

Access to ledger_event_handler controller.

Returns:



120
121
122
# File 'lib/modern_treasury/client.rb', line 120

def ledger_event_handler
  @ledger_event_handler ||= LedgerEventHandlerController.new @global_configuration
end

#ledger_transactionLedgerTransactionController

Access to ledger_transaction controller.

Returns:



126
127
128
# File 'lib/modern_treasury/client.rb', line 126

def ledger_transaction
  @ledger_transaction ||= LedgerTransactionController.new @global_configuration
end

#ledgerable_eventLedgerableEventController

Access to ledgerable_event controller.

Returns:



132
133
134
# File 'lib/modern_treasury/client.rb', line 132

def ledgerable_event
  @ledgerable_event ||= LedgerableEventController.new @global_configuration
end

#line_itemLineItemController

Access to line_item controller.

Returns:



144
145
146
# File 'lib/modern_treasury/client.rb', line 144

def line_item
  @line_item ||= LineItemController.new @global_configuration
end

#mreturnReturnController

Access to mreturn controller.

Returns:



174
175
176
# File 'lib/modern_treasury/client.rb', line 174

def mreturn
  @mreturn ||= ReturnController.new @global_configuration
end

#paper_itemPaperItemController

Access to paper_item controller.

Returns:



150
151
152
# File 'lib/modern_treasury/client.rb', line 150

def paper_item
  @paper_item ||= PaperItemController.new @global_configuration
end

#payment_flowPaymentFlowController

Access to payment_flow controller.

Returns:



222
223
224
# File 'lib/modern_treasury/client.rb', line 222

def payment_flow
  @payment_flow ||= PaymentFlowController.new @global_configuration
end

#payment_orderPaymentOrderController

Access to payment_order controller.

Returns:



156
157
158
# File 'lib/modern_treasury/client.rb', line 156

def payment_order
  @payment_order ||= PaymentOrderController.new @global_configuration
end

#payment_referencePaymentReferenceController

Access to payment_reference controller.

Returns:



162
163
164
# File 'lib/modern_treasury/client.rb', line 162

def payment_reference
  @payment_reference ||= PaymentReferenceController.new @global_configuration
end

#pingPingController

Access to ping controller.

Returns:



168
169
170
# File 'lib/modern_treasury/client.rb', line 168

def ping
  @ping ||= PingController.new @global_configuration
end

#reversalReversalController

Access to reversal controller.

Returns:



180
181
182
# File 'lib/modern_treasury/client.rb', line 180

def reversal
  @reversal ||= ReversalController.new @global_configuration
end

#routing_detailRoutingDetailController

Access to routing_detail controller.

Returns:



186
187
188
# File 'lib/modern_treasury/client.rb', line 186

def routing_detail
  @routing_detail ||= RoutingDetailController.new @global_configuration
end

#transactionTransactionController

Access to transaction controller.

Returns:



198
199
200
# File 'lib/modern_treasury/client.rb', line 198

def transaction
  @transaction ||= TransactionController.new @global_configuration
end

#transaction_line_itemTransactionLineItemController

Access to transaction_line_item controller.

Returns:



192
193
194
# File 'lib/modern_treasury/client.rb', line 192

def transaction_line_item
  @transaction_line_item ||= TransactionLineItemController.new @global_configuration
end

#user_agent_detailObject



12
13
14
# File 'lib/modern_treasury/client.rb', line 12

def user_agent_detail
  config.user_agent_detail
end

#validationValidationController

Access to validation controller.

Returns:



204
205
206
# File 'lib/modern_treasury/client.rb', line 204

def validation
  @validation ||= ValidationController.new @global_configuration
end

#virtual_accountVirtualAccountController

Access to virtual_account controller.

Returns:



210
211
212
# File 'lib/modern_treasury/client.rb', line 210

def 
  @virtual_account ||= VirtualAccountController.new @global_configuration
end