Class: ModernTreasury::Client

Inherits:
Internal::Transport::BaseClient show all
Defined in:
lib/modern_treasury/client.rb

Constant Summary collapse

DEFAULT_MAX_RETRIES =

Default max number of retries to attempt after a failed retryable request.

2
DEFAULT_TIMEOUT_IN_SECONDS =

Default per-request timeout.

60.0
DEFAULT_INITIAL_RETRY_DELAY =

Default initial retry delay in seconds. Overall delay is calculated using exponential backoff + jitter.

0.5
DEFAULT_MAX_RETRY_DELAY =

Default max retry delay in seconds.

8.0

Constants inherited from Internal::Transport::BaseClient

Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS

Instance Attribute Summary collapse

Attributes inherited from Internal::Transport::BaseClient

#base_url, #headers, #idempotency_header, #initial_retry_delay, #max_retries, #max_retry_delay, #requester, #timeout

Instance Method Summary collapse

Methods inherited from Internal::Transport::BaseClient

follow_redirect, #inspect, reap_connection!, #request, #send_request, should_retry?, validate!

Methods included from Internal::Util::SorbetRuntimeSupport

#const_missing, #define_sorbet_constant!, #sorbet_constant_defined?, #to_sorbet_type, to_sorbet_type

Constructor Details

#initialize(api_key: , organization_id: , base_url: , max_retries: self.class::DEFAULT_MAX_RETRIES, timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS, initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY, max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY, idempotency_header: "Idempotency-Key") ⇒ Client

Creates and returns a new client for interacting with the API.

