calc-matic 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 +137 -0
- data/bin/console +15 -0
- data/lib/apimatic_calculator/api_helper.rb +10 -0
- data/lib/apimatic_calculator/apis/base_api.rb +67 -0
- data/lib/apimatic_calculator/apis/simple_calculator_api.rb +37 -0
- data/lib/apimatic_calculator/client.rb +60 -0
- data/lib/apimatic_calculator/configuration.rb +153 -0
- data/lib/apimatic_calculator/exceptions/api_exception.rb +21 -0
- data/lib/apimatic_calculator/http/api_response.rb +19 -0
- data/lib/apimatic_calculator/http/http_call_back.rb +10 -0
- data/lib/apimatic_calculator/http/http_method_enum.rb +10 -0
- data/lib/apimatic_calculator/http/http_request.rb +10 -0
- data/lib/apimatic_calculator/http/http_response.rb +10 -0
- data/lib/apimatic_calculator/http/proxy_settings.rb +22 -0
- data/lib/apimatic_calculator/logging/configuration/api_logging_configuration.rb +186 -0
- data/lib/apimatic_calculator/logging/sdk_logger.rb +17 -0
- data/lib/apimatic_calculator/models/base_model.rb +110 -0
- data/lib/apimatic_calculator/models/operation_type.rb +44 -0
- data/lib/apimatic_calculator/utilities/date_time_helper.rb +11 -0
- data/lib/apimatic_calculator/utilities/file_wrapper.rb +28 -0
- data/lib/apimatic_calculator.rb +45 -0
- metadata +106 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: a598fa2d4b6ccfe2a092f71047ce9b834a1ce3bf8b690d66b5491da6b6651099
|
|
4
|
+
data.tar.gz: 983976f064f4ed682d3aa241c797f4140fcfee3dbaaf4f5b92794d8d542695c5
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 70220d35f9b063ca677630a3408a3941fd45fb83f245a0cc221a5fd0423f1e8374ce3e8aa6cd5962a9f7d58740a72631123fbadb760c67ff2d86f35e690f36b8
|
|
7
|
+
data.tar.gz: 3ca2f109a0201c22cb4c11d05b7028f3a21ed6e141843cdabe1f4fc944496c052dc9beac1b5a0411a5a687dd6b3bbebd7fa5464dd3ba67e627c6cf7738948c42
|
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,137 @@
|
|
|
1
|
+
|
|
2
|
+
# Getting Started with APIMATIC Calculator
|
|
3
|
+
|
|
4
|
+
## Introduction
|
|
5
|
+
|
|
6
|
+
Simple calculator API hosted on APIMATIC
|
|
7
|
+
|
|
8
|
+
## Install the Package
|
|
9
|
+
|
|
10
|
+
Install the gem from the command line:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
gem install calc-matic -v 1.0.0
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or add the gem to your Gemfile and run `bundle`:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem 'calc-matic', '1.0.0'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For additional gem details, see the [RubyGems page for the calc-matic gem](https://rubygems.org/gems/calc-matic/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 'apimatic_calculator'
|
|
40
|
+
include ApimaticCalculator
|
|
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/apimatic_calculator
|
|
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
|
+
## Initialize the API Client
|
|
60
|
+
|
|
61
|
+
**_Note:_** Documentation for the client can be found [here.](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/client.md)
|
|
62
|
+
|
|
63
|
+
The following parameters are configurable for the API Client:
|
|
64
|
+
|
|
65
|
+
| Parameter | Type | Description |
|
|
66
|
+
| --- | --- | --- |
|
|
67
|
+
| connection | `Faraday::Connection` | The Faraday connection object passed by the SDK user for making requests |
|
|
68
|
+
| adapter | `Faraday::Adapter` | The Faraday adapter object passed by the SDK user for performing http requests |
|
|
69
|
+
| timeout | `Float` | The value to use for connection timeout. <br> **Default: 30** |
|
|
70
|
+
| max_retries | `Integer` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
|
|
71
|
+
| retry_interval | `Float` | Pause in seconds between retries. <br> **Default: 1** |
|
|
72
|
+
| backoff_factor | `Float` | The amount to multiply each successive retry's interval amount by in order to provide backoff. <br> **Default: 2** |
|
|
73
|
+
| retry_statuses | `Array` | A list of HTTP statuses to retry. <br> **Default: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]** |
|
|
74
|
+
| retry_methods | `Array` | A list of HTTP methods to retry. <br> **Default: %i[get put]** |
|
|
75
|
+
| http_callback | `HttpCallBack` | The Http CallBack allows defining callables for pre and post API calls. |
|
|
76
|
+
| proxy_settings | [`ProxySettings`](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/proxy-settings.md) | Optional proxy configuration to route HTTP requests through a proxy server. |
|
|
77
|
+
| logging_configuration | [`LoggingConfiguration`](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/logging-configuration.md) | The SDK logging configuration for API calls |
|
|
78
|
+
|
|
79
|
+
The API client can be initialized as follows:
|
|
80
|
+
|
|
81
|
+
### Code-Based Client Initialization
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
require 'apimatic_calculator'
|
|
85
|
+
include ApimaticCalculator
|
|
86
|
+
|
|
87
|
+
client = Client.new(
|
|
88
|
+
logging_configuration: LoggingConfiguration.new(
|
|
89
|
+
log_level: Logger::INFO,
|
|
90
|
+
request_logging_config: RequestLoggingConfiguration.new(
|
|
91
|
+
log_body: true
|
|
92
|
+
),
|
|
93
|
+
response_logging_config: ResponseLoggingConfiguration.new(
|
|
94
|
+
log_headers: true
|
|
95
|
+
)
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Environment-Based Client Initialization
|
|
101
|
+
|
|
102
|
+
```ruby
|
|
103
|
+
require 'apimatic_calculator'
|
|
104
|
+
include ApimaticCalculator
|
|
105
|
+
|
|
106
|
+
# Create client from environment
|
|
107
|
+
client = Client.from_env
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
See the [`Environment-Based Client Initialization`](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/environment-based-client-initialization.md) section for details.
|
|
111
|
+
|
|
112
|
+
## List of APIs
|
|
113
|
+
|
|
114
|
+
* [Simple Calculator](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/controllers/simple-calculator.md)
|
|
115
|
+
|
|
116
|
+
## SDK Infrastructure
|
|
117
|
+
|
|
118
|
+
### Configuration
|
|
119
|
+
|
|
120
|
+
* [ProxySettings](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/proxy-settings.md)
|
|
121
|
+
* [Environment-Based Client Initialization](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/environment-based-client-initialization.md)
|
|
122
|
+
* [AbstractLogger](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/abstract-logger.md)
|
|
123
|
+
* [LoggingConfiguration](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/logging-configuration.md)
|
|
124
|
+
* [RequestLoggingConfiguration](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/request-logging-configuration.md)
|
|
125
|
+
* [ResponseLoggingConfiguration](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/response-logging-configuration.md)
|
|
126
|
+
|
|
127
|
+
### HTTP
|
|
128
|
+
|
|
129
|
+
* [HttpResponse](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/http-response.md)
|
|
130
|
+
* [HttpRequest](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/http-request.md)
|
|
131
|
+
|
|
132
|
+
### Utilities
|
|
133
|
+
|
|
134
|
+
* [ApiResponse](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/api-response.md)
|
|
135
|
+
* [ApiHelper](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/api-helper.md)
|
|
136
|
+
* [DateTimeHelper](https://www.github.com/WasifMatic/ruby-sdk/tree/1.0.0/doc/date-time-helper.md)
|
|
137
|
+
|
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 'apimatic_calculator'
|
|
8
|
+
|
|
9
|
+
puts 'ApimaticCalculator SDK loaded!'
|
|
10
|
+
puts 'You can now create a client with: client = ApimaticCalculator::Client.new'
|
|
11
|
+
puts 'Or use from_env: client = ApimaticCalculator::Client.from_env'
|
|
12
|
+
|
|
13
|
+
# Start an interactive IRB session
|
|
14
|
+
require 'irb'
|
|
15
|
+
IRB.start
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# BaseApi.
|
|
8
|
+
class BaseApi
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
attr_accessor :config, :http_call_back
|
|
11
|
+
|
|
12
|
+
def self.user_agent
|
|
13
|
+
'Ruby-SDK/1.0.0 [OS: {os-info}, Engine: {engine}/{engine-version}]'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.user_agent_parameters
|
|
17
|
+
{
|
|
18
|
+
'{engine}' => { 'value' => RUBY_ENGINE, 'encode' => false },
|
|
19
|
+
'{engine-version}' => { 'value' => RUBY_ENGINE_VERSION, 'encode' => false },
|
|
20
|
+
'{os-info}' => { 'value' => RUBY_PLATFORM, 'encode' => false }
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
GLOBAL_ERRORS = {
|
|
25
|
+
'default' => ErrorCase.new
|
|
26
|
+
.error_message('HTTP response not OK.')
|
|
27
|
+
.exception_type(APIException)
|
|
28
|
+
}.freeze
|
|
29
|
+
|
|
30
|
+
# Initialization constructor.
|
|
31
|
+
# @param [GlobalConfiguration] global_configuration The instance of GlobalConfiguration.
|
|
32
|
+
def initialize(global_configuration)
|
|
33
|
+
@global_configuration = global_configuration
|
|
34
|
+
@config = @global_configuration.client_configuration
|
|
35
|
+
@http_call_back = @config.http_callback
|
|
36
|
+
@api_call = ApiCall.new(@global_configuration)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Creates a new instance of the request builder.
|
|
40
|
+
# @param [String] http_method The HTTP method to use in the request.
|
|
41
|
+
# @param [String] path The endpoint path to use in the request.
|
|
42
|
+
# @param [String] server The server to extract the base uri for the request.
|
|
43
|
+
# @return [RequestBuilder] The instance of RequestBuilder.
|
|
44
|
+
def new_request_builder(http_method, path, server)
|
|
45
|
+
RequestBuilder.new
|
|
46
|
+
.http_method(http_method)
|
|
47
|
+
.path(path)
|
|
48
|
+
.server(server)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Creates a new instance of the response handler.
|
|
52
|
+
# @return [ResponseHandler] The instance of ResponseHandler.
|
|
53
|
+
def new_response_handler
|
|
54
|
+
ResponseHandler.new
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Creates a new instance of the parameter.
|
|
58
|
+
# @param [String|optional] key The key of the parameter.
|
|
59
|
+
# @param [Object] value The value of the parameter.
|
|
60
|
+
# @return [Parameter] The instance of Parameter.
|
|
61
|
+
def new_parameter(value, key: nil)
|
|
62
|
+
Parameter.new
|
|
63
|
+
.key(key)
|
|
64
|
+
.value(value)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# SimpleCalculatorApi
|
|
8
|
+
class SimpleCalculatorApi < BaseApi
|
|
9
|
+
# Calculates the expression using the specified operation.
|
|
10
|
+
# @param [OperationType] operation Required parameter: The operator to apply
|
|
11
|
+
# on the variables
|
|
12
|
+
# @param [Float] x Required parameter: The LHS value
|
|
13
|
+
# @param [Float] y Required parameter: The RHS value
|
|
14
|
+
# @return [ApiResponse] Complete http response with raw body and status code.
|
|
15
|
+
def calculate(operation,
|
|
16
|
+
x,
|
|
17
|
+
y)
|
|
18
|
+
@api_call
|
|
19
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
|
20
|
+
'/{operation}',
|
|
21
|
+
Server::DEFAULT)
|
|
22
|
+
.template_param(new_parameter(operation, key: 'operation')
|
|
23
|
+
.is_required(true)
|
|
24
|
+
.should_encode(true))
|
|
25
|
+
.query_param(new_parameter(x, key: 'x')
|
|
26
|
+
.is_required(true))
|
|
27
|
+
.query_param(new_parameter(y, key: 'y')
|
|
28
|
+
.is_required(true)))
|
|
29
|
+
.response(new_response_handler
|
|
30
|
+
.deserializer(APIHelper.method(:deserialize_primitive_types))
|
|
31
|
+
.deserialize_into(proc do |response| response&.to_f end)
|
|
32
|
+
.is_api_response(true)
|
|
33
|
+
.is_primitive_response(true))
|
|
34
|
+
.execute
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# apimatic_calculator client class.
|
|
8
|
+
class Client
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
attr_reader :config
|
|
11
|
+
|
|
12
|
+
def user_agent_detail
|
|
13
|
+
config.user_agent_detail
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Access to simple_calculator controller.
|
|
17
|
+
# @return [SimpleCalculatorApi] Returns the controller instance.
|
|
18
|
+
def simple_calculator
|
|
19
|
+
@simple_calculator ||= SimpleCalculatorApi.new @global_configuration
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def initialize(
|
|
23
|
+
connection: nil, adapter: :net_http_persistent, timeout: 30,
|
|
24
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
|
25
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
|
26
|
+
retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
|
|
27
|
+
logging_configuration: nil, environment: Environment::PRODUCTION,
|
|
28
|
+
config: nil
|
|
29
|
+
)
|
|
30
|
+
@config = if config.nil?
|
|
31
|
+
Configuration.new(
|
|
32
|
+
connection: connection, adapter: adapter, timeout: timeout,
|
|
33
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
|
34
|
+
backoff_factor: backoff_factor,
|
|
35
|
+
retry_statuses: retry_statuses,
|
|
36
|
+
retry_methods: retry_methods, http_callback: http_callback,
|
|
37
|
+
proxy_settings: proxy_settings,
|
|
38
|
+
logging_configuration: logging_configuration,
|
|
39
|
+
environment: environment
|
|
40
|
+
)
|
|
41
|
+
else
|
|
42
|
+
config
|
|
43
|
+
end
|
|
44
|
+
user_agent_params = BaseApi.user_agent_parameters
|
|
45
|
+
|
|
46
|
+
@global_configuration = GlobalConfiguration.new(client_configuration: @config)
|
|
47
|
+
.base_uri_executor(@config.method(:get_base_uri))
|
|
48
|
+
.global_errors(BaseApi::GLOBAL_ERRORS)
|
|
49
|
+
.user_agent(BaseApi.user_agent,
|
|
50
|
+
agent_parameters: user_agent_params)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Creates a client directly from environment variables.
|
|
54
|
+
def self.from_env(**overrides)
|
|
55
|
+
default_config = Configuration.build_default_config_from_env
|
|
56
|
+
new_config = default_config.clone_with(**overrides)
|
|
57
|
+
new(config: new_config)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# An enum for SDK environments.
|
|
8
|
+
class Environment
|
|
9
|
+
# PRODUCTION: This environment connect to the LIVE calculator API
|
|
10
|
+
ENVIRONMENT = [
|
|
11
|
+
PRODUCTION = 'production'.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
|
+
default_value
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# An enum for API servers.
|
|
23
|
+
class Server
|
|
24
|
+
SERVER = [
|
|
25
|
+
DEFAULT = 'default'.freeze
|
|
26
|
+
].freeze
|
|
27
|
+
|
|
28
|
+
# Converts a string or symbol into a valid Server constant.
|
|
29
|
+
def self.from_value(value, default_value = DEFAULT)
|
|
30
|
+
return default_value if value.nil?
|
|
31
|
+
|
|
32
|
+
default_value
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# All configuration including auth info and base URI for the API access
|
|
37
|
+
# are configured in this class.
|
|
38
|
+
class Configuration < CoreLibrary::HttpClientConfiguration
|
|
39
|
+
# The attribute readers for properties.
|
|
40
|
+
attr_reader :environment
|
|
41
|
+
|
|
42
|
+
class << self
|
|
43
|
+
attr_reader :environments
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def initialize(
|
|
47
|
+
connection: nil, adapter: :net_http_persistent, timeout: 30,
|
|
48
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
|
49
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
|
50
|
+
retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
|
|
51
|
+
logging_configuration: nil, environment: Environment::PRODUCTION
|
|
52
|
+
)
|
|
53
|
+
super connection: connection, adapter: adapter, timeout: timeout,
|
|
54
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
|
55
|
+
backoff_factor: backoff_factor, retry_statuses: retry_statuses,
|
|
56
|
+
retry_methods: retry_methods, http_callback: http_callback,
|
|
57
|
+
proxy_settings: proxy_settings,
|
|
58
|
+
logging_configuration: logging_configuration
|
|
59
|
+
|
|
60
|
+
# Current API environment
|
|
61
|
+
@environment = String(environment)
|
|
62
|
+
|
|
63
|
+
# The Http Client to use for making requests.
|
|
64
|
+
set_http_client CoreLibrary::FaradayClient.new(self)
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def clone_with(connection: nil, adapter: nil, timeout: nil,
|
|
68
|
+
max_retries: nil, retry_interval: nil, backoff_factor: nil,
|
|
69
|
+
retry_statuses: nil, retry_methods: nil, http_callback: nil,
|
|
70
|
+
proxy_settings: nil, logging_configuration: nil,
|
|
71
|
+
environment: nil)
|
|
72
|
+
connection ||= self.connection
|
|
73
|
+
adapter ||= self.adapter
|
|
74
|
+
timeout ||= self.timeout
|
|
75
|
+
max_retries ||= self.max_retries
|
|
76
|
+
retry_interval ||= self.retry_interval
|
|
77
|
+
backoff_factor ||= self.backoff_factor
|
|
78
|
+
retry_statuses ||= self.retry_statuses
|
|
79
|
+
retry_methods ||= self.retry_methods
|
|
80
|
+
http_callback ||= self.http_callback
|
|
81
|
+
proxy_settings ||= self.proxy_settings
|
|
82
|
+
logging_configuration ||= self.logging_configuration
|
|
83
|
+
environment ||= self.environment
|
|
84
|
+
|
|
85
|
+
Configuration.new(connection: connection, adapter: adapter,
|
|
86
|
+
timeout: timeout, max_retries: max_retries,
|
|
87
|
+
retry_interval: retry_interval,
|
|
88
|
+
backoff_factor: backoff_factor,
|
|
89
|
+
retry_statuses: retry_statuses,
|
|
90
|
+
retry_methods: retry_methods,
|
|
91
|
+
http_callback: http_callback,
|
|
92
|
+
proxy_settings: proxy_settings,
|
|
93
|
+
logging_configuration: logging_configuration,
|
|
94
|
+
environment: environment)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
# All the environments the SDK can run in.
|
|
99
|
+
ENVIRONMENTS = {
|
|
100
|
+
Environment::PRODUCTION => {
|
|
101
|
+
Server::DEFAULT => 'https://examples.apimatic.io/apps/calculator'
|
|
102
|
+
}
|
|
103
|
+
}.freeze
|
|
104
|
+
|
|
105
|
+
# Generates the appropriate base URI for the environment and the server.
|
|
106
|
+
# @param [Configuration::Server] server The server enum for which the base URI is
|
|
107
|
+
# required.
|
|
108
|
+
# @return [String] The base URI.
|
|
109
|
+
def get_base_uri(server = Server::DEFAULT)
|
|
110
|
+
ENVIRONMENTS[environment][server].clone
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# Builds a Configuration instance using environment variables.
|
|
114
|
+
def self.build_default_config_from_env
|
|
115
|
+
# === Core environment ===
|
|
116
|
+
environment = Environment.from_value(ENV.fetch('ENVIRONMENT', 'production'))
|
|
117
|
+
timeout = (ENV['TIMEOUT'] || 30).to_f
|
|
118
|
+
max_retries = (ENV['MAX_RETRIES'] || 0).to_i
|
|
119
|
+
retry_interval = (ENV['RETRY_INTERVAL'] || 1).to_f
|
|
120
|
+
backoff_factor = (ENV['BACKOFF_FACTOR'] || 2).to_f
|
|
121
|
+
retry_statuses = ENV.fetch('RETRY_STATUSES',
|
|
122
|
+
'[408, 413, 429, 500, 502, 503, 504, 521, 522, 524]').gsub(/[\[\]]/, '')
|
|
123
|
+
.split(',')
|
|
124
|
+
.map(&:strip)
|
|
125
|
+
.map do |item|
|
|
126
|
+
item.match?(/\A\d+\z/) ? item.to_i : item.downcase
|
|
127
|
+
end
|
|
128
|
+
retry_methods = ENV.fetch('RETRY_METHODS', '%i[get put]').gsub(/[\[\]]/, '')
|
|
129
|
+
.split(',')
|
|
130
|
+
.map(&:strip)
|
|
131
|
+
.map do |item|
|
|
132
|
+
item.match?(/\A\d+\z/) ? item.to_i : item.downcase
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# === Proxy settings ===
|
|
136
|
+
proxy_settings = ProxySettings.from_env
|
|
137
|
+
# === Logging Configuration ===
|
|
138
|
+
logging_configuration = LoggingConfiguration.from_env if LoggingConfiguration.any_logging_configured?
|
|
139
|
+
|
|
140
|
+
Configuration.new(
|
|
141
|
+
environment: environment,
|
|
142
|
+
timeout: timeout,
|
|
143
|
+
max_retries: max_retries,
|
|
144
|
+
retry_interval: retry_interval,
|
|
145
|
+
backoff_factor: backoff_factor,
|
|
146
|
+
retry_statuses: retry_statuses,
|
|
147
|
+
retry_methods: retry_methods,
|
|
148
|
+
proxy_settings: proxy_settings,
|
|
149
|
+
logging_configuration: logging_configuration
|
|
150
|
+
)
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# Class for exceptions when there is a network error, status code error, etc.
|
|
8
|
+
class APIException < CoreLibrary::ApiException
|
|
9
|
+
# Provides a human-readable string representation of the object.
|
|
10
|
+
def to_s
|
|
11
|
+
class_name = self.class.name.split('::').last
|
|
12
|
+
"<#{class_name} status_code: #{@response_code}, reason: #{@reason}>"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Provides a debugging-friendly string with detailed object information.
|
|
16
|
+
def inspect
|
|
17
|
+
class_name = self.class.name.split('::').last
|
|
18
|
+
"<#{class_name} status_code: #{@response_code.inspect}, reason: #{@reason.inspect}>"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# Http response received.
|
|
8
|
+
class ApiResponse < CoreLibrary::ApiResponse
|
|
9
|
+
# The constructor
|
|
10
|
+
# @param [HttpResponse] http_response The original, raw response from the api.
|
|
11
|
+
# @param [Object] data The data field specified for the response.
|
|
12
|
+
# @param [Array<String>] errors Any errors returned by the server.
|
|
13
|
+
def initialize(http_response,
|
|
14
|
+
data: nil,
|
|
15
|
+
errors: nil)
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# HttpCallBack allows defining callables for pre and post API calls.
|
|
8
|
+
class HttpCallBack < CoreLibrary::HttpCallback
|
|
9
|
+
end
|
|
10
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
##
|
|
8
|
+
# ProxySettings encapsulates HTTP proxy configuration for Faraday,
|
|
9
|
+
# including optional basic authentication.
|
|
10
|
+
#
|
|
11
|
+
class ProxySettings < CoreLibrary::ProxySettings
|
|
12
|
+
def self.from_env
|
|
13
|
+
address = ENV['PROXY_ADDRESS']
|
|
14
|
+
port = ENV['PROXY_PORT']
|
|
15
|
+
username = ENV['PROXY_USERNAME']
|
|
16
|
+
password = ENV['PROXY_PASSWORD']
|
|
17
|
+
return nil if address.nil? || address.strip.empty?
|
|
18
|
+
|
|
19
|
+
new(address: address, port: port, username: username, password: password)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# Initializes a new instance of RequestLoggingConfiguration.
|
|
8
|
+
class RequestLoggingConfiguration < CoreLibrary::ApiRequestLoggingConfiguration
|
|
9
|
+
# @param log_body [Boolean] Indicates whether the message body should be logged. Default is false.
|
|
10
|
+
# @param log_headers [Boolean] Indicates whether the message headers should be logged. Default is false.
|
|
11
|
+
# @param headers_to_exclude [Array<String>] Array of headers not displayed in logging. Default is an empty array.
|
|
12
|
+
# @param headers_to_include [Array<String>] Array of headers to be displayed in logging. Default is an empty array.
|
|
13
|
+
# @param headers_to_unmask [Array<String>] Array of headers which values are non-sensitive to display in logging.
|
|
14
|
+
# Default is an empty array.
|
|
15
|
+
def initialize(log_body: false, log_headers: false, headers_to_include: nil,
|
|
16
|
+
headers_to_exclude: nil, headers_to_unmask: nil,
|
|
17
|
+
include_query_in_path: false)
|
|
18
|
+
super(
|
|
19
|
+
log_body,
|
|
20
|
+
log_headers,
|
|
21
|
+
headers_to_exclude,
|
|
22
|
+
headers_to_include,
|
|
23
|
+
headers_to_unmask,
|
|
24
|
+
include_query_in_path
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def clone_with(log_body: nil, log_headers: nil, headers_to_include: nil,
|
|
29
|
+
headers_to_exclude: nil, headers_to_unmask: nil, include_query_in_path: nil)
|
|
30
|
+
log_body ||= self.log_body
|
|
31
|
+
log_headers ||= self.log_headers
|
|
32
|
+
headers_to_include ||= self.headers_to_include
|
|
33
|
+
headers_to_exclude ||= self.headers_to_exclude
|
|
34
|
+
headers_to_unmask ||= self.headers_to_unmask
|
|
35
|
+
include_query_in_path ||= self.include_query_in_path
|
|
36
|
+
|
|
37
|
+
RequestLoggingConfiguration.new(
|
|
38
|
+
log_body: log_body,
|
|
39
|
+
log_headers: log_headers,
|
|
40
|
+
headers_to_include: headers_to_include,
|
|
41
|
+
headers_to_exclude: headers_to_exclude,
|
|
42
|
+
headers_to_unmask: headers_to_unmask,
|
|
43
|
+
include_query_in_path: include_query_in_path
|
|
44
|
+
)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.from_env
|
|
48
|
+
log_body = ENV['REQUEST_LOG_BODY']
|
|
49
|
+
log_headers = ENV['REQUEST_LOG_HEADERS']
|
|
50
|
+
headers_to_include = ENV['REQUEST_HEADERS_TO_INCLUDE']
|
|
51
|
+
headers_to_exclude = ENV['REQUEST_HEADERS_TO_EXCLUDE']
|
|
52
|
+
headers_to_unmask = ENV['REQUEST_HEADERS_TO_UNMASK']
|
|
53
|
+
include_query_in_path = ENV['REQUEST_INCLUDE_QUERY_IN_PATH']
|
|
54
|
+
|
|
55
|
+
new(
|
|
56
|
+
log_body: log_body,
|
|
57
|
+
log_headers: log_headers,
|
|
58
|
+
headers_to_include: headers_to_include,
|
|
59
|
+
headers_to_exclude: headers_to_exclude,
|
|
60
|
+
headers_to_unmask: headers_to_unmask,
|
|
61
|
+
include_query_in_path: include_query_in_path
|
|
62
|
+
)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def self.any_logging_configured?
|
|
66
|
+
%w[
|
|
67
|
+
REQUEST_LOG_BODY
|
|
68
|
+
REQUEST_LOG_HEADERS
|
|
69
|
+
REQUEST_HEADERS_TO_INCLUDE
|
|
70
|
+
REQUEST_HEADERS_TO_EXCLUDE
|
|
71
|
+
REQUEST_HEADERS_TO_UNMASK
|
|
72
|
+
REQUEST_INCLUDE_QUERY_IN_PATH
|
|
73
|
+
].any? { |key| ENV.key?(key) && !ENV[key].nil? && !ENV[key].empty? }
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Initializes a new instance of ResponseLoggingConfiguration.
|
|
78
|
+
class ResponseLoggingConfiguration < CoreLibrary::ApiResponseLoggingConfiguration
|
|
79
|
+
def initialize(log_body: false, log_headers: false, headers_to_include: nil,
|
|
80
|
+
headers_to_exclude: nil, headers_to_unmask: nil)
|
|
81
|
+
super(
|
|
82
|
+
log_body,
|
|
83
|
+
log_headers,
|
|
84
|
+
headers_to_exclude,
|
|
85
|
+
headers_to_include,
|
|
86
|
+
headers_to_unmask
|
|
87
|
+
)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def clone_with(log_body: nil, log_headers: nil, headers_to_include: nil,
|
|
91
|
+
headers_to_exclude: nil, headers_to_unmask: nil)
|
|
92
|
+
log_body ||= self.log_body
|
|
93
|
+
log_headers ||= self.log_headers
|
|
94
|
+
headers_to_include ||= self.headers_to_include
|
|
95
|
+
headers_to_exclude ||= self.headers_to_exclude
|
|
96
|
+
headers_to_unmask ||= self.headers_to_unmask
|
|
97
|
+
|
|
98
|
+
ResponseLoggingConfiguration.new(
|
|
99
|
+
log_body: log_body,
|
|
100
|
+
log_headers: log_headers,
|
|
101
|
+
headers_to_include: headers_to_include,
|
|
102
|
+
headers_to_exclude: headers_to_exclude,
|
|
103
|
+
headers_to_unmask: headers_to_unmask
|
|
104
|
+
)
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def self.from_env
|
|
108
|
+
log_body = ENV['RESPONSE_LOG_BODY']
|
|
109
|
+
log_headers = ENV['RESPONSE_LOG_HEADERS']
|
|
110
|
+
headers_to_include = ENV['RESPONSE_HEADERS_TO_INCLUDE']
|
|
111
|
+
headers_to_exclude = ENV['RESPONSE_HEADERS_TO_EXCLUDE']
|
|
112
|
+
headers_to_unmask = ENV['RESPONSE_HEADERS_TO_UNMASK']
|
|
113
|
+
|
|
114
|
+
new(
|
|
115
|
+
log_body: log_body,
|
|
116
|
+
log_headers: log_headers,
|
|
117
|
+
headers_to_include: headers_to_include,
|
|
118
|
+
headers_to_exclude: headers_to_exclude,
|
|
119
|
+
headers_to_unmask: headers_to_unmask
|
|
120
|
+
)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def self.any_logging_configured?
|
|
124
|
+
%w[
|
|
125
|
+
RESPONSE_LOG_BODY
|
|
126
|
+
RESPONSE_LOG_HEADERS
|
|
127
|
+
RESPONSE_HEADERS_TO_INCLUDE
|
|
128
|
+
RESPONSE_HEADERS_TO_EXCLUDE
|
|
129
|
+
RESPONSE_HEADERS_TO_UNMASK
|
|
130
|
+
].any? { |key| ENV.key?(key) && !ENV[key].nil? && !ENV[key].empty? }
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Initializes a new instance of LoggingConfiguration.
|
|
135
|
+
class LoggingConfiguration < CoreLibrary::ApiLoggingConfiguration
|
|
136
|
+
def initialize(logger: nil, log_level: nil, mask_sensitive_headers: true,
|
|
137
|
+
request_logging_config: nil,
|
|
138
|
+
response_logging_config: nil)
|
|
139
|
+
request_logging_config ||= RequestLoggingConfiguration.new
|
|
140
|
+
response_logging_config ||= ResponseLoggingConfiguration.new
|
|
141
|
+
super(
|
|
142
|
+
logger,
|
|
143
|
+
log_level,
|
|
144
|
+
request_logging_config,
|
|
145
|
+
response_logging_config,
|
|
146
|
+
mask_sensitive_headers
|
|
147
|
+
)
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def clone_with(logger: nil, log_level: nil, mask_sensitive_headers: nil,
|
|
151
|
+
request_logging_config: nil, response_logging_config: nil)
|
|
152
|
+
logger ||= self.logger
|
|
153
|
+
log_level ||= self.log_level
|
|
154
|
+
mask_sensitive_headers ||= self.mask_sensitive_headers
|
|
155
|
+
request_logging_config ||= self.request_logging_config.clone
|
|
156
|
+
response_logging_config ||= self.response_logging_config.clone
|
|
157
|
+
|
|
158
|
+
LoggingConfiguration.new(
|
|
159
|
+
logger: logger,
|
|
160
|
+
log_level: log_level,
|
|
161
|
+
mask_sensitive_headers: mask_sensitive_headers,
|
|
162
|
+
request_logging_config: request_logging_config,
|
|
163
|
+
response_logging_config: response_logging_config
|
|
164
|
+
)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def self.from_env
|
|
168
|
+
log_level = ENV['LOG_LEVEL']
|
|
169
|
+
mask_sensitive_headers = ENV['MASK_SENSITIVE_HEADERS']
|
|
170
|
+
|
|
171
|
+
new(
|
|
172
|
+
log_level: log_level,
|
|
173
|
+
mask_sensitive_headers: mask_sensitive_headers,
|
|
174
|
+
request_logging_config: RequestLoggingConfiguration.from_env,
|
|
175
|
+
response_logging_config: ResponseLoggingConfiguration.from_env
|
|
176
|
+
)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def self.any_logging_configured?
|
|
180
|
+
RequestLoggingConfiguration.any_logging_configured? ||
|
|
181
|
+
ResponseLoggingConfiguration.any_logging_configured? ||
|
|
182
|
+
ENV.key?('LOG_LEVEL') ||
|
|
183
|
+
ENV.key?('MASK_SENSITIVE_HEADERS')
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# Represents the generic logger facade
|
|
8
|
+
class AbstractLogger < Logger
|
|
9
|
+
# Logs a message with a specified log level and additional parameters.
|
|
10
|
+
# @param level [Symbol] The log level of the message.
|
|
11
|
+
# @param message [String] The message to log.
|
|
12
|
+
# @param params [Hash] Additional parameters to include in the log message.
|
|
13
|
+
def log(level, message, params)
|
|
14
|
+
raise NotImplementedError, 'This method needs to be implemented in a child class.'
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# Base model.
|
|
8
|
+
# rubocop:disable all
|
|
9
|
+
class BaseModel < CoreLibrary::BaseModel
|
|
10
|
+
# Returns a Hash representation of the current object.
|
|
11
|
+
def to_hash
|
|
12
|
+
# validating the model being serialized
|
|
13
|
+
self.class.validate(self) if self.class.respond_to?(:validate)
|
|
14
|
+
|
|
15
|
+
hash = {}
|
|
16
|
+
instance_variables.each do |name|
|
|
17
|
+
value = instance_variable_get(name)
|
|
18
|
+
name = name[1..]
|
|
19
|
+
if name == 'additional_properties'
|
|
20
|
+
additional_properties = process_additional_properties(value, self.class.names)
|
|
21
|
+
hash.merge!(additional_properties)
|
|
22
|
+
else
|
|
23
|
+
key = self.class.names.key?(name) ? self.class.names[name] : name
|
|
24
|
+
optional_fields = self.class.optionals
|
|
25
|
+
nullable_fields = self.class.nullables
|
|
26
|
+
if value.nil?
|
|
27
|
+
next unless nullable_fields.include?(name)
|
|
28
|
+
|
|
29
|
+
if !optional_fields.include?(name) && !nullable_fields.include?(name)
|
|
30
|
+
raise ArgumentError,
|
|
31
|
+
"`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
hash[key] = nil
|
|
36
|
+
unless value.nil?
|
|
37
|
+
if respond_to?("to_custom_#{name}")
|
|
38
|
+
if (value.instance_of? Array) || (value.instance_of? Hash)
|
|
39
|
+
params = [hash, key]
|
|
40
|
+
hash[key] = send("to_custom_#{name}", *params)
|
|
41
|
+
else
|
|
42
|
+
hash[key] = send("to_custom_#{name}")
|
|
43
|
+
end
|
|
44
|
+
elsif respond_to?("to_union_type_#{name}")
|
|
45
|
+
hash[key] = send("to_union_type_#{name}")
|
|
46
|
+
elsif value.instance_of? Array
|
|
47
|
+
hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
|
48
|
+
elsif value.instance_of? Hash
|
|
49
|
+
hash[key] = {}
|
|
50
|
+
value.each do |k, v|
|
|
51
|
+
hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
|
|
52
|
+
end
|
|
53
|
+
else
|
|
54
|
+
hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
hash
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Processes additional properties, ensuring no conflicts with existing properties.
|
|
63
|
+
def process_additional_properties(additional_properties, existing_prop_names)
|
|
64
|
+
hash = {}
|
|
65
|
+
additional_properties.each do |name, value|
|
|
66
|
+
check_for_conflict(name, existing_prop_names)
|
|
67
|
+
|
|
68
|
+
hash[name] = if value.is_a?(Array)
|
|
69
|
+
process_array(value)
|
|
70
|
+
elsif value.is_a?(Hash)
|
|
71
|
+
process_hash(value)
|
|
72
|
+
else
|
|
73
|
+
process_basic_value(value)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
hash
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Checks if an additional property conflicts with a model's existing property.
|
|
80
|
+
def check_for_conflict(name, existing_prop_names)
|
|
81
|
+
return unless existing_prop_names.key?(name)
|
|
82
|
+
|
|
83
|
+
raise ArgumentError, "An additional property key, '#{name}' conflicts with one of the model's properties"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Processes an array of values, recursively calling `to_hash` on BaseModel objects.
|
|
87
|
+
def process_array(value)
|
|
88
|
+
value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Processes a hash of values, recursively calling `to_hash` on BaseModel objects.
|
|
92
|
+
def process_hash(value)
|
|
93
|
+
value.transform_values do |v|
|
|
94
|
+
v.is_a?(BaseModel) ? v.to_hash : v
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Processes a basic value (non-array, non-hash).
|
|
99
|
+
def process_basic_value(value)
|
|
100
|
+
value.is_a?(BaseModel) ? value.to_hash : value
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Returns a JSON representation of the curent object.
|
|
104
|
+
def to_json(options = {})
|
|
105
|
+
hash = to_hash
|
|
106
|
+
hash.to_json(options)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
# rubocop:enable all
|
|
110
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# Possible operators are sum, subtract, multiply, divide
|
|
8
|
+
class OperationType
|
|
9
|
+
OPERATION_TYPE = [
|
|
10
|
+
# TODO: Write general description for SUM
|
|
11
|
+
SUM = 'SUM'.freeze,
|
|
12
|
+
|
|
13
|
+
# TODO: Write general description for SUBTRACT
|
|
14
|
+
SUBTRACT = 'SUBTRACT'.freeze,
|
|
15
|
+
|
|
16
|
+
# TODO: Write general description for MULTIPLY
|
|
17
|
+
MULTIPLY = 'MULTIPLY'.freeze,
|
|
18
|
+
|
|
19
|
+
# TODO: Write general description for DIVIDE
|
|
20
|
+
DIVIDE = 'DIVIDE'.freeze
|
|
21
|
+
].freeze
|
|
22
|
+
|
|
23
|
+
def self.validate(value)
|
|
24
|
+
return false if value.nil?
|
|
25
|
+
|
|
26
|
+
OPERATION_TYPE.include?(value)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.from_value(value, default_value = SUM)
|
|
30
|
+
return default_value if value.nil?
|
|
31
|
+
|
|
32
|
+
str = value.to_s.strip
|
|
33
|
+
|
|
34
|
+
case str.downcase
|
|
35
|
+
when 'sum' then SUM
|
|
36
|
+
when 'subtract' then SUBTRACT
|
|
37
|
+
when 'multiply' then MULTIPLY
|
|
38
|
+
when 'divide' then DIVIDE
|
|
39
|
+
else
|
|
40
|
+
default_value
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
require 'date'
|
|
7
|
+
module ApimaticCalculator
|
|
8
|
+
# A utility that supports dateTime conversion to different formats
|
|
9
|
+
class DateTimeHelper < CoreLibrary::DateTimeHelper
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module ApimaticCalculator
|
|
7
|
+
# A utility to allow users to set the content-type for files
|
|
8
|
+
class FileWrapper < CoreLibrary::FileWrapper
|
|
9
|
+
# The constructor.
|
|
10
|
+
# @param [File] file The file to be sent in the request.
|
|
11
|
+
# @param [string] content_type The content type of the provided file.
|
|
12
|
+
def initialize(file, content_type: 'application/octet-stream')
|
|
13
|
+
super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Provides a human-readable string representation of the object.
|
|
17
|
+
def to_s
|
|
18
|
+
class_name = self.class.name.split('::').last
|
|
19
|
+
"<#{class_name} file: #{@file}, content_type: #{@content_type}>"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Provides a debugging-friendly string with detailed object information.
|
|
23
|
+
def to_inspect
|
|
24
|
+
class_name = self.class.name.split('::').last
|
|
25
|
+
"<#{class_name} file: #{@file.inspect}, content_type: #{@content_type.inspect}>"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# apimatic_calculator
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by APIMATIC
|
|
4
|
+
# v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
require 'date'
|
|
7
|
+
require 'json'
|
|
8
|
+
|
|
9
|
+
require 'apimatic_core_interfaces'
|
|
10
|
+
require 'apimatic_core'
|
|
11
|
+
require 'apimatic_faraday_client_adapter'
|
|
12
|
+
|
|
13
|
+
require_relative 'apimatic_calculator/api_helper'
|
|
14
|
+
require_relative 'apimatic_calculator/client'
|
|
15
|
+
|
|
16
|
+
# Utilities
|
|
17
|
+
require_relative 'apimatic_calculator/utilities/file_wrapper'
|
|
18
|
+
require_relative 'apimatic_calculator/utilities/date_time_helper'
|
|
19
|
+
|
|
20
|
+
# Http
|
|
21
|
+
require_relative 'apimatic_calculator/http/api_response'
|
|
22
|
+
require_relative 'apimatic_calculator/http/http_call_back'
|
|
23
|
+
require_relative 'apimatic_calculator/http/http_method_enum'
|
|
24
|
+
require_relative 'apimatic_calculator/http/http_request'
|
|
25
|
+
require_relative 'apimatic_calculator/http/http_response'
|
|
26
|
+
require_relative 'apimatic_calculator/http/proxy_settings'
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# Logger
|
|
30
|
+
require_relative 'apimatic_calculator/logging/configuration/' \
|
|
31
|
+
'api_logging_configuration'
|
|
32
|
+
require_relative 'apimatic_calculator/logging/sdk_logger'
|
|
33
|
+
|
|
34
|
+
# Models
|
|
35
|
+
require_relative 'apimatic_calculator/models/base_model'
|
|
36
|
+
require_relative 'apimatic_calculator/models/operation_type'
|
|
37
|
+
|
|
38
|
+
# Exceptions
|
|
39
|
+
require_relative 'apimatic_calculator/exceptions/api_exception'
|
|
40
|
+
|
|
41
|
+
require_relative 'apimatic_calculator/configuration'
|
|
42
|
+
|
|
43
|
+
# Controllers
|
|
44
|
+
require_relative 'apimatic_calculator/apis/base_api'
|
|
45
|
+
require_relative 'apimatic_calculator/apis/simple_calculator_api'
|
metadata
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: calc-matic
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Matic
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2026-01-31 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: apimatic_core_interfaces
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: 0.2.3
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: 0.2.3
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: apimatic_core
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 0.3.20
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 0.3.20
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: apimatic_faraday_client_adapter
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.1.6
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.1.6
|
|
55
|
+
description: ''
|
|
56
|
+
email: []
|
|
57
|
+
executables: []
|
|
58
|
+
extensions: []
|
|
59
|
+
extra_rdoc_files: []
|
|
60
|
+
files:
|
|
61
|
+
- LICENSE
|
|
62
|
+
- README.md
|
|
63
|
+
- bin/console
|
|
64
|
+
- lib/apimatic_calculator.rb
|
|
65
|
+
- lib/apimatic_calculator/api_helper.rb
|
|
66
|
+
- lib/apimatic_calculator/apis/base_api.rb
|
|
67
|
+
- lib/apimatic_calculator/apis/simple_calculator_api.rb
|
|
68
|
+
- lib/apimatic_calculator/client.rb
|
|
69
|
+
- lib/apimatic_calculator/configuration.rb
|
|
70
|
+
- lib/apimatic_calculator/exceptions/api_exception.rb
|
|
71
|
+
- lib/apimatic_calculator/http/api_response.rb
|
|
72
|
+
- lib/apimatic_calculator/http/http_call_back.rb
|
|
73
|
+
- lib/apimatic_calculator/http/http_method_enum.rb
|
|
74
|
+
- lib/apimatic_calculator/http/http_request.rb
|
|
75
|
+
- lib/apimatic_calculator/http/http_response.rb
|
|
76
|
+
- lib/apimatic_calculator/http/proxy_settings.rb
|
|
77
|
+
- lib/apimatic_calculator/logging/configuration/api_logging_configuration.rb
|
|
78
|
+
- lib/apimatic_calculator/logging/sdk_logger.rb
|
|
79
|
+
- lib/apimatic_calculator/models/base_model.rb
|
|
80
|
+
- lib/apimatic_calculator/models/operation_type.rb
|
|
81
|
+
- lib/apimatic_calculator/utilities/date_time_helper.rb
|
|
82
|
+
- lib/apimatic_calculator/utilities/file_wrapper.rb
|
|
83
|
+
homepage: https://apimatic.io
|
|
84
|
+
licenses:
|
|
85
|
+
- MIT
|
|
86
|
+
metadata: {}
|
|
87
|
+
post_install_message:
|
|
88
|
+
rdoc_options: []
|
|
89
|
+
require_paths:
|
|
90
|
+
- lib
|
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '2.6'
|
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
|
+
requirements:
|
|
98
|
+
- - ">="
|
|
99
|
+
- !ruby/object:Gem::Version
|
|
100
|
+
version: '0'
|
|
101
|
+
requirements: []
|
|
102
|
+
rubygems_version: 3.1.6
|
|
103
|
+
signing_key:
|
|
104
|
+
specification_version: 4
|
|
105
|
+
summary: dwdw
|
|
106
|
+
test_files: []
|