saeed-calc-apimatic 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +28 -0
- data/README.md +68 -0
- data/lib/apimatic_calculator/api_helper.rb +10 -0
- data/lib/apimatic_calculator/client.rb +43 -0
- data/lib/apimatic_calculator/configuration.rb +92 -0
- data/lib/apimatic_calculator/controllers/base_controller.rb +65 -0
- data/lib/apimatic_calculator/controllers/simple_calculator_controller.rb +31 -0
- data/lib/apimatic_calculator/exceptions/api_exception.rb +10 -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/models/base_model.rb +62 -0
- data/lib/apimatic_calculator/models/operation_type_enum.rb +29 -0
- data/lib/apimatic_calculator/utilities/date_time_helper.rb +11 -0
- data/lib/apimatic_calculator/utilities/file_wrapper.rb +16 -0
- data/lib/apimatic_calculator.rb +39 -0
- data/test/controllers/controller_test_base.rb +28 -0
- data/test/controllers/test_simple_calculator_controller.rb +35 -0
- data/test/http_response_catcher.rb +19 -0
- metadata +21 -104
- data/bin/arch +0 -1
- data/bin/ash +0 -1
- data/bin/base64 +0 -1
- data/bin/bbconfig +0 -1
- data/bin/busybox +0 -0
- data/bin/cat +0 -1
- data/bin/chattr +0 -1
- data/bin/chgrp +0 -1
- data/bin/chmod +0 -1
- data/bin/chown +0 -1
- data/bin/cp +0 -1
- data/bin/date +0 -1
- data/bin/dd +0 -1
- data/bin/df +0 -1
- data/bin/dmesg +0 -1
- data/bin/dnsdomainname +0 -1
- data/bin/dumpkmap +0 -1
- data/bin/echo +0 -1
- data/bin/ed +0 -1
- data/bin/egrep +0 -1
- data/bin/false +0 -1
- data/bin/fatattr +0 -1
- data/bin/fdflush +0 -1
- data/bin/fgrep +0 -1
- data/bin/fsync +0 -1
- data/bin/getopt +0 -1
- data/bin/grep +0 -1
- data/bin/gunzip +0 -1
- data/bin/gzip +0 -1
- data/bin/hostname +0 -1
- data/bin/ionice +0 -1
- data/bin/iostat +0 -1
- data/bin/ipcalc +0 -1
- data/bin/kbd_mode +0 -1
- data/bin/kill +0 -1
- data/bin/link +0 -1
- data/bin/linux32 +0 -1
- data/bin/linux64 +0 -1
- data/bin/ln +0 -1
- data/bin/login +0 -1
- data/bin/ls +0 -1
- data/bin/lsattr +0 -1
- data/bin/lzop +0 -1
- data/bin/makemime +0 -1
- data/bin/mkdir +0 -1
- data/bin/mknod +0 -1
- data/bin/mktemp +0 -1
- data/bin/more +0 -1
- data/bin/mount +0 -1
- data/bin/mountpoint +0 -1
- data/bin/mpstat +0 -1
- data/bin/mv +0 -1
- data/bin/netstat +0 -1
- data/bin/nice +0 -1
- data/bin/pidof +0 -0
- data/bin/ping +0 -1
- data/bin/ping6 +0 -1
- data/bin/pipe_progress +0 -1
- data/bin/printenv +0 -1
- data/bin/ps +0 -0
- data/bin/pwait +0 -0
- data/bin/pwd +0 -1
- data/bin/reformime +0 -1
- data/bin/rev +0 -1
- data/bin/rm +0 -1
- data/bin/rmdir +0 -1
- data/bin/run-parts +0 -1
- data/bin/sed +0 -1
- data/bin/setpriv +0 -1
- data/bin/setserial +0 -1
- data/bin/sh +0 -1
- data/bin/slabtop +0 -0
- data/bin/sleep +0 -1
- data/bin/stat +0 -1
- data/bin/stty +0 -1
- data/bin/su +0 -1
- data/bin/sync +0 -1
- data/bin/tar +0 -1
- data/bin/tload +0 -0
- data/bin/touch +0 -1
- data/bin/true +0 -1
- data/bin/umount +0 -1
- data/bin/uname +0 -1
- data/bin/usleep +0 -1
- data/bin/vmstat +0 -0
- data/bin/w +0 -0
- data/bin/watch +0 -0
- data/bin/zcat +0 -1
- data/lib/apk/db/installed +0 -3582
- data/lib/apk/db/lock +0 -0
- data/lib/apk/db/scripts.tar +0 -0
- data/lib/apk/db/triggers +0 -2
- data/lib/ld-musl-x86_64.so.1 +0 -0
- data/lib/libapk.so.3.12.0 +0 -0
- data/lib/libc.musl-x86_64.so.1 +0 -1
- data/lib/libcrypto.so.1.1 +0 -0
- data/lib/libprocps.so.8 +0 -1
- data/lib/libprocps.so.8.0.3 +0 -0
- data/lib/libssl.so.1.1 +0 -0
- data/lib/libz.so +0 -1
- data/lib/libz.so.1 +0 -1
- data/lib/libz.so.1.2.12 +0 -0
- data/lib/sysctl.d/00-alpine.conf +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 828f732de096b07de47ca02756b1b5b208e8ffb42c925d1ef1b0e194e86ff308
|
4
|
+
data.tar.gz: 789c880a98932fbe93e65e1fc661707640537b7749ef1818bd9fd6d81c601024
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '087711b29146bd432596054d5c0816987e90d21fc787400f0e2cbfd291b9cc531aad0a81e59fcd8c1a2f46caafcbd559052796c9a672df389e359df012e784f3'
|
7
|
+
data.tar.gz: abdafbad02270efca73ffe5c8ff14fea1488ee990f5d38e020ff2ae650cbd96800e1cde740c557903b85f3c5497e116b689083c1daca7d6ba65b84636a20a88d
|
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 - 2024 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,68 @@
|
|
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
|
+
```ruby
|
13
|
+
gem install saeed-calc-apimatic -v 0.1.1
|
14
|
+
```
|
15
|
+
|
16
|
+
Or add the gem to your Gemfile and run `bundle`:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'saeed-calc-apimatic', '0.1.1'
|
20
|
+
```
|
21
|
+
|
22
|
+
For additional gem details, see the [RubyGems page for the saeed-calc-apimatic gem](https://rubygems.org/gems/saeed-calc-apimatic/versions/0.1.1).
|
23
|
+
|
24
|
+
## Test the SDK
|
25
|
+
|
26
|
+
To run the tests, navigate to the root directory of the SDK in your terminal and execute the following command:
|
27
|
+
|
28
|
+
```
|
29
|
+
rake
|
30
|
+
```
|
31
|
+
|
32
|
+
## Initialize the API Client
|
33
|
+
|
34
|
+
**_Note:_** Documentation for the client can be found [here.](doc/client.md)
|
35
|
+
|
36
|
+
The following parameters are configurable for the API Client:
|
37
|
+
|
38
|
+
| Parameter | Type | Description |
|
39
|
+
| --- | --- | --- |
|
40
|
+
| `environment` | Environment | The API environment. <br> **Default: `Environment.PRODUCTION`** |
|
41
|
+
| `connection` | `Faraday::Connection` | The Faraday connection object passed by the SDK user for making requests |
|
42
|
+
| `adapter` | `Faraday::Adapter` | The Faraday adapter object passed by the SDK user for performing http requests |
|
43
|
+
| `timeout` | `Float` | The value to use for connection timeout. <br> **Default: 60** |
|
44
|
+
| `max_retries` | `Integer` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
|
45
|
+
| `retry_interval` | `Float` | Pause in seconds between retries. <br> **Default: 1** |
|
46
|
+
| `backoff_factor` | `Float` | The amount to multiply each successive retry's interval amount by in order to provide backoff. <br> **Default: 2** |
|
47
|
+
| `retry_statuses` | `Array` | A list of HTTP statuses to retry. <br> **Default: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]** |
|
48
|
+
| `retry_methods` | `Array` | A list of HTTP methods to retry. <br> **Default: %i[get put]** |
|
49
|
+
| `http_callback` | `HttpCallBack` | The Http CallBack allows defining callables for pre and post API calls. |
|
50
|
+
|
51
|
+
The API client can be initialized as follows:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
client = ApimaticCalculator::Client.new(
|
55
|
+
environment: Environment::PRODUCTION
|
56
|
+
)
|
57
|
+
```
|
58
|
+
|
59
|
+
## List of APIs
|
60
|
+
|
61
|
+
* [Simple Calculator](doc/controllers/simple-calculator.md)
|
62
|
+
|
63
|
+
## Classes Documentation
|
64
|
+
|
65
|
+
* [Utility Classes](doc/utility-classes.md)
|
66
|
+
* [HttpResponse](doc/http-response.md)
|
67
|
+
* [HttpRequest](doc/http-request.md)
|
68
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# apimatic_calculator client class.
|
8
|
+
class Client
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
# Access to simple_calculator controller.
|
12
|
+
# @return [SimpleCalculatorController] Returns the controller instance.
|
13
|
+
def simple_calculator
|
14
|
+
@simple_calculator ||= SimpleCalculatorController.new @global_configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(
|
18
|
+
connection: nil, adapter: :net_http_persistent, timeout: 60,
|
19
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
20
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
21
|
+
retry_methods: %i[get put], http_callback: nil,
|
22
|
+
environment: Environment::PRODUCTION, config: nil
|
23
|
+
)
|
24
|
+
@config = if config.nil?
|
25
|
+
Configuration.new(connection: connection, adapter: adapter,
|
26
|
+
timeout: timeout, max_retries: max_retries,
|
27
|
+
retry_interval: retry_interval,
|
28
|
+
backoff_factor: backoff_factor,
|
29
|
+
retry_statuses: retry_statuses,
|
30
|
+
retry_methods: retry_methods,
|
31
|
+
http_callback: http_callback,
|
32
|
+
environment: environment)
|
33
|
+
else
|
34
|
+
config
|
35
|
+
end
|
36
|
+
|
37
|
+
@global_configuration = GlobalConfiguration.new(client_configuration: @config)
|
38
|
+
.base_uri_executor(@config.method(:get_base_uri))
|
39
|
+
.global_errors(BaseController::GLOBAL_ERRORS)
|
40
|
+
.user_agent(BaseController.user_agent)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://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
|
+
end
|
14
|
+
|
15
|
+
# An enum for API servers.
|
16
|
+
class Server
|
17
|
+
SERVER = [
|
18
|
+
CALCULATOR = 'Calculator'.freeze
|
19
|
+
].freeze
|
20
|
+
end
|
21
|
+
|
22
|
+
# All configuration including auth info and base URI for the API access
|
23
|
+
# are configured in this class.
|
24
|
+
class Configuration < CoreLibrary::HttpClientConfiguration
|
25
|
+
# The attribute readers for properties.
|
26
|
+
attr_reader :environment
|
27
|
+
|
28
|
+
class << self
|
29
|
+
attr_reader :environments
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(
|
33
|
+
connection: nil, adapter: :net_http_persistent, timeout: 60,
|
34
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
35
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
36
|
+
retry_methods: %i[get put], http_callback: nil,
|
37
|
+
environment: Environment::PRODUCTION
|
38
|
+
)
|
39
|
+
|
40
|
+
super connection: connection, adapter: adapter, timeout: timeout,
|
41
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
42
|
+
backoff_factor: backoff_factor, retry_statuses: retry_statuses,
|
43
|
+
retry_methods: retry_methods, http_callback: http_callback
|
44
|
+
|
45
|
+
# Current API environment
|
46
|
+
@environment = String(environment)
|
47
|
+
|
48
|
+
# The Http Client to use for making requests.
|
49
|
+
set_http_client CoreLibrary::FaradayClient.new(self)
|
50
|
+
end
|
51
|
+
|
52
|
+
def clone_with(connection: nil, adapter: nil, timeout: nil,
|
53
|
+
max_retries: nil, retry_interval: nil, backoff_factor: nil,
|
54
|
+
retry_statuses: nil, retry_methods: nil, http_callback: nil,
|
55
|
+
environment: nil)
|
56
|
+
connection ||= self.connection
|
57
|
+
adapter ||= self.adapter
|
58
|
+
timeout ||= self.timeout
|
59
|
+
max_retries ||= self.max_retries
|
60
|
+
retry_interval ||= self.retry_interval
|
61
|
+
backoff_factor ||= self.backoff_factor
|
62
|
+
retry_statuses ||= self.retry_statuses
|
63
|
+
retry_methods ||= self.retry_methods
|
64
|
+
http_callback ||= self.http_callback
|
65
|
+
environment ||= self.environment
|
66
|
+
|
67
|
+
Configuration.new(connection: connection, adapter: adapter,
|
68
|
+
timeout: timeout, max_retries: max_retries,
|
69
|
+
retry_interval: retry_interval,
|
70
|
+
backoff_factor: backoff_factor,
|
71
|
+
retry_statuses: retry_statuses,
|
72
|
+
retry_methods: retry_methods,
|
73
|
+
http_callback: http_callback, environment: environment)
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
# All the environments the SDK can run in.
|
78
|
+
ENVIRONMENTS = {
|
79
|
+
Environment::PRODUCTION => {
|
80
|
+
Server::CALCULATOR => 'https://examples.apimatic.io/apps/calculator'
|
81
|
+
}
|
82
|
+
}.freeze
|
83
|
+
|
84
|
+
# Generates the appropriate base URI for the environment and the server.
|
85
|
+
# @param [Configuration::Server] server The server enum for which the base URI is
|
86
|
+
# required.
|
87
|
+
# @return [String] The base URI.
|
88
|
+
def get_base_uri(server = Server::CALCULATOR)
|
89
|
+
ENVIRONMENTS[environment][server].clone
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# BaseController.
|
8
|
+
class BaseController
|
9
|
+
attr_accessor :config, :http_call_back
|
10
|
+
|
11
|
+
def self.user_agent
|
12
|
+
'APIMATIC 3.0'
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
GLOBAL_ERRORS = {
|
17
|
+
'default' => ErrorCase.new
|
18
|
+
.error_message('HTTP response not OK.')
|
19
|
+
.exception_type(APIException)
|
20
|
+
}.freeze
|
21
|
+
|
22
|
+
# Initialization constructor.
|
23
|
+
# @param [GlobalConfiguration] global_configuration The instance of GlobalConfiguration.
|
24
|
+
def initialize(global_configuration)
|
25
|
+
@global_configuration = global_configuration
|
26
|
+
@config = @global_configuration.client_configuration
|
27
|
+
@http_call_back = @config.http_callback
|
28
|
+
@api_call = ApiCall.new(@global_configuration)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Creates a new builder for the Api Call instance.
|
32
|
+
# @return [ApiCall] The instance of ApiCall.
|
33
|
+
def new_api_call_builder
|
34
|
+
@api_call.new_builder
|
35
|
+
end
|
36
|
+
|
37
|
+
# Creates a new instance of the request builder.
|
38
|
+
# @param [String] http_method The HTTP method to use in the request.
|
39
|
+
# @param [String] path The endpoint path to use in the request.
|
40
|
+
# @param [String] server The server to extract the base uri for the request.
|
41
|
+
# @return [RequestBuilder] The instance of RequestBuilder.
|
42
|
+
def new_request_builder(http_method, path, server)
|
43
|
+
RequestBuilder.new
|
44
|
+
.http_method(http_method)
|
45
|
+
.path(path)
|
46
|
+
.server(server)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Creates a new instance of the response handler.
|
50
|
+
# @return [ResponseHandler] The instance of ResponseHandler.
|
51
|
+
def new_response_handler
|
52
|
+
ResponseHandler.new
|
53
|
+
end
|
54
|
+
|
55
|
+
# Creates a new instance of the parameter.
|
56
|
+
# @param [String|optional] key The key of the parameter.
|
57
|
+
# @param [Object] value The value of the parameter.
|
58
|
+
# @return [Parameter] The instance of Parameter.
|
59
|
+
def new_parameter(value, key: nil)
|
60
|
+
Parameter.new
|
61
|
+
.key(key)
|
62
|
+
.value(value)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# SimpleCalculatorController
|
8
|
+
class SimpleCalculatorController < BaseController
|
9
|
+
# Calculates the expression using the specified operation.
|
10
|
+
# @param [OperationTypeEnum] operation Required parameter: The operator to
|
11
|
+
# apply on the variables
|
12
|
+
# @param [Float] x Required parameter: The LHS value
|
13
|
+
# @param [Float] y Required parameter: The RHS value
|
14
|
+
# @return [Float] response from the API call
|
15
|
+
def get_calculate(options = {})
|
16
|
+
new_api_call_builder
|
17
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
18
|
+
'/{operation}',
|
19
|
+
Server::CALCULATOR)
|
20
|
+
.template_param(new_parameter(options['operation'], key: 'operation')
|
21
|
+
.should_encode(true))
|
22
|
+
.query_param(new_parameter(options['x'], key: 'x'))
|
23
|
+
.query_param(new_parameter(options['y'], key: 'y')))
|
24
|
+
.response(new_response_handler
|
25
|
+
.deserializer(APIHelper.method(:deserialize_primitive_types))
|
26
|
+
.deserialize_into(proc do |response| response.to_f end)
|
27
|
+
.is_primitive_response(true))
|
28
|
+
.execute
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://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
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://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,62 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# Base model.
|
8
|
+
class BaseModel < CoreLibrary::BaseModel
|
9
|
+
# Returns a Hash representation of the current object.
|
10
|
+
def to_hash
|
11
|
+
# validating the model being serialized
|
12
|
+
self.class.validate(self) if self.class.respond_to?(:validate)
|
13
|
+
|
14
|
+
hash = {}
|
15
|
+
instance_variables.each do |name|
|
16
|
+
value = instance_variable_get(name)
|
17
|
+
name = name[1..]
|
18
|
+
key = self.class.names.key?(name) ? self.class.names[name] : name
|
19
|
+
optional_fields = self.class.optionals
|
20
|
+
nullable_fields = self.class.nullables
|
21
|
+
if value.nil?
|
22
|
+
next unless nullable_fields.include?(name)
|
23
|
+
|
24
|
+
if !optional_fields.include?(name) && !nullable_fields.include?(name)
|
25
|
+
raise ArgumentError,
|
26
|
+
"`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
hash[key] = nil
|
31
|
+
unless value.nil?
|
32
|
+
if respond_to?("to_custom_#{name}")
|
33
|
+
if (value.instance_of? Array) || (value.instance_of? Hash)
|
34
|
+
params = [hash, key]
|
35
|
+
hash[key] = send("to_custom_#{name}", *params)
|
36
|
+
else
|
37
|
+
hash[key] = send("to_custom_#{name}")
|
38
|
+
end
|
39
|
+
elsif respond_to?("to_union_type_#{name}")
|
40
|
+
hash[key] = send("to_union_type_#{name}")
|
41
|
+
elsif value.instance_of? Array
|
42
|
+
hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
43
|
+
elsif value.instance_of? Hash
|
44
|
+
hash[key] = {}
|
45
|
+
value.each do |k, v|
|
46
|
+
hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
|
47
|
+
end
|
48
|
+
else
|
49
|
+
hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
hash
|
54
|
+
end
|
55
|
+
|
56
|
+
# Returns a JSON representation of the curent object.
|
57
|
+
def to_json(options = {})
|
58
|
+
hash = to_hash
|
59
|
+
hash.to_json(options)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# Possible operators are sum, subtract, multiply, divide
|
8
|
+
class OperationTypeEnum
|
9
|
+
OPERATION_TYPE_ENUM = [
|
10
|
+
# Represents the sum operator
|
11
|
+
SUM = 'SUM'.freeze,
|
12
|
+
|
13
|
+
# Represents the subtract operator
|
14
|
+
SUBTRACT = 'SUBTRACT'.freeze,
|
15
|
+
|
16
|
+
# Represents the multiply operator
|
17
|
+
MULTIPLY = 'MULTIPLY'.freeze,
|
18
|
+
|
19
|
+
# Represents the divide operator
|
20
|
+
DIVIDE = 'DIVIDE'.freeze
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
def self.validate(value)
|
24
|
+
return false if value.nil?
|
25
|
+
|
26
|
+
OPERATION_TYPE_ENUM.include?(value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://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,16 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://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
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
require 'json'
|
8
|
+
require 'apimatic_core_interfaces'
|
9
|
+
require 'apimatic_core'
|
10
|
+
require 'apimatic_faraday_client_adapter'
|
11
|
+
# rubocop:disable Style/MixinUsage
|
12
|
+
include CoreLibrary
|
13
|
+
# rubocop:enable Style/MixinUsage
|
14
|
+
|
15
|
+
require_relative 'apimatic_calculator/api_helper'
|
16
|
+
require_relative 'apimatic_calculator/client'
|
17
|
+
|
18
|
+
# Utilities
|
19
|
+
require_relative 'apimatic_calculator/utilities/file_wrapper'
|
20
|
+
require_relative 'apimatic_calculator/utilities/date_time_helper'
|
21
|
+
|
22
|
+
# Http
|
23
|
+
require_relative 'apimatic_calculator/http/http_call_back'
|
24
|
+
require_relative 'apimatic_calculator/http/http_method_enum'
|
25
|
+
require_relative 'apimatic_calculator/http/http_request'
|
26
|
+
require_relative 'apimatic_calculator/http/http_response'
|
27
|
+
|
28
|
+
# Models
|
29
|
+
require_relative 'apimatic_calculator/models/base_model'
|
30
|
+
require_relative 'apimatic_calculator/models/operation_type_enum'
|
31
|
+
|
32
|
+
# Exceptions
|
33
|
+
require_relative 'apimatic_calculator/exceptions/api_exception'
|
34
|
+
|
35
|
+
require_relative 'apimatic_calculator/configuration'
|
36
|
+
|
37
|
+
# Controllers
|
38
|
+
require_relative 'apimatic_calculator/controllers/base_controller'
|
39
|
+
require_relative 'apimatic_calculator/controllers/simple_calculator_controller'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'minitest/hell'
|
9
|
+
require 'minitest/pride'
|
10
|
+
require 'minitest/proveit'
|
11
|
+
require 'apimatic_calculator'
|
12
|
+
require_relative '../http_response_catcher'
|
13
|
+
|
14
|
+
class ControllerTestBase < Minitest::Test
|
15
|
+
parallelize_me!
|
16
|
+
include ApimaticCalculator
|
17
|
+
|
18
|
+
# Create configuration and set any test parameters
|
19
|
+
def create_configuration
|
20
|
+
Configuration.new(http_callback: HttpResponseCatcher.new)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Initializes the base test controller
|
24
|
+
def setup_class
|
25
|
+
_config = create_configuration
|
26
|
+
@client = Client.new(config: _config)
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require_relative 'controller_test_base'
|
7
|
+
|
8
|
+
class SimpleCalculatorControllerTests < ControllerTestBase
|
9
|
+
# Called only once for the class before any test has executed
|
10
|
+
def setup
|
11
|
+
setup_class
|
12
|
+
@controller = @client.simple_calculator
|
13
|
+
@response_catcher = @controller.http_call_back
|
14
|
+
end
|
15
|
+
|
16
|
+
# Check if multiplication works
|
17
|
+
def test_multiply
|
18
|
+
# Parameters for the API call
|
19
|
+
options = {}
|
20
|
+
options['operation'] = 'MULTIPLY'
|
21
|
+
options['x'] = 4
|
22
|
+
options['y'] = 5
|
23
|
+
|
24
|
+
# Perform the API call through the SDK function
|
25
|
+
result = @controller.get_calculate(options)
|
26
|
+
|
27
|
+
# Test response code
|
28
|
+
assert_equal(200, @response_catcher.response.status_code)
|
29
|
+
|
30
|
+
# Test whether the captured response is as we expected
|
31
|
+
refute_nil(result)
|
32
|
+
assert_equal('20', @response_catcher.response.raw_body)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
class HttpResponseCatcher < ApimaticCalculator::HttpCallBack
|
7
|
+
attr_accessor :response
|
8
|
+
|
9
|
+
def on_before_request(request)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Catching the response
|
13
|
+
def on_after_response(response)
|
14
|
+
@response = response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|