Class: AdvancedBilling::Configuration
- Inherits:
-
CoreLibrary::HttpClientConfiguration
- Object
- CoreLibrary::HttpClientConfiguration
- AdvancedBilling::Configuration
- Defined in:
- lib/advanced_billing/configuration.rb
Overview
All configuration including auth info and base URI for the API access are configured in this class.
Constant Summary collapse
- ENVIRONMENTS =
All the environments the SDK can run in.
{ Environment::PRODUCTION => { Server::DEFAULT => 'https://{subdomain}.{domain}' }, Environment::ENVIRONMENT2 => { Server::DEFAULT => 'https://events.chargify.com' } }.freeze
Class Attribute Summary collapse
-
.environments ⇒ Object
readonly
Returns the value of attribute environments.
Instance Attribute Summary collapse
-
#basic_auth_credentials ⇒ Object
readonly
The attribute readers for properties.
-
#domain ⇒ Object
readonly
The attribute readers for properties.
-
#environment ⇒ Object
readonly
The attribute readers for properties.
-
#subdomain ⇒ Object
readonly
The attribute readers for properties.
Instance Method Summary collapse
- #basic_auth_password ⇒ Object
- #basic_auth_user_name ⇒ Object
- #clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, environment: nil, subdomain: nil, domain: nil, basic_auth_user_name: nil, basic_auth_password: nil, basic_auth_credentials: nil) ⇒ Object
- #create_auth_credentials_object(basic_auth_user_name, basic_auth_password, basic_auth_credentials) ⇒ Object
-
#get_base_uri(server = Server::DEFAULT) ⇒ String
Generates the appropriate base URI for the environment and the server.
-
#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], retry_methods: %i[get put],, http_callback: nil, environment: Environment::PRODUCTION, subdomain: 'subdomain', domain: 'chargify.com', basic_auth_user_name: nil, basic_auth_password: nil, basic_auth_credentials: nil) ⇒ Configuration
constructor
A new instance of Configuration.
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], retry_methods: %i[get put],, http_callback: nil, environment: Environment::PRODUCTION, subdomain: 'subdomain', domain: 'chargify.com', basic_auth_user_name: nil, basic_auth_password: nil, basic_auth_credentials: nil) ⇒ Configuration
Returns a new instance of Configuration.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/advanced_billing/configuration.rb', line 42 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], retry_methods: %i[get put], http_callback: nil, environment: Environment::PRODUCTION, subdomain: 'subdomain', domain: 'chargify.com', basic_auth_user_name: nil, basic_auth_password: nil, basic_auth_credentials: nil ) super 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: http_callback # Current API environment @environment = String(environment) # The subdomain for your Chargify site. @subdomain = subdomain # The Chargify server domain. @domain = domain # The username to use with basic authentication @basic_auth_user_name = basic_auth_user_name # The password to use with basic authentication @basic_auth_password = basic_auth_password # Initializing Basic Authentication credentials with the provided auth parameters @basic_auth_credentials = create_auth_credentials_object( basic_auth_user_name, basic_auth_password, basic_auth_credentials ) # The Http Client to use for making requests. set_http_client CoreLibrary::FaradayClient.new(self) end |
Class Attribute Details
.environments ⇒ Object (readonly)
Returns the value of attribute environments.
39 40 41 |
# File 'lib/advanced_billing/configuration.rb', line 39 def environments @environments end |
Instance Attribute Details
#basic_auth_credentials ⇒ Object (readonly)
The attribute readers for properties.
36 37 38 |
# File 'lib/advanced_billing/configuration.rb', line 36 def basic_auth_credentials @basic_auth_credentials end |
#domain ⇒ Object (readonly)
The attribute readers for properties.
36 37 38 |
# File 'lib/advanced_billing/configuration.rb', line 36 def domain @domain end |
#environment ⇒ Object (readonly)
The attribute readers for properties.
36 37 38 |
# File 'lib/advanced_billing/configuration.rb', line 36 def environment @environment end |
#subdomain ⇒ Object (readonly)
The attribute readers for properties.
36 37 38 |
# File 'lib/advanced_billing/configuration.rb', line 36 def subdomain @subdomain end |
Instance Method Details
#basic_auth_password ⇒ Object
31 32 33 |
# File 'lib/advanced_billing/configuration.rb', line 31 def basic_auth_password @basic_auth_credentials.password end |
#basic_auth_user_name ⇒ Object
27 28 29 |
# File 'lib/advanced_billing/configuration.rb', line 27 def basic_auth_user_name @basic_auth_credentials.username end |
#clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, environment: nil, subdomain: nil, domain: nil, basic_auth_user_name: nil, basic_auth_password: nil, basic_auth_credentials: nil) ⇒ Object
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 |
# File 'lib/advanced_billing/configuration.rb', line 81 def clone_with(connection: nil, adapter: nil, timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, http_callback: nil, environment: nil, subdomain: nil, domain: nil, basic_auth_user_name: nil, basic_auth_password: nil, basic_auth_credentials: nil) connection ||= self.connection adapter ||= self.adapter timeout ||= self.timeout max_retries ||= self.max_retries retry_interval ||= self.retry_interval backoff_factor ||= self.backoff_factor retry_statuses ||= self.retry_statuses retry_methods ||= self.retry_methods http_callback ||= self.http_callback environment ||= self.environment subdomain ||= self.subdomain domain ||= self.domain basic_auth_credentials = create_auth_credentials_object( basic_auth_user_name, basic_auth_password, basic_auth_credentials || self.basic_auth_credentials ) 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: http_callback, environment: environment, subdomain: subdomain, domain: domain, basic_auth_credentials: basic_auth_credentials) end |
#create_auth_credentials_object(basic_auth_user_name, basic_auth_password, basic_auth_credentials) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/advanced_billing/configuration.rb', line 115 def create_auth_credentials_object(basic_auth_user_name, basic_auth_password, basic_auth_credentials) return basic_auth_credentials if basic_auth_user_name.nil? && basic_auth_password.nil? warn('The \'basic_auth_user_name\', \'basic_auth_password\' params are d'\ 'eprecated. Use \'basic_auth_credentials\' param instead.') unless basic_auth_credentials.nil? return basic_auth_credentials.clone_with( username: basic_auth_user_name, password: basic_auth_password ) end BasicAuthCredentials.new(username: basic_auth_user_name, password: basic_auth_password) end |
#get_base_uri(server = Server::DEFAULT) ⇒ String
Generates the appropriate base URI for the environment and the server. required.
148 149 150 151 152 153 154 155 156 |
# File 'lib/advanced_billing/configuration.rb', line 148 def get_base_uri(server = Server::DEFAULT) parameters = { 'subdomain' => { 'value' => subdomain, 'encode' => false }, 'domain' => { 'value' => domain, 'encode' => false } } APIHelper.append_url_with_template_parameters( ENVIRONMENTS[environment][server], parameters ) end |