Module: CDEKApiClient::Config
- Defined in:
- lib/cdek_api_client/config.rb
Overview
Configuration module for CDEK API Client
Constant Summary collapse
- PRODUCTION =
Available API environments
'production'- DEMO =
'demo'- ENDPOINTS =
API endpoints for different environments
{ PRODUCTION => 'https://api.cdek.ru/v2', DEMO => 'https://api.edu.cdek.ru/v2' }.freeze
Class Method Summary collapse
-
.base_url(environment: nil, custom_url: nil) ⇒ String
Get the base URL for the current configuration.
-
.token_url(environment: nil, custom_url: nil) ⇒ String
Get the token URL for authentication.
Class Method Details
.base_url(environment: nil, custom_url: nil) ⇒ String
Get the base URL for the current configuration
21 22 23 24 25 26 27 28 |
# File 'lib/cdek_api_client/config.rb', line 21 def base_url(environment: nil, custom_url: nil) return custom_url if custom_url env = environment&.to_s&.downcase || ENV.fetch('CDEK_API_ENV', DEMO) ENDPOINTS.fetch(env) do raise ArgumentError, "Unknown environment: #{env}. Use :production or :demo" end end |
.token_url(environment: nil, custom_url: nil) ⇒ String
Get the token URL for authentication
34 35 36 |
# File 'lib/cdek_api_client/config.rb', line 34 def token_url(environment: nil, custom_url: nil) "#{base_url(environment: environment, custom_url: custom_url)}/oauth/token" end |