Class: MethodRuby::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- MethodRuby::Client
- Defined in:
- lib/method_ruby/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- ENVIRONMENTS =
rubocop:disable Style/MutableConstant
{ production: "https://production.methodfi.com", sandbox: "https://sandbox.methodfi.com", dev: "https://dev.methodfi.com" }
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
-
#accounts ⇒ MethodRuby::Resources::Accounts
readonly
Financial accounts (ACH, liability, clearing, debit card).
-
#api_key ⇒ String
readonly
Secret key for API authentication.
-
#card_products ⇒ MethodRuby::Resources::CardProducts
readonly
Card product definitions.
-
#entities ⇒ MethodRuby::Resources::Entities
readonly
Individuals, corporations, and receive-only entities.
-
#events ⇒ MethodRuby::Resources::Events
readonly
Webhook event log.
-
#forwarding_requests ⇒ MethodRuby::Resources::ForwardingRequests
readonly
Request forwarding with sensitive data injection.
-
#managed_accounts ⇒ MethodRuby::Resources::ManagedAccounts
readonly
Method-managed accounts.
-
#merchants ⇒ MethodRuby::Resources::Merchants
readonly
Merchant directory.
-
#opal_token ⇒ String?
readonly
Opal token for Opal session endpoints.
-
#payments ⇒ MethodRuby::Resources::Payments
readonly
ACH and clearing payments.
-
#ping ⇒ MethodRuby::Resources::Ping
readonly
Health check endpoint.
-
#reports ⇒ MethodRuby::Resources::Reports
readonly
Downloadable reports.
-
#secrets ⇒ MethodRuby::Resources::Secrets
readonly
Secure secret storage.
- #simulate ⇒ MethodRuby::Resources::Simulate readonly
-
#teams ⇒ MethodRuby::Resources::Teams
readonly
Team and API key management.
-
#webhooks ⇒ MethodRuby::Resources::Webhooks
readonly
Webhook subscriptions.
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
-
#initialize(api_key: ENV["METHOD_API_KEY"], opal_token: nil, environment: nil, base_url: ENV["METHOD_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) ⇒ Client
constructor
Creates and returns a new client for interacting with the API.
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: ENV["METHOD_API_KEY"], opal_token: nil, environment: nil, base_url: ENV["METHOD_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) ⇒ Client
Creates and returns a new client for interacting with the API.
token. Defaults to ‘ENV`
Each environment maps to a different base URL:
-
‘production` corresponds to `production.methodfi.com`
-
‘sandbox` corresponds to `sandbox.methodfi.com`
-
‘dev` corresponds to `dev.methodfi.com`
‘“api.example.com/v2/”`. Defaults to `ENV`
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/method_ruby/client.rb', line 144 def initialize( api_key: ENV["METHOD_API_KEY"], opal_token: nil, environment: nil, base_url: ENV["METHOD_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 ) base_url ||= MethodRuby::Client::ENVIRONMENTS.fetch(environment&.to_sym || :production) do = "environment must be one of #{MethodRuby::Client::ENVIRONMENTS.keys}, got #{environment}" raise ArgumentError.new() end if api_key.nil? raise ArgumentError.new("api_key is required, and can be set via environ: \"METHOD_API_KEY\"") end headers = {} custom_headers_env = ENV["METHOD_CUSTOM_HEADERS"] unless custom_headers_env.nil? parsed = {} custom_headers_env.split("\n").each do |line| colon = line.index(":") unless colon.nil? parsed[line[0...colon].strip] = line[(colon + 1)..].strip end end headers = parsed.merge(headers) end @api_key = api_key.to_s @opal_token = opal_token&.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, headers: headers ) @entities = MethodRuby::Resources::Entities.new(client: self) @accounts = MethodRuby::Resources::Accounts.new(client: self) @managed_accounts = MethodRuby::Resources::ManagedAccounts.new(client: self) @merchants = MethodRuby::Resources::Merchants.new(client: self) @payments = MethodRuby::Resources::Payments.new(client: self) @reports = MethodRuby::Resources::Reports.new(client: self) @simulate = MethodRuby::Resources::Simulate.new(client: self) @teams = MethodRuby::Resources::Teams.new(client: self) @webhooks = MethodRuby::Resources::Webhooks.new(client: self) @events = MethodRuby::Resources::Events.new(client: self) @forwarding_requests = MethodRuby::Resources::ForwardingRequests.new(client: self) @secrets = MethodRuby::Resources::Secrets.new(client: self) @card_products = MethodRuby::Resources::CardProducts.new(client: self) @ping = MethodRuby::Resources::Ping.new(client: self) end |
Instance Attribute Details
#accounts ⇒ MethodRuby::Resources::Accounts (readonly)
Financial accounts (ACH, liability, clearing, debit card)
43 44 45 |
# File 'lib/method_ruby/client.rb', line 43 def accounts @accounts end |
#api_key ⇒ String (readonly)
Secret key for API authentication. Use your team’s secret key as the Bearer token.
31 32 33 |
# File 'lib/method_ruby/client.rb', line 31 def api_key @api_key end |
#card_products ⇒ MethodRuby::Resources::CardProducts (readonly)
Card product definitions
86 87 88 |
# File 'lib/method_ruby/client.rb', line 86 def card_products @card_products end |
#entities ⇒ MethodRuby::Resources::Entities (readonly)
Individuals, corporations, and receive-only entities
39 40 41 |
# File 'lib/method_ruby/client.rb', line 39 def entities @entities end |
#events ⇒ MethodRuby::Resources::Events (readonly)
Webhook event log
74 75 76 |
# File 'lib/method_ruby/client.rb', line 74 def events @events end |
#forwarding_requests ⇒ MethodRuby::Resources::ForwardingRequests (readonly)
Request forwarding with sensitive data injection
78 79 80 |
# File 'lib/method_ruby/client.rb', line 78 def forwarding_requests @forwarding_requests end |
#managed_accounts ⇒ MethodRuby::Resources::ManagedAccounts (readonly)
Method-managed accounts
47 48 49 |
# File 'lib/method_ruby/client.rb', line 47 def managed_accounts @managed_accounts end |
#merchants ⇒ MethodRuby::Resources::Merchants (readonly)
Merchant directory
51 52 53 |
# File 'lib/method_ruby/client.rb', line 51 def merchants @merchants end |
#opal_token ⇒ String? (readonly)
Opal token for Opal session endpoints.
35 36 37 |
# File 'lib/method_ruby/client.rb', line 35 def opal_token @opal_token end |
#payments ⇒ MethodRuby::Resources::Payments (readonly)
ACH and clearing payments
55 56 57 |
# File 'lib/method_ruby/client.rb', line 55 def payments @payments end |
#ping ⇒ MethodRuby::Resources::Ping (readonly)
Health check endpoint
90 91 92 |
# File 'lib/method_ruby/client.rb', line 90 def ping @ping end |
#reports ⇒ MethodRuby::Resources::Reports (readonly)
Downloadable reports
59 60 61 |
# File 'lib/method_ruby/client.rb', line 59 def reports @reports end |
#secrets ⇒ MethodRuby::Resources::Secrets (readonly)
Secure secret storage
82 83 84 |
# File 'lib/method_ruby/client.rb', line 82 def secrets @secrets end |
#simulate ⇒ MethodRuby::Resources::Simulate (readonly)
62 63 64 |
# File 'lib/method_ruby/client.rb', line 62 def simulate @simulate end |
#teams ⇒ MethodRuby::Resources::Teams (readonly)
Team and API key management
66 67 68 |
# File 'lib/method_ruby/client.rb', line 66 def teams @teams end |
#webhooks ⇒ MethodRuby::Resources::Webhooks (readonly)
Webhook subscriptions
70 71 72 |
# File 'lib/method_ruby/client.rb', line 70 def webhooks @webhooks end |