Class: MethodRuby::Client

Inherits:
Internal::Transport::BaseClient show all
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

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: ENV["METHOD_API_KEY"], 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.

to ‘ENV`

Each environment maps to a different base URL:

  • production corresponds to https://production.methodfi.com

  • sandbox corresponds to https://sandbox.methodfi.com

  • dev corresponds to https://dev.methodfi.com

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

Parameters:

  • api_key (String, nil) (defaults to: ENV["METHOD_API_KEY"])

    API key-based authentication. Include your API key as a Bearer token. Defaults

  • environment (:production, :sandbox, :dev, nil) (defaults to: nil)

    Specifies the environment to use for the API.

  • base_url (String, nil) (defaults to: ENV["METHOD_BASE_URL"])

    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)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/method_ruby/client.rb', line 82

def initialize(
  api_key: ENV["METHOD_API_KEY"],
  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
    message = "environment must be one of #{MethodRuby::Client::ENVIRONMENTS.keys}, got #{environment}"
    raise ArgumentError.new(message)
  end

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

  @api_key = api_key.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
  )

  @entities = MethodRuby::Resources::Entities.new(client: self)
  @ping = MethodRuby::Resources::Ping.new(client: self)
end

Instance Attribute Details

#api_keyString (readonly)

API key-based authentication. Include your API key as a Bearer token.

Returns:

  • (String)


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

def api_key
  @api_key
end

#entitiesMethodRuby::Resources::Entities (readonly)

Entities represent your application’s end-users. An Entity is the legal holder of an Account and can be either an individual or a corporation.



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

def entities
  @entities
end

#pingMethodRuby::Resources::Ping (readonly)

API health check endpoint.



39
40
41
# File 'lib/method_ruby/client.rb', line 39

def ping
  @ping
end