Class: UnivapayClientSdk::Client
- Inherits:
-
Object
- Object
- UnivapayClientSdk::Client
- Includes:
- CoreLibrary
- Defined in:
- lib/univapay_client_sdk/client.rb,
lib/univapay_client_sdk/extensions.rb
Overview
Reopened onto the generated client class to expose the app token's context.
Instance Attribute Summary collapse
-
#auth_managers ⇒ Object
readonly
Returns the value of attribute auth_managers.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Class Method Summary collapse
-
.from_env(**overrides) ⇒ Object
Creates a client directly from environment variables.
Instance Method Summary collapse
-
#cancels ⇒ CancelsApi
Access to cancels controller.
-
#charges ⇒ ChargesApi
Access to charges controller.
-
#direct_debit ⇒ DirectDebitApi
Access to direct_debit controller.
-
#get_current_merchant_id ⇒ String?
The merchant this client's app token was issued for, decoded from the configured JWT.
-
#get_current_store_id ⇒ String?
The store this client's app token was issued for, decoded from the configured JWT.
-
#initialize(connection: nil, adapter: :net_http_persistent, timeout: 30, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put get put],, http_callback: nil, proxy_settings: nil, logging_configuration: nil, environment: Environment::PRODUCTION, base_url: 'https://api.univapay.com', direct_debit_base_url: 'https://direct-debit.gopay-services.com', bearer_auth_credentials: nil, config: nil) ⇒ Client
constructor
A new instance of Client.
-
#initialize_auth_managers(global_config) ⇒ Object
Initializes the auth managers hash used for authenticating API calls.
-
#merchants ⇒ MerchantsApi
Access to merchants controller.
-
#refunds ⇒ RefundsApi
Access to refunds controller.
-
#stores ⇒ StoresApi
Access to stores controller.
-
#subscriptions ⇒ SubscriptionsApi
Access to subscriptions controller.
-
#transaction_tokens ⇒ TransactionTokensApi
Access to transaction_tokens controller.
- #user_agent_detail ⇒ Object
-
#webhooks ⇒ WebhooksApi
Access to webhooks controller.
Constructor Details
#initialize(connection: nil, adapter: :net_http_persistent, timeout: 30, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put get put],, http_callback: nil, proxy_settings: nil, logging_configuration: nil, environment: Environment::PRODUCTION, base_url: 'https://api.univapay.com', direct_debit_base_url: 'https://direct-debit.gopay-services.com', bearer_auth_credentials: nil, config: nil) ⇒ Client
Returns a new instance of Client.
76 77 78 79 80 81 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 113 114 115 116 117 118 |
# File 'lib/univapay_client_sdk/client.rb', line 76 def initialize( connection: nil, adapter: :net_http_persistent, timeout: 30, max_retries: 0, retry_interval: 1, backoff_factor: 2, retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524, 408, 413, 429, 500, 502, 503, 504, 521, 522, 524], retry_methods: %i[get put get put], http_callback: nil, proxy_settings: nil, logging_configuration: nil, environment: Environment::PRODUCTION, base_url: 'https://api.univapay.com', direct_debit_base_url: 'https://direct-debit.gopay-services.com', bearer_auth_credentials: nil, config: nil ) @config = if config.nil? Configuration.new( connection: connection, adapter: adapter, timeout: timeout, max_retries: max_retries, retry_interval: retry_interval, backoff_factor: backoff_factor, retry_statuses: retry_statuses, retry_methods: retry_methods, http_callback: IdempotencyCallback.new(http_callback), proxy_settings: proxy_settings, logging_configuration: logging_configuration, environment: environment, base_url: base_url, direct_debit_base_url: direct_debit_base_url, bearer_auth_credentials: bearer_auth_credentials ) elsif config.http_callback.is_a?(IdempotencyCallback) config else config.clone_with( http_callback: IdempotencyCallback.new(config.http_callback) ) end user_agent_params = BaseApi.user_agent_parameters @global_configuration = GlobalConfiguration.new(client_configuration: @config) .base_uri_executor(@config.method(:get_base_uri)) .global_errors(BaseApi::GLOBAL_ERRORS) .user_agent(BaseApi.user_agent, agent_parameters: user_agent_params) initialize_auth_managers(@global_configuration) @global_configuration = @global_configuration.auth_managers(@auth_managers) end |
Instance Attribute Details
#auth_managers ⇒ Object (readonly)
Returns the value of attribute auth_managers.
16 17 18 |
# File 'lib/univapay_client_sdk/client.rb', line 16 def auth_managers @auth_managers end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
16 17 18 |
# File 'lib/univapay_client_sdk/client.rb', line 16 def config @config end |
Class Method Details
.from_env(**overrides) ⇒ Object
Creates a client directly from environment variables.
130 131 132 133 134 |
# File 'lib/univapay_client_sdk/client.rb', line 130 def self.from_env(**overrides) default_config = Configuration.build_default_config_from_env new_config = default_config.clone_with(**overrides) new(config: new_config) end |
Instance Method Details
#cancels ⇒ CancelsApi
Access to cancels controller.
48 49 50 |
# File 'lib/univapay_client_sdk/client.rb', line 48 def cancels @cancels ||= CancelsApi.new @global_configuration end |
#charges ⇒ ChargesApi
Access to charges controller.
24 25 26 |
# File 'lib/univapay_client_sdk/client.rb', line 24 def charges @charges ||= ChargesApi.new @global_configuration end |
#direct_debit ⇒ DirectDebitApi
Access to direct_debit controller.
72 73 74 |
# File 'lib/univapay_client_sdk/client.rb', line 72 def direct_debit @direct_debit ||= DirectDebitApi.new @global_configuration end |
#get_current_merchant_id ⇒ String?
The merchant this client's app token was issued for, decoded from the configured JWT.
Both merchant-level and store-level app tokens carry a merchant, so this is set for either kind of token.
245 246 247 |
# File 'lib/univapay_client_sdk/extensions.rb', line 245 def get_current_merchant_id AppJwt.read_uuid_claim(jwt_token_or_nil, 'merchant_id') end |
#get_current_store_id ⇒ String?
The store this client's app token was issued for, decoded from the configured JWT.
Only store-level app tokens are scoped to a store. A merchant-level token
carries no store_id claim, so this returns nil for one -- use stores
to list the merchant's stores instead.
258 259 260 |
# File 'lib/univapay_client_sdk/extensions.rb', line 258 def get_current_store_id AppJwt.read_uuid_claim(jwt_token_or_nil, 'store_id') end |
#initialize_auth_managers(global_config) ⇒ Object
Initializes the auth managers hash used for authenticating API calls.
122 123 124 125 126 127 |
# File 'lib/univapay_client_sdk/client.rb', line 122 def initialize_auth_managers(global_config) @auth_managers = {} http_client_config = global_config.client_configuration %w[JWT_TOKEN].each { |auth| @auth_managers[auth] = nil } @auth_managers['JWT_TOKEN'] = Oauth2.new(http_client_config.bearer_auth_credentials) end |
#merchants ⇒ MerchantsApi
Access to merchants controller.
54 55 56 |
# File 'lib/univapay_client_sdk/client.rb', line 54 def merchants @merchants ||= MerchantsApi.new @global_configuration end |
#refunds ⇒ RefundsApi
Access to refunds controller.
36 37 38 |
# File 'lib/univapay_client_sdk/client.rb', line 36 def refunds @refunds ||= RefundsApi.new @global_configuration end |
#stores ⇒ StoresApi
Access to stores controller.
60 61 62 |
# File 'lib/univapay_client_sdk/client.rb', line 60 def stores @stores ||= StoresApi.new @global_configuration end |
#subscriptions ⇒ SubscriptionsApi
Access to subscriptions controller.
42 43 44 |
# File 'lib/univapay_client_sdk/client.rb', line 42 def subscriptions @subscriptions ||= SubscriptionsApi.new @global_configuration end |
#transaction_tokens ⇒ TransactionTokensApi
Access to transaction_tokens controller.
30 31 32 |
# File 'lib/univapay_client_sdk/client.rb', line 30 def transaction_tokens @transaction_tokens ||= TransactionTokensApi.new @global_configuration end |
#user_agent_detail ⇒ Object
18 19 20 |
# File 'lib/univapay_client_sdk/client.rb', line 18 def user_agent_detail config.user_agent_detail end |
#webhooks ⇒ WebhooksApi
Access to webhooks controller.
66 67 68 |
# File 'lib/univapay_client_sdk/client.rb', line 66 def webhooks @webhooks ||= WebhooksApi.new @global_configuration end |