Class: Square::Configuration
- Inherits:
-
Object
- Object
- Square::Configuration
- Defined in:
- lib/square/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.
{ 'production' => { 'default' => 'https://connect.squareup.com' }, 'sandbox' => { 'default' => 'https://connect.squareupsandbox.com' }, 'custom' => { 'default' => '{custom_url}' } }.freeze
Class Attribute Summary collapse
-
.environments ⇒ Object
readonly
Returns the value of attribute environments.
Instance Method Summary collapse
- #clone_with(timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, environment: nil, custom_url: nil, square_version: nil, access_token: nil, additional_headers: nil) ⇒ Object
- #create_http_client ⇒ Object
-
#get_base_uri(server = 'default') ⇒ String
Generates the appropriate base URI for the environment and the server.
-
#initialize(timeout: 60, 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], environment: 'production', custom_url: 'https://connect.squareup.com', square_version: '2021-09-15', access_token: 'TODO: Replace', additional_headers: {}) ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize(timeout: 60, 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], environment: 'production', custom_url: 'https://connect.squareup.com', square_version: '2021-09-15', access_token: 'TODO: Replace', additional_headers: {}) ⇒ Configuration
Returns a new instance of Configuration.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/square/configuration.rb', line 19 def initialize(timeout: 60, 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], environment: 'production', custom_url: 'https://connect.squareup.com', square_version: '2021-09-15', access_token: 'TODO: Replace', additional_headers: {}) # The value to use for connection timeout @timeout = timeout # The number of times to retry an endpoint call if it fails @max_retries = max_retries # Pause in seconds between retries @retry_interval = retry_interval # The amount to multiply each successive retry's interval amount # by in order to provide backoff @backoff_factor = backoff_factor # A list of HTTP statuses to retry @retry_statuses = retry_statuses # A list of HTTP methods to retry @retry_methods = retry_methods # Current API environment @environment = String(environment) # Sets the base URL requests are made to. Defaults to `https://connect.squareup.com` @custom_url = custom_url # Square Connect API versions @square_version = square_version # The OAuth 2.0 Access Token to use for API requests. @access_token = access_token # Additional headers to add to each API request @additional_headers = additional_headers.clone # The Http Client to use for making requests. @http_client = create_http_client end |
Class Attribute Details
.environments ⇒ Object (readonly)
Returns the value of attribute environments.
16 17 18 |
# File 'lib/square/configuration.rb', line 16 def environments @environments end |
Instance Method Details
#clone_with(timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, environment: nil, custom_url: nil, square_version: nil, access_token: nil, additional_headers: nil) ⇒ Object
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 |
# File 'lib/square/configuration.rb', line 64 def clone_with(timeout: nil, max_retries: nil, retry_interval: nil, backoff_factor: nil, retry_statuses: nil, retry_methods: nil, environment: nil, custom_url: nil, square_version: nil, access_token: nil, additional_headers: nil) 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 environment ||= self.environment custom_url ||= self.custom_url square_version ||= self.square_version access_token ||= self.access_token additional_headers ||= self.additional_headers Configuration.new(timeout: timeout, max_retries: max_retries, retry_interval: retry_interval, backoff_factor: backoff_factor, retry_statuses: retry_statuses, retry_methods: retry_methods, environment: environment, custom_url: custom_url, square_version: square_version, access_token: access_token, additional_headers: additional_headers) end |
#create_http_client ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/square/configuration.rb', line 90 def create_http_client FaradayClient.new(timeout: timeout, max_retries: max_retries, retry_interval: retry_interval, backoff_factor: backoff_factor, retry_statuses: retry_statuses, retry_methods: retry_methods) end |
#get_base_uri(server = 'default') ⇒ String
Generates the appropriate base URI for the environment and the server. required.
115 116 117 118 119 120 121 122 |
# File 'lib/square/configuration.rb', line 115 def get_base_uri(server = 'default') parameters = { 'custom_url' => { 'value' => custom_url, 'encode' => false } } APIHelper.append_url_with_template_parameters( ENVIRONMENTS[environment][server], parameters ) end |