‘“api.example.com/v2/”`. Defaults to `ENV`

Parameters:

  • api_key (String, nil) (defaults to: )

    Defaults to ‘ENV`

  • organization_id (String, nil) (defaults to: )

    Defaults to ‘ENV`

  • base_url (String, nil) (defaults to: )

    Override the default base URL for the API, e.g.,

  • max_retries (Integer) (defaults to: self.class::DEFAULT_MAX_RETRIES)

    Max number of retries to attempt after a failed retryable request.

  • timeout (Float) (defaults to: self.class::DEFAULT_TIMEOUT_IN_SECONDS)
  • initial_retry_delay (Float) (defaults to: self.class::DEFAULT_INITIAL_RETRY_DELAY)
  • max_retry_delay (Float) (defaults to: self.class::DEFAULT_MAX_RETRY_DELAY)
  • idempotency_header (String) (defaults to: "Idempotency-Key")


185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
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
# File 'lib/modern_treasury/client.rb', line 185

def initialize(
  api_key: ENV["MODERN_TREASURY_API_KEY"],
  organization_id: ENV["MODERN_TREASURY_ORGANIZATION_ID"],
  base_url: ENV["MODERN_TREASURY_BASE_URL"],
  max_retries: self.class::DEFAULT_MAX_RETRIES,
  timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
  initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
  max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY,
  idempotency_header: "Idempotency-Key"
)
  base_url ||= "https://app.moderntreasury.com"

  if api_key.nil?
    raise ArgumentError.new("api_key is required, and can be set via environ: \"MODERN_TREASURY_API_KEY\"")
  end
  if organization_id.nil?
    raise ArgumentError.new("organization_id is required, and can be set via environ: \"MODERN_TREASURY_ORGANIZATION_ID\"")
  end

  @api_key = api_key.to_s
  @organization_id = organization_id.to_s

  super(
    base_url: base_url,
    timeout: timeout,
    max_retries: max_retries,
    initial_retry_delay: initial_retry_delay,
    max_retry_delay: max_retry_delay,
    idempotency_header: idempotency_header
  )

  @connections = ModernTreasury::Resources::Connections.new(client: self)
  @counterparties = ModernTreasury::Resources::Counterparties.new(client: self)
  @events = ModernTreasury::Resources::Events.new(client: self)
  @expected_payments = ModernTreasury::Resources::ExpectedPayments.new(client: self)
  @external_accounts = ModernTreasury::Resources::ExternalAccounts.new(client: self)
  @incoming_payment_details = ModernTreasury::Resources::IncomingPaymentDetails.new(client: self)
  @invoices = ModernTreasury::Resources::Invoices.new(client: self)
  @documents = ModernTreasury::Resources::Documents.new(client: self)
  @account_collection_flows = ModernTreasury::Resources::AccountCollectionFlows.new(client: self)
  @account_details = ModernTreasury::Resources::AccountDetails.new(client: self)
  @routing_details = ModernTreasury::Resources::RoutingDetails.new(client: self)
  @internal_accounts = ModernTreasury::Resources::InternalAccounts.new(client: self)
  @ledgers = ModernTreasury::Resources::Ledgers.new(client: self)
  @ledger_account_categories = ModernTreasury::Resources::LedgerAccountCategories.new(client: self)
  @ledger_accounts = ModernTreasury::Resources::LedgerAccounts.new(client: self)
  @ledger_account_balance_monitors =
    ModernTreasury::Resources::LedgerAccountBalanceMonitors.new(client: self)
  @ledger_account_statements = ModernTreasury::Resources::LedgerAccountStatements.new(client: self)
  @ledger_entries = ModernTreasury::Resources::LedgerEntries.new(client: self)
  @ledger_transactions = ModernTreasury::Resources::LedgerTransactions.new(client: self)
  @line_items = ModernTreasury::Resources::LineItems.new(client: self)
  @payment_flows = ModernTreasury::Resources::PaymentFlows.new(client: self)
  @payment_orders = ModernTreasury::Resources::PaymentOrders.new(client: self)
  @payment_references = ModernTreasury::Resources::PaymentReferences.new(client: self)
  @returns = ModernTreasury::Resources::Returns.new(client: self)
  @transactions = ModernTreasury::Resources::Transactions.new(client: self)
  @validations = ModernTreasury::Resources::Validations.new(client: self)
  @virtual_accounts = ModernTreasury::Resources::VirtualAccounts.new(client: self)
  @bulk_requests = ModernTreasury::Resources::BulkRequests.new(client: self)
  @bulk_results = ModernTreasury::Resources::BulkResults.new(client: self)
  @ledger_account_settlements = ModernTreasury::Resources::LedgerAccountSettlements.new(client: self)
  @foreign_exchange_quotes = ModernTreasury::Resources::ForeignExchangeQuotes.new(client: self)
  @connection_legal_entities = ModernTreasury::Resources::ConnectionLegalEntities.new(client: self)
  @legal_entities = ModernTreasury::Resources::LegalEntities.new(client: self)
  @legal_entity_associations = ModernTreasury::Resources::LegalEntityAssociations.new(client: self)
  @payment_actions = ModernTreasury::Resources::PaymentActions.new(client: self)
  @journal_entries = ModernTreasury::Resources::JournalEntries.new(client: self)
  @journal_reports = ModernTreasury::Resources::JournalReports.new(client: self)
  @holds = ModernTreasury::Resources::Holds.new(client: self)
end

Instance Attribute Details

#account_collection_flowsModernTreasury::Resources::AccountCollectionFlows (readonly)



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

def 
  @account_collection_flows
end

#account_detailsModernTreasury::Resources::AccountDetails (readonly)



52
53
54
# File 'lib/modern_treasury/client.rb', line 52

def 
  @account_details
end

#api_keyString (readonly)

Returns:

  • (String)


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

def api_key
  @api_key
end

#bulk_requestsModernTreasury::Resources::BulkRequests (readonly)



106
107
108
# File 'lib/modern_treasury/client.rb', line 106

def bulk_requests
  @bulk_requests
end

#bulk_resultsModernTreasury::Resources::BulkResults (readonly)



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

def bulk_results
  @bulk_results
end


118
119
120
# File 'lib/modern_treasury/client.rb', line 118

def connection_legal_entities
  @connection_legal_entities
end

#connectionsModernTreasury::Resources::Connections (readonly)



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

def connections
  @connections
end

#counterpartiesModernTreasury::Resources::Counterparties (readonly)



28
29
30
# File 'lib/modern_treasury/client.rb', line 28

def counterparties
  @counterparties
end

#documentsModernTreasury::Resources::Documents (readonly)



46
47
48
# File 'lib/modern_treasury/client.rb', line 46

def documents
  @documents
end

#eventsModernTreasury::Resources::Events (readonly)



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

def events
  @events
end

#expected_paymentsModernTreasury::Resources::ExpectedPayments (readonly)



34
35
36
# File 'lib/modern_treasury/client.rb', line 34

def expected_payments
  @expected_payments
end

#external_accountsModernTreasury::Resources::ExternalAccounts (readonly)



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

def external_accounts
  @external_accounts
end

#foreign_exchange_quotesModernTreasury::Resources::ForeignExchangeQuotes (readonly)



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

def foreign_exchange_quotes
  @foreign_exchange_quotes
end

#holdsModernTreasury::Resources::Holds (readonly)



136
137
138
# File 'lib/modern_treasury/client.rb', line 136

def holds
  @holds
end

#incoming_payment_detailsModernTreasury::Resources::IncomingPaymentDetails (readonly)



40
41
42
# File 'lib/modern_treasury/client.rb', line 40

def incoming_payment_details
  @incoming_payment_details
end

#internal_accountsModernTreasury::Resources::InternalAccounts (readonly)



58
59
60
# File 'lib/modern_treasury/client.rb', line 58

def internal_accounts
  @internal_accounts
end

#invoicesModernTreasury::Resources::Invoices (readonly)



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

def invoices
  @invoices
end

#journal_entriesModernTreasury::Resources::JournalEntries (readonly)



130
131
132
# File 'lib/modern_treasury/client.rb', line 130

def journal_entries
  @journal_entries
end

#journal_reportsModernTreasury::Resources::JournalReports (readonly)



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

def journal_reports
  @journal_reports
end

#ledger_account_balance_monitorsModernTreasury::Resources::LedgerAccountBalanceMonitors (readonly)



70
71
72
# File 'lib/modern_treasury/client.rb', line 70

def 
  @ledger_account_balance_monitors
end

#ledger_account_categoriesModernTreasury::Resources::LedgerAccountCategories (readonly)



64
65
66
# File 'lib/modern_treasury/client.rb', line 64

def 
  @ledger_account_categories
end

#ledger_account_settlementsModernTreasury::Resources::LedgerAccountSettlements (readonly)



112
113
114
# File 'lib/modern_treasury/client.rb', line 112

def 
  @ledger_account_settlements
end

#ledger_account_statementsModernTreasury::Resources::LedgerAccountStatements (readonly)



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

def 
  @ledger_account_statements
end

#ledger_accountsModernTreasury::Resources::LedgerAccounts (readonly)



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

def ledger_accounts
  @ledger_accounts
end

#ledger_entriesModernTreasury::Resources::LedgerEntries (readonly)



76
77
78
# File 'lib/modern_treasury/client.rb', line 76

def ledger_entries
  @ledger_entries
end

#ledger_transactionsModernTreasury::Resources::LedgerTransactions (readonly)



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

def ledger_transactions
  @ledger_transactions
end

#ledgersModernTreasury::Resources::Ledgers (readonly)



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

def ledgers
  @ledgers
end


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

def legal_entities
  @legal_entities
end


124
125
126
# File 'lib/modern_treasury/client.rb', line 124

def legal_entity_associations
  @legal_entity_associations
end

#line_itemsModernTreasury::Resources::LineItems (readonly)



82
83
84
# File 'lib/modern_treasury/client.rb', line 82

def line_items
  @line_items
end

#organization_idString (readonly)

Returns:

  • (String)


22
23
24
# File 'lib/modern_treasury/client.rb', line 22

def organization_id
  @organization_id
end

#payment_actionsModernTreasury::Resources::PaymentActions (readonly)



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

def payment_actions
  @payment_actions
end

#payment_flowsModernTreasury::Resources::PaymentFlows (readonly)



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

def payment_flows
  @payment_flows
end

#payment_ordersModernTreasury::Resources::PaymentOrders (readonly)



88
89
90
# File 'lib/modern_treasury/client.rb', line 88

def payment_orders
  @payment_orders
end

#payment_referencesModernTreasury::Resources::PaymentReferences (readonly)



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

def payment_references
  @payment_references
end

#returnsModernTreasury::Resources::Returns (readonly)



94
95
96
# File 'lib/modern_treasury/client.rb', line 94

def returns
  @returns
end

#routing_detailsModernTreasury::Resources::RoutingDetails (readonly)



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

def routing_details
  @routing_details
end

#transactionsModernTreasury::Resources::Transactions (readonly)



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

def transactions
  @transactions
end

#validationsModernTreasury::Resources::Validations (readonly)



100
101
102
# File 'lib/modern_treasury/client.rb', line 100

def validations
  @validations
end

#virtual_accountsModernTreasury::Resources::VirtualAccounts (readonly)



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

def virtual_accounts
  @virtual_accounts
end

Instance Method Details

#ping(request_options: {}) ⇒ ModernTreasury::Models::PingResponse

A test endpoint often used to confirm credentials and headers are being passed in correctly.

Parameters:

Returns:

See Also:



148
149
150
151
152
153
154
155
# File 'lib/modern_treasury/client.rb', line 148

def ping(params = {})
  request(
    method: :get,
    path: "api/ping",
    model: ModernTreasury::PingResponse,
    options: params[:request_options]
  )
end