colorado-booth-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +202 -0
- data/bin/console +15 -0
- data/lib/multi_auth_sample/api_helper.rb +10 -0
- data/lib/multi_auth_sample/client.rb +118 -0
- data/lib/multi_auth_sample/configuration.rb +262 -0
- data/lib/multi_auth_sample/controllers/authentication_controller.rb +149 -0
- data/lib/multi_auth_sample/controllers/base_controller.rb +60 -0
- data/lib/multi_auth_sample/controllers/o_auth_authorization_controller.rb +188 -0
- data/lib/multi_auth_sample/exceptions/api_exception.rb +21 -0
- data/lib/multi_auth_sample/exceptions/o_auth_provider_exception.rb +64 -0
- data/lib/multi_auth_sample/http/auth/api_header.rb +59 -0
- data/lib/multi_auth_sample/http/auth/api_key.rb +59 -0
- data/lib/multi_auth_sample/http/auth/basic_auth.rb +62 -0
- data/lib/multi_auth_sample/http/auth/custom_auth.rb +40 -0
- data/lib/multi_auth_sample/http/auth/o_auth_acg.rb +163 -0
- data/lib/multi_auth_sample/http/auth/o_auth_bearer_token.rb +53 -0
- data/lib/multi_auth_sample/http/auth/o_auth_ccg.rb +148 -0
- data/lib/multi_auth_sample/http/auth/o_auth_ropcg.rb +139 -0
- data/lib/multi_auth_sample/http/http_call_back.rb +10 -0
- data/lib/multi_auth_sample/http/http_method_enum.rb +10 -0
- data/lib/multi_auth_sample/http/http_request.rb +10 -0
- data/lib/multi_auth_sample/http/http_response.rb +10 -0
- data/lib/multi_auth_sample/http/proxy_settings.rb +22 -0
- data/lib/multi_auth_sample/models/base_model.rb +122 -0
- data/lib/multi_auth_sample/models/o_auth_provider_error_enum.rb +62 -0
- data/lib/multi_auth_sample/models/o_auth_scope_o_auth_acg_enum.rb +26 -0
- data/lib/multi_auth_sample/models/o_auth_token.rb +106 -0
- data/lib/multi_auth_sample/models/service_status.rb +140 -0
- data/lib/multi_auth_sample/models/suite_code_enum.rb +50 -0
- data/lib/multi_auth_sample/models/user.rb +111 -0
- data/lib/multi_auth_sample/utilities/date_time_helper.rb +11 -0
- data/lib/multi_auth_sample/utilities/file_wrapper.rb +28 -0
- data/lib/multi_auth_sample.rb +55 -0
- data/test/controllers/controller_test_base.rb +60 -0
- data/test/controllers/test_authentication_controller.rb +110 -0
- data/test/http_response_catcher.rb +19 -0
- metadata +150 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 0ecfc30bca2e0a1ac9bc1aec6603adc469e58546d6ced2ed3296651ec0b2a14c
|
|
4
|
+
data.tar.gz: 2da57faacb5be3a5ddfe3e75e183feda6e77e92955a968179dd3f82aa76a85e4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 648855a5a06ab8844edbb1334913c38847bdf917eb85c9b48bae03cae645ef34450fabdbe3ccab6af5c83cb6776eea9332e667bedeb8478f8ddc73d6d3232315
|
|
7
|
+
data.tar.gz: 2d3bc04e89b1917c36387c3392419d269e35f3046ef6619589c5ec0c87b04d9368dd2f718d646c3813b7d87997fc651c4e2d4b6274ae62e25d3fde83280a4156
|
data/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
License:
|
|
2
|
+
========
|
|
3
|
+
The MIT License (MIT)
|
|
4
|
+
http://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2014 - 2026 APIMATIC Limited
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
|
25
|
+
|
|
26
|
+
Trade Mark:
|
|
27
|
+
==========
|
|
28
|
+
APIMATIC is a trade mark for APIMATIC Limited
|
data/README.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
# Getting Started with MultiAuth-Sample
|
|
3
|
+
|
|
4
|
+
## Introduction
|
|
5
|
+
|
|
6
|
+
API for Markdown Notes app.
|
|
7
|
+
|
|
8
|
+
## Install the Package
|
|
9
|
+
|
|
10
|
+
Install the gem from the command line:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
gem install colorado-booth-sdk -v 1.0.0
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or add the gem to your Gemfile and run `bundle`:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem 'colorado-booth-sdk', '1.0.0'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For additional gem details, see the [RubyGems page for the colorado-booth-sdk gem](https://rubygems.org/gems/colorado-booth-sdk/versions/1.0.0).
|
|
23
|
+
|
|
24
|
+
## IRB Console Usage
|
|
25
|
+
|
|
26
|
+
You can explore the SDK interactively using IRB in two ways
|
|
27
|
+
|
|
28
|
+
### 1. Use IRB with Installed Gem
|
|
29
|
+
|
|
30
|
+
Open your system terminal (Command Prompt, Git Bash or macOS Terminal) and type the following command to start the irb console.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
irb
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Now you can load the SDK in the IRB
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
require 'multi_auth_sample'
|
|
40
|
+
include MultiAuthSample
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. Use IRB within SDK
|
|
44
|
+
|
|
45
|
+
Open your system terminal (Command Prompt, Git Bash or macOS Terminal) and navigate to the root folder of SDK.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
cd path/to/multi_auth_sample
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Now you can start the preconfigured irb console by running the following command
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
ruby bin/console
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**_Note:_** This automatically loads the SDK from lib/
|
|
58
|
+
|
|
59
|
+
## Test the SDK
|
|
60
|
+
|
|
61
|
+
To run the tests, navigate to the root directory of the SDK in your terminal and execute the following command:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
rake
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Initialize the API Client
|
|
68
|
+
|
|
69
|
+
**_Note:_** Documentation for the client can be found [here.](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/client.md)
|
|
70
|
+
|
|
71
|
+
The following parameters are configurable for the API Client:
|
|
72
|
+
|
|
73
|
+
| Parameter | Type | Description |
|
|
74
|
+
| --- | --- | --- |
|
|
75
|
+
| access_token | `String` | |
|
|
76
|
+
| port | `String` | *Default*: `'80'` |
|
|
77
|
+
| suites | `SuiteCodeEnum` | *Default*: `SuiteCodeEnum::HEARTS` |
|
|
78
|
+
| environment | [`Environment`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/README.md#environments) | The API environment. <br> **Default: `Environment.TESTING`** |
|
|
79
|
+
| connection | `Faraday::Connection` | The Faraday connection object passed by the SDK user for making requests |
|
|
80
|
+
| adapter | `Faraday::Adapter` | The Faraday adapter object passed by the SDK user for performing http requests |
|
|
81
|
+
| timeout | `Float` | The value to use for connection timeout. <br> **Default: 60** |
|
|
82
|
+
| max_retries | `Integer` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
|
|
83
|
+
| retry_interval | `Float` | Pause in seconds between retries. <br> **Default: 1** |
|
|
84
|
+
| backoff_factor | `Float` | The amount to multiply each successive retry's interval amount by in order to provide backoff. <br> **Default: 2** |
|
|
85
|
+
| retry_statuses | `Array` | A list of HTTP statuses to retry. <br> **Default: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]** |
|
|
86
|
+
| retry_methods | `Array` | A list of HTTP methods to retry. <br> **Default: %i[get put]** |
|
|
87
|
+
| http_callback | `HttpCallBack` | The Http CallBack allows defining callables for pre and post API calls. |
|
|
88
|
+
| proxy_settings | [`ProxySettings`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/proxy-settings.md) | Optional proxy configuration to route HTTP requests through a proxy server. |
|
|
89
|
+
| basic_auth_credentials | [`BasicAuthCredentials`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/basic-authentication.md) | The credential object for Basic Authentication |
|
|
90
|
+
| api_key_credentials | [`ApiKeyCredentials`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/custom-query-parameter.md) | The credential object for Custom Query Parameter |
|
|
91
|
+
| api_header_credentials | [`ApiHeaderCredentials`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/custom-header-signature.md) | The credential object for Custom Header Signature |
|
|
92
|
+
| o_auth_ccg_credentials | [`OAuthCCGCredentials`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-client-credentials-grant.md) | The credential object for OAuth 2 Client Credentials Grant |
|
|
93
|
+
| o_auth_acg_credentials | [`OAuthACGCredentials`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-authorization-code-grant.md) | The credential object for OAuth 2 Authorization Code Grant |
|
|
94
|
+
| o_auth_ropcg_credentials | [`OAuthROPCGCredentials`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-resource-owner-credentials-grant.md) | The credential object for OAuth 2 Resource Owner Credentials Grant |
|
|
95
|
+
| o_auth_bearer_token_credentials | [`OAuthBearerTokenCredentials`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-bearer-token.md) | The credential object for OAuth 2 Bearer token |
|
|
96
|
+
|
|
97
|
+
The API client can be initialized as follows:
|
|
98
|
+
|
|
99
|
+
### Code-Based Client Initialization
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
require 'multi_auth_sample'
|
|
103
|
+
include MultiAuthSample
|
|
104
|
+
|
|
105
|
+
client = Client.new(
|
|
106
|
+
access_token: 'accessToken',
|
|
107
|
+
basic_auth_credentials: BasicAuthCredentials.new(
|
|
108
|
+
username: 'Username',
|
|
109
|
+
password: 'Password'
|
|
110
|
+
),
|
|
111
|
+
api_key_credentials: ApiKeyCredentials.new(
|
|
112
|
+
token: 'token',
|
|
113
|
+
api_key: 'api-key'
|
|
114
|
+
),
|
|
115
|
+
api_header_credentials: ApiHeaderCredentials.new(
|
|
116
|
+
token: 'token',
|
|
117
|
+
api_key: 'api-key'
|
|
118
|
+
),
|
|
119
|
+
o_auth_ccg_credentials: OAuthCCGCredentials.new(
|
|
120
|
+
o_auth_client_id: 'OAuthClientId',
|
|
121
|
+
o_auth_client_secret: 'OAuthClientSecret'
|
|
122
|
+
),
|
|
123
|
+
o_auth_acg_credentials: OAuthACGCredentials.new(
|
|
124
|
+
o_auth_client_id: 'OAuthClientId',
|
|
125
|
+
o_auth_client_secret: 'OAuthClientSecret',
|
|
126
|
+
o_auth_redirect_uri: 'OAuthRedirectUri',
|
|
127
|
+
o_auth_scopes: [
|
|
128
|
+
OAuthScopeOAuthACGEnum::READ_SCOPE
|
|
129
|
+
]
|
|
130
|
+
),
|
|
131
|
+
o_auth_ropcg_credentials: OAuthROPCGCredentials.new(
|
|
132
|
+
o_auth_client_id: 'OAuthClientId',
|
|
133
|
+
o_auth_client_secret: 'OAuthClientSecret',
|
|
134
|
+
o_auth_username: 'OAuthUsername',
|
|
135
|
+
o_auth_password: 'OAuthPassword'
|
|
136
|
+
),
|
|
137
|
+
o_auth_bearer_token_credentials: OAuthBearerTokenCredentials.new(
|
|
138
|
+
access_token: 'AccessToken'
|
|
139
|
+
),
|
|
140
|
+
environment: Environment::TESTING,
|
|
141
|
+
port: '80',
|
|
142
|
+
suites: SuiteCodeEnum::HEARTS
|
|
143
|
+
)
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### Environment-Based Client Initialization
|
|
147
|
+
|
|
148
|
+
```ruby
|
|
149
|
+
require 'multi_auth_sample'
|
|
150
|
+
include MultiAuthSample
|
|
151
|
+
|
|
152
|
+
# Create client from environment
|
|
153
|
+
client = Client.from_env
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
See the [`Environment-Based Client Initialization`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/environment-based-client-initialization.md) section for details.
|
|
157
|
+
|
|
158
|
+
## Environments
|
|
159
|
+
|
|
160
|
+
The SDK can be configured to use a different environment for making API calls. Available environments are:
|
|
161
|
+
|
|
162
|
+
### Fields
|
|
163
|
+
|
|
164
|
+
| Name | Description |
|
|
165
|
+
| --- | --- |
|
|
166
|
+
| PRODUCTION | - |
|
|
167
|
+
| TESTING | **Default** |
|
|
168
|
+
|
|
169
|
+
## Authorization
|
|
170
|
+
|
|
171
|
+
This API uses the following authentication schemes.
|
|
172
|
+
|
|
173
|
+
* [`basicAuth (Basic Authentication)`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/basic-authentication.md)
|
|
174
|
+
* [`apiKey (Custom Query Parameter)`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/custom-query-parameter.md)
|
|
175
|
+
* [`apiHeader (Custom Header Signature)`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/custom-header-signature.md)
|
|
176
|
+
* [`OAuthCCG (OAuth 2 Client Credentials Grant)`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-client-credentials-grant.md)
|
|
177
|
+
* [`OAuthACG (OAuth 2 Authorization Code Grant)`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-authorization-code-grant.md)
|
|
178
|
+
* [`OAuthROPCG (OAuth 2 Resource Owner Credentials Grant)`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-resource-owner-credentials-grant.md)
|
|
179
|
+
* [`OAuthBearerToken (OAuth 2 Bearer token)`](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-bearer-token.md)
|
|
180
|
+
* `CustomAuth (Custom Authentication)`
|
|
181
|
+
|
|
182
|
+
## List of APIs
|
|
183
|
+
|
|
184
|
+
* [Authentication](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/controllers/authentication.md)
|
|
185
|
+
|
|
186
|
+
## SDK Infrastructure
|
|
187
|
+
|
|
188
|
+
### Configuration
|
|
189
|
+
|
|
190
|
+
* [ProxySettings](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/proxy-settings.md)
|
|
191
|
+
* [Environment-Based Client Initialization](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/environment-based-client-initialization.md)
|
|
192
|
+
|
|
193
|
+
### HTTP
|
|
194
|
+
|
|
195
|
+
* [HttpResponse](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/http-response.md)
|
|
196
|
+
* [HttpRequest](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/http-request.md)
|
|
197
|
+
|
|
198
|
+
### Utilities
|
|
199
|
+
|
|
200
|
+
* [ApiHelper](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/api-helper.md)
|
|
201
|
+
* [DateTimeHelper](https://www.github.com/ZahraN444/colorado-booth-ruby-sdk/tree/1.0.0/doc/date-time-helper.md)
|
|
202
|
+
|
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# Load the lib folder into Ruby's load path
|
|
4
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
|
5
|
+
|
|
6
|
+
# Require the gem
|
|
7
|
+
require 'multi_auth_sample'
|
|
8
|
+
|
|
9
|
+
puts 'MultiAuthSample SDK loaded!'
|
|
10
|
+
puts 'You can now create a client with: client = MultiAuthSample::Client.new'
|
|
11
|
+
puts 'Or use from_env: client = MultiAuthSample::Client.from_env'
|
|
12
|
+
|
|
13
|
+
# Start an interactive IRB session
|
|
14
|
+
require 'irb'
|
|
15
|
+
IRB.start
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
# multi_auth_sample
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0
|
|
4
|
+
# ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module MultiAuthSample
|
|
7
|
+
# multi_auth_sample client class.
|
|
8
|
+
class Client
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
attr_reader :config, :auth_managers
|
|
11
|
+
|
|
12
|
+
def user_agent_detail
|
|
13
|
+
config.user_agent_detail
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Returns the configured authentication OAuthCCG instance.
|
|
17
|
+
def o_auth_ccg
|
|
18
|
+
@auth_managers['OAuthCCG']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Returns the configured authentication OAuthACG instance.
|
|
22
|
+
def o_auth_acg
|
|
23
|
+
@auth_managers['OAuthACG']
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns the configured authentication OAuthROPCG instance.
|
|
27
|
+
def o_auth_ropcg
|
|
28
|
+
@auth_managers['OAuthROPCG']
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Access to authentication controller.
|
|
32
|
+
# @return [AuthenticationController] Returns the controller instance.
|
|
33
|
+
def authentication
|
|
34
|
+
@authentication ||= AuthenticationController.new @global_configuration
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Access to o_auth_authorization controller.
|
|
38
|
+
# @return [OAuthAuthorizationController] Returns the controller instance.
|
|
39
|
+
def o_auth_authorization
|
|
40
|
+
@o_auth_authorization ||= OAuthAuthorizationController.new @global_configuration
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def initialize(
|
|
44
|
+
connection: nil, adapter: :net_http_persistent, timeout: 60,
|
|
45
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
|
46
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
|
47
|
+
retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
|
|
48
|
+
environment: Environment::TESTING, port: '80',
|
|
49
|
+
suites: SuiteCodeEnum::HEARTS, basic_auth_credentials: nil,
|
|
50
|
+
api_key_credentials: nil, api_header_credentials: nil,
|
|
51
|
+
o_auth_ccg_credentials: nil, o_auth_acg_credentials: nil,
|
|
52
|
+
o_auth_ropcg_credentials: nil, o_auth_bearer_token_credentials: nil,
|
|
53
|
+
custom_auth_credentials: nil, access_token: '', config: nil
|
|
54
|
+
)
|
|
55
|
+
@config = if config.nil?
|
|
56
|
+
Configuration.new(
|
|
57
|
+
connection: connection, adapter: adapter, timeout: timeout,
|
|
58
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
|
59
|
+
backoff_factor: backoff_factor,
|
|
60
|
+
retry_statuses: retry_statuses,
|
|
61
|
+
retry_methods: retry_methods, http_callback: http_callback,
|
|
62
|
+
proxy_settings: proxy_settings, environment: environment,
|
|
63
|
+
port: port, suites: suites,
|
|
64
|
+
basic_auth_credentials: basic_auth_credentials,
|
|
65
|
+
api_key_credentials: api_key_credentials,
|
|
66
|
+
api_header_credentials: api_header_credentials,
|
|
67
|
+
o_auth_ccg_credentials: o_auth_ccg_credentials,
|
|
68
|
+
o_auth_acg_credentials: o_auth_acg_credentials,
|
|
69
|
+
o_auth_ropcg_credentials: o_auth_ropcg_credentials,
|
|
70
|
+
o_auth_bearer_token_credentials: o_auth_bearer_token_credentials,
|
|
71
|
+
custom_auth_credentials: custom_auth_credentials,
|
|
72
|
+
access_token: access_token
|
|
73
|
+
)
|
|
74
|
+
else
|
|
75
|
+
config
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
@global_configuration = GlobalConfiguration.new(client_configuration: @config)
|
|
79
|
+
.base_uri_executor(@config.method(:get_base_uri))
|
|
80
|
+
.global_errors(BaseController::GLOBAL_ERRORS)
|
|
81
|
+
.user_agent(BaseController.user_agent)
|
|
82
|
+
.global_header('accessToken', @config.access_token)
|
|
83
|
+
|
|
84
|
+
initialize_auth_managers(@global_configuration)
|
|
85
|
+
@global_configuration = @global_configuration.auth_managers(@auth_managers)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# Initializes the auth managers hash used for authenticating API calls.
|
|
89
|
+
# @param [GlobalConfiguration] global_config The global configuration of the SDK)
|
|
90
|
+
def initialize_auth_managers(global_config)
|
|
91
|
+
@auth_managers = {}
|
|
92
|
+
http_client_config = global_config.client_configuration
|
|
93
|
+
%w[basicAuth apiKey apiHeader OAuthCCG OAuthACG OAuthROPCG OAuthBearerToken CustomAuth].each do |auth|
|
|
94
|
+
@auth_managers[auth] = nil
|
|
95
|
+
end
|
|
96
|
+
@auth_managers['basicAuth'] = BasicAuth.new(http_client_config.basic_auth_credentials)
|
|
97
|
+
@auth_managers['apiKey'] = ApiKey.new(http_client_config.api_key_credentials)
|
|
98
|
+
@auth_managers['apiHeader'] = ApiHeader.new(http_client_config.api_header_credentials)
|
|
99
|
+
@auth_managers['OAuthCCG'] = OAuthCCG.new(http_client_config.o_auth_ccg_credentials,
|
|
100
|
+
global_config)
|
|
101
|
+
@auth_managers['OAuthACG'] = OAuthACG.new(http_client_config.o_auth_acg_credentials,
|
|
102
|
+
global_config)
|
|
103
|
+
@auth_managers['OAuthROPCG'] = OAuthROPCG.new(http_client_config.o_auth_ropcg_credentials,
|
|
104
|
+
global_config)
|
|
105
|
+
@auth_managers['OAuthBearerToken'] = OAuthBearerToken.new(
|
|
106
|
+
http_client_config.o_auth_bearer_token_credentials
|
|
107
|
+
)
|
|
108
|
+
@auth_managers['CustomAuth'] = CustomAuth.new(http_client_config)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
# Creates a client directly from environment variables.
|
|
112
|
+
def self.from_env(**overrides)
|
|
113
|
+
default_config = Configuration.build_default_config_from_env
|
|
114
|
+
new_config = default_config.clone_with(**overrides)
|
|
115
|
+
new(config: new_config)
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# multi_auth_sample
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC v3.0
|
|
4
|
+
# ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module MultiAuthSample
|
|
7
|
+
# An enum for SDK environments.
|
|
8
|
+
class Environment
|
|
9
|
+
ENVIRONMENT = [
|
|
10
|
+
PRODUCTION = 'production'.freeze,
|
|
11
|
+
TESTING = 'testing'.freeze
|
|
12
|
+
].freeze
|
|
13
|
+
|
|
14
|
+
# Converts a string or symbol into a valid Environment constant.
|
|
15
|
+
def self.from_value(value, default_value = PRODUCTION)
|
|
16
|
+
return default_value if value.nil?
|
|
17
|
+
|
|
18
|
+
str = value.to_s.strip.downcase
|
|
19
|
+
case str
|
|
20
|
+
when 'production' then PRODUCTION
|
|
21
|
+
when 'testing' then TESTING
|
|
22
|
+
|
|
23
|
+
else
|
|
24
|
+
warn "[Environment] Unknown environment '#{value}', falling back to #{default_value} "
|
|
25
|
+
default_value
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# An enum for API servers.
|
|
31
|
+
class Server
|
|
32
|
+
SERVER = [
|
|
33
|
+
DEFAULT = 'default'.freeze,
|
|
34
|
+
AUTH = 'auth'.freeze
|
|
35
|
+
].freeze
|
|
36
|
+
|
|
37
|
+
# Converts a string or symbol into a valid Server constant.
|
|
38
|
+
def self.from_value(value, default_value = DEFAULT)
|
|
39
|
+
return default_value if value.nil?
|
|
40
|
+
|
|
41
|
+
str = value.to_s.strip.downcase
|
|
42
|
+
case str
|
|
43
|
+
when 'default' then DEFAULT
|
|
44
|
+
when 'auth' then AUTH
|
|
45
|
+
|
|
46
|
+
else
|
|
47
|
+
warn "[Server] Unknown server '#{value}', falling back to #{default_value} "
|
|
48
|
+
default_value
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# All configuration including auth info and base URI for the API access
|
|
54
|
+
# are configured in this class.
|
|
55
|
+
class Configuration < CoreLibrary::HttpClientConfiguration
|
|
56
|
+
# The attribute readers for properties.
|
|
57
|
+
attr_reader :environment, :port, :suites, :basic_auth_credentials,
|
|
58
|
+
:api_key_credentials, :api_header_credentials,
|
|
59
|
+
:o_auth_ccg_credentials, :o_auth_acg_credentials,
|
|
60
|
+
:o_auth_ropcg_credentials, :o_auth_bearer_token_credentials,
|
|
61
|
+
:custom_auth_credentials, :access_token
|
|
62
|
+
|
|
63
|
+
class << self
|
|
64
|
+
attr_reader :environments
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def initialize(
|
|
68
|
+
connection: nil, adapter: :net_http_persistent, timeout: 60,
|
|
69
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
|
70
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
|
71
|
+
retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
|
|
72
|
+
environment: Environment::TESTING, port: '80',
|
|
73
|
+
suites: SuiteCodeEnum::HEARTS, basic_auth_credentials: nil,
|
|
74
|
+
api_key_credentials: nil, api_header_credentials: nil,
|
|
75
|
+
o_auth_ccg_credentials: nil, o_auth_acg_credentials: nil,
|
|
76
|
+
o_auth_ropcg_credentials: nil, o_auth_bearer_token_credentials: nil,
|
|
77
|
+
custom_auth_credentials: nil, access_token: ''
|
|
78
|
+
)
|
|
79
|
+
super connection: connection, adapter: adapter, timeout: timeout,
|
|
80
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
|
81
|
+
backoff_factor: backoff_factor, retry_statuses: retry_statuses,
|
|
82
|
+
retry_methods: retry_methods, http_callback: http_callback,
|
|
83
|
+
proxy_settings: proxy_settings
|
|
84
|
+
|
|
85
|
+
# Current API environment
|
|
86
|
+
@environment = String(environment)
|
|
87
|
+
|
|
88
|
+
# port value
|
|
89
|
+
@port = port
|
|
90
|
+
|
|
91
|
+
# suites value
|
|
92
|
+
@suites = suites
|
|
93
|
+
|
|
94
|
+
# The object holding Basic Authentication credentials
|
|
95
|
+
@basic_auth_credentials = basic_auth_credentials
|
|
96
|
+
|
|
97
|
+
# The object holding Custom Query Parameter credentials
|
|
98
|
+
@api_key_credentials = api_key_credentials
|
|
99
|
+
|
|
100
|
+
# The object holding Custom Header Signature credentials
|
|
101
|
+
@api_header_credentials = api_header_credentials
|
|
102
|
+
|
|
103
|
+
# The object holding OAuth 2 Client Credentials Grant credentials
|
|
104
|
+
@o_auth_ccg_credentials = o_auth_ccg_credentials
|
|
105
|
+
|
|
106
|
+
# The object holding OAuth 2 Authorization Code Grant credentials
|
|
107
|
+
@o_auth_acg_credentials = o_auth_acg_credentials
|
|
108
|
+
|
|
109
|
+
# The object holding OAuth 2 Resource Owner Credentials Grant credentials
|
|
110
|
+
@o_auth_ropcg_credentials = o_auth_ropcg_credentials
|
|
111
|
+
|
|
112
|
+
# The object holding OAuth 2 Bearer token credentials
|
|
113
|
+
@o_auth_bearer_token_credentials = o_auth_bearer_token_credentials
|
|
114
|
+
|
|
115
|
+
# The object holding Custom Authentication credentials
|
|
116
|
+
@custom_auth_credentials = custom_auth_credentials
|
|
117
|
+
|
|
118
|
+
# TODO: Replace
|
|
119
|
+
@access_token = access_token
|
|
120
|
+
|
|
121
|
+
# The Http Client to use for making requests.
|
|
122
|
+
set_http_client CoreLibrary::FaradayClient.new(self)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def clone_with(connection: nil, adapter: nil, timeout: nil,
|
|
126
|
+
max_retries: nil, retry_interval: nil, backoff_factor: nil,
|
|
127
|
+
retry_statuses: nil, retry_methods: nil, http_callback: nil,
|
|
128
|
+
proxy_settings: nil, environment: nil, port: nil,
|
|
129
|
+
suites: nil, basic_auth_credentials: nil,
|
|
130
|
+
api_key_credentials: nil, api_header_credentials: nil,
|
|
131
|
+
o_auth_ccg_credentials: nil, o_auth_acg_credentials: nil,
|
|
132
|
+
o_auth_ropcg_credentials: nil,
|
|
133
|
+
o_auth_bearer_token_credentials: nil,
|
|
134
|
+
custom_auth_credentials: nil, access_token: nil)
|
|
135
|
+
connection ||= self.connection
|
|
136
|
+
adapter ||= self.adapter
|
|
137
|
+
timeout ||= self.timeout
|
|
138
|
+
max_retries ||= self.max_retries
|
|
139
|
+
retry_interval ||= self.retry_interval
|
|
140
|
+
backoff_factor ||= self.backoff_factor
|
|
141
|
+
retry_statuses ||= self.retry_statuses
|
|
142
|
+
retry_methods ||= self.retry_methods
|
|
143
|
+
http_callback ||= self.http_callback
|
|
144
|
+
proxy_settings ||= self.proxy_settings
|
|
145
|
+
environment ||= self.environment
|
|
146
|
+
port ||= self.port
|
|
147
|
+
suites ||= self.suites
|
|
148
|
+
basic_auth_credentials ||= self.basic_auth_credentials
|
|
149
|
+
api_key_credentials ||= self.api_key_credentials
|
|
150
|
+
api_header_credentials ||= self.api_header_credentials
|
|
151
|
+
o_auth_ccg_credentials ||= self.o_auth_ccg_credentials
|
|
152
|
+
o_auth_acg_credentials ||= self.o_auth_acg_credentials
|
|
153
|
+
o_auth_ropcg_credentials ||= self.o_auth_ropcg_credentials
|
|
154
|
+
o_auth_bearer_token_credentials ||= self.o_auth_bearer_token_credentials
|
|
155
|
+
custom_auth_credentials ||= self.custom_auth_credentials
|
|
156
|
+
access_token ||= self.access_token
|
|
157
|
+
|
|
158
|
+
Configuration.new(
|
|
159
|
+
connection: connection, adapter: adapter, timeout: timeout,
|
|
160
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
|
161
|
+
backoff_factor: backoff_factor, retry_statuses: retry_statuses,
|
|
162
|
+
retry_methods: retry_methods, http_callback: http_callback,
|
|
163
|
+
proxy_settings: proxy_settings, environment: environment, port: port,
|
|
164
|
+
suites: suites, basic_auth_credentials: basic_auth_credentials,
|
|
165
|
+
api_key_credentials: api_key_credentials,
|
|
166
|
+
api_header_credentials: api_header_credentials,
|
|
167
|
+
o_auth_ccg_credentials: o_auth_ccg_credentials,
|
|
168
|
+
o_auth_acg_credentials: o_auth_acg_credentials,
|
|
169
|
+
o_auth_ropcg_credentials: o_auth_ropcg_credentials,
|
|
170
|
+
o_auth_bearer_token_credentials: o_auth_bearer_token_credentials,
|
|
171
|
+
custom_auth_credentials: custom_auth_credentials,
|
|
172
|
+
access_token: access_token
|
|
173
|
+
)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
# All the environments the SDK can run in.
|
|
178
|
+
ENVIRONMENTS = {
|
|
179
|
+
Environment::PRODUCTION => {
|
|
180
|
+
Server::DEFAULT => 'http://apimatic.hopto.org:{suites}',
|
|
181
|
+
Server::AUTH => 'http://apimaticauth.hopto.org:3000'
|
|
182
|
+
},
|
|
183
|
+
Environment::TESTING => {
|
|
184
|
+
Server::DEFAULT => 'http://localhost:3000',
|
|
185
|
+
Server::AUTH => 'http://localhost:3000/oauth2/auth-server'
|
|
186
|
+
}
|
|
187
|
+
}.freeze
|
|
188
|
+
|
|
189
|
+
# Generates the appropriate base URI for the environment and the server.
|
|
190
|
+
# @param [Configuration::Server] server The server enum for which the base URI is
|
|
191
|
+
# required.
|
|
192
|
+
# @return [String] The base URI.
|
|
193
|
+
def get_base_uri(server = Server::DEFAULT)
|
|
194
|
+
parameters = {
|
|
195
|
+
'port' => { 'value' => port, 'encode' => false },
|
|
196
|
+
'suites' => { 'value' => suites, 'encode' => false }
|
|
197
|
+
}
|
|
198
|
+
APIHelper.append_url_with_template_parameters(
|
|
199
|
+
ENVIRONMENTS[environment][server], parameters
|
|
200
|
+
)
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# Builds a Configuration instance using environment variables.
|
|
204
|
+
def self.build_default_config_from_env
|
|
205
|
+
# === Core environment ===
|
|
206
|
+
environment = Environment.from_value(ENV.fetch('ENVIRONMENT', 'testing'))
|
|
207
|
+
port = ENV.fetch('PORT', '80')
|
|
208
|
+
suites = SuiteCodeEnum.from_value(ENV.fetch('SUITES', 'hearts'))
|
|
209
|
+
access_token = ENV.fetch('ACCESS_TOKEN', 'nil')
|
|
210
|
+
timeout = (ENV['TIMEOUT'] || 60).to_f
|
|
211
|
+
max_retries = (ENV['MAX_RETRIES'] || 0).to_i
|
|
212
|
+
retry_interval = (ENV['RETRY_INTERVAL'] || 1).to_f
|
|
213
|
+
backoff_factor = (ENV['BACKOFF_FACTOR'] || 2).to_f
|
|
214
|
+
retry_statuses = ENV.fetch('RETRY_STATUSES',
|
|
215
|
+
'[408, 413, 429, 500, 502, 503, 504, 521, 522, 524]').gsub(/[\[\]]/, '')
|
|
216
|
+
.split(',')
|
|
217
|
+
.map(&:strip)
|
|
218
|
+
.map do |item|
|
|
219
|
+
item.match?(/\A\d+\z/) ? item.to_i : item.downcase
|
|
220
|
+
end
|
|
221
|
+
retry_methods = ENV.fetch('RETRY_METHODS', '%i[get put]').gsub(/[\[\]]/, '')
|
|
222
|
+
.split(',')
|
|
223
|
+
.map(&:strip)
|
|
224
|
+
.map do |item|
|
|
225
|
+
item.match?(/\A\d+\z/) ? item.to_i : item.downcase
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
# === Authentication credentials ===
|
|
229
|
+
basic_auth_credentials = BasicAuthCredentials.from_env
|
|
230
|
+
api_key_credentials = ApiKeyCredentials.from_env
|
|
231
|
+
api_header_credentials = ApiHeaderCredentials.from_env
|
|
232
|
+
o_auth_ccg_credentials = OAuthCCGCredentials.from_env
|
|
233
|
+
o_auth_acg_credentials = OAuthACGCredentials.from_env
|
|
234
|
+
o_auth_ropcg_credentials = OAuthROPCGCredentials.from_env
|
|
235
|
+
o_auth_bearer_token_credentials = OAuthBearerTokenCredentials.from_env
|
|
236
|
+
|
|
237
|
+
# === Proxy settings ===
|
|
238
|
+
proxy_settings = ProxySettings.from_env
|
|
239
|
+
|
|
240
|
+
Configuration.new(
|
|
241
|
+
environment: environment,
|
|
242
|
+
port: port,
|
|
243
|
+
suites: suites,
|
|
244
|
+
access_token: access_token,
|
|
245
|
+
timeout: timeout,
|
|
246
|
+
max_retries: max_retries,
|
|
247
|
+
retry_interval: retry_interval,
|
|
248
|
+
backoff_factor: backoff_factor,
|
|
249
|
+
retry_statuses: retry_statuses,
|
|
250
|
+
retry_methods: retry_methods,
|
|
251
|
+
basic_auth_credentials: basic_auth_credentials,
|
|
252
|
+
api_key_credentials: api_key_credentials,
|
|
253
|
+
api_header_credentials: api_header_credentials,
|
|
254
|
+
o_auth_ccg_credentials: o_auth_ccg_credentials,
|
|
255
|
+
o_auth_acg_credentials: o_auth_acg_credentials,
|
|
256
|
+
o_auth_ropcg_credentials: o_auth_ropcg_credentials,
|
|
257
|
+
o_auth_bearer_token_credentials: o_auth_bearer_token_credentials,
|
|
258
|
+
proxy_settings: proxy_settings
|
|
259
|
+
)
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
end
|