Class: DeliveryFivePostClient::Client
- Inherits:
-
Internal::Transport::BaseClient
- Object
- Internal::Transport::BaseClient
- DeliveryFivePostClient::Client
- Defined in:
- lib/delivery_five_post_client/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://api-preprod-omni.x5.ru", environment_1: "https://api-omni.x5.ru"}
Constants inherited from Internal::Transport::BaseClient
Internal::Transport::BaseClient::MAX_REDIRECTS, Internal::Transport::BaseClient::PLATFORM_HEADERS
Instance Attribute Summary collapse
- #api ⇒ DeliveryFivePostClient::Resources::API readonly
- #api_key ⇒ String readonly
- #webhooks ⇒ DeliveryFivePostClient::Resources::Webhooks readonly
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["DELIVERY_FIVE_POST_CLIENT_API_KEY"], environment: nil, base_url: ENV["DELIVERY_FIVE_POST_CLIENT_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["DELIVERY_FIVE_POST_CLIENT_API_KEY"], environment: nil, base_url: ENV["DELIVERY_FIVE_POST_CLIENT_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.
Each environment maps to a different base URL:
productioncorresponds tohttps://api-preprod-omni.x5.ruenvironment_1corresponds tohttps://api-omni.x5.ru
"https://api.example.com/v2/". Defaults to
ENV["DELIVERY_FIVE_POST_CLIENT_BASE_URL"]
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/delivery_five_post_client/client.rb', line 63 def initialize( api_key: ENV["DELIVERY_FIVE_POST_CLIENT_API_KEY"], environment: nil, base_url: ENV["DELIVERY_FIVE_POST_CLIENT_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 ||= DeliveryFivePostClient::Client::ENVIRONMENTS.fetch(environment&.to_sym || :production) do = "environment must be one of #{DeliveryFivePostClient::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: \"DELIVERY_FIVE_POST_CLIENT_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 ) @api = DeliveryFivePostClient::Resources::API.new(client: self) @webhooks = DeliveryFivePostClient::Resources::Webhooks.new(client: self) end |
Instance Attribute Details
#api ⇒ DeliveryFivePostClient::Resources::API (readonly)
27 28 29 |
# File 'lib/delivery_five_post_client/client.rb', line 27 def api @api end |
#api_key ⇒ String (readonly)
24 25 26 |
# File 'lib/delivery_five_post_client/client.rb', line 24 def api_key @api_key end |
#webhooks ⇒ DeliveryFivePostClient::Resources::Webhooks (readonly)
30 31 32 |
# File 'lib/delivery_five_post_client/client.rb', line 30 def webhooks @webhooks end |