Calculator_Task 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +135 -0
- data/lib/calculator_task.rb +35 -0
- data/lib/calculator_task/api_helper.rb +275 -0
- data/lib/calculator_task/calculator_task_client.rb +21 -0
- data/lib/calculator_task/configuration.rb +20 -0
- data/lib/calculator_task/controllers/base_controller.rb +51 -0
- data/lib/calculator_task/controllers/simple_calculator_controller.rb +55 -0
- data/lib/calculator_task/exceptions/api_exception.rb +20 -0
- data/lib/calculator_task/http/faraday_client.rb +64 -0
- data/lib/calculator_task/http/http_call_back.rb +24 -0
- data/lib/calculator_task/http/http_client.rb +104 -0
- data/lib/calculator_task/http/http_context.rb +20 -0
- data/lib/calculator_task/http/http_method_enum.rb +13 -0
- data/lib/calculator_task/http/http_request.rb +50 -0
- data/lib/calculator_task/http/http_response.rb +23 -0
- data/lib/calculator_task/models/base_model.rb +36 -0
- data/lib/calculator_task/models/operation_type_enum.rb +23 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b131a3d366194fc786d9e1cd8e17bff4a80724d0bffc48c5c4eb6b905056a793
|
4
|
+
data.tar.gz: 68a79cd8d607c70fd8318fcef99b9c111446d915a60b668617c072daeaa3ca53
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1088e7252340a2e3b4985f1b267d0ba0e8cc4ac163282e36d4ba151f82279013b7f1870390cbfb5b7a24d04cf183299e05467b90c6ca62028121c8ad89733ffa
|
7
|
+
data.tar.gz: 667235aaebff70f2dd5fa3fac52e788bcba29c26938c01c4e9f17c4757a40bc9a624bcf68a87ab12056d2a7550324e0cc7e54c2ef8271f13dc275623389903e1
|
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 - 2016 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,135 @@
|
|
1
|
+
# Getting started
|
2
|
+
|
3
|
+
Simple Calculator API.
|
4
|
+
|
5
|
+
## How to Build
|
6
|
+
|
7
|
+
This client library is a Ruby gem which can be compiled and used in your Ruby and Ruby on Rails project. This library requires a few gems from the RubyGems repository.
|
8
|
+
|
9
|
+
1. Open the command line interface or the terminal and navigate to the folder containing the source code.
|
10
|
+
2. Run ``` gem build calculator_task.gemspec ``` to build the gem.
|
11
|
+
3. Once built, the gem can be installed on the current work environment using ``` gem install calculator_task-1.0.gem ```
|
12
|
+
|
13
|
+
![Building Gem](https://apidocs.io/illustration/ruby?step=buildSDK&workspaceFolder=Calculator%20Task-Ruby&workspaceName=Calculator%20Task-Ruby&projectName=calculator_task&gemName=calculator_task&gemVer=1.0)
|
14
|
+
|
15
|
+
## How to Use
|
16
|
+
|
17
|
+
The following section explains how to use the CalculatorTask Ruby Gem in a new Rails project using RubyMine™. The basic workflow presented here is also applicable if you prefer using a different editor or IDE.
|
18
|
+
|
19
|
+
### 1. Starting a new project
|
20
|
+
|
21
|
+
Close any existing projects in RubyMine™ by selecting ``` File -> Close Project ```. Next, click on ``` Create New Project ``` to create a new project from scratch.
|
22
|
+
|
23
|
+
![Create a new project in RubyMine](https://apidocs.io/illustration/ruby?step=createNewProject0&workspaceFolder=Calculator%20Task-Ruby&workspaceName=CalculatorTask&projectName=calculator_task&gemName=calculator_task&gemVer=1.0)
|
24
|
+
|
25
|
+
Next, provide ``` TestApp ``` as the project name, choose ``` Rails Application ``` as the project type, and click ``` OK ```.
|
26
|
+
|
27
|
+
![Create a new Rails Application in RubyMine - step 1](https://apidocs.io/illustration/ruby?step=createNewProject1&workspaceFolder=Calculator%20Task-Ruby&workspaceName=CalculatorTask&projectName=calculator_task&gemName=calculator_task&gemVer=1.0)
|
28
|
+
|
29
|
+
In the next dialog make sure that correct *Ruby SDK* is being used (minimum 2.0.0) and click ``` OK ```.
|
30
|
+
|
31
|
+
![Create a new Rails Application in RubyMine - step 2](https://apidocs.io/illustration/ruby?step=createNewProject2&workspaceFolder=Calculator%20Task-Ruby&workspaceName=CalculatorTask&projectName=calculator_task&gemName=calculator_task&gemVer=1.0)
|
32
|
+
|
33
|
+
This will create a new Rails Application project with an existing set of files and folder.
|
34
|
+
|
35
|
+
### 2. Add reference of the gem
|
36
|
+
|
37
|
+
In order to use the CalculatorTask gem in the new project we must add a gem reference. Locate the ```Gemfile``` in the *Project Explorer* window under the ``` TestApp ``` project node. The file contains references to all gems being used in the project. Here, add the reference to the library gem by adding the following line: ``` gem 'calculator_task', '~> 1.0' ```
|
38
|
+
|
39
|
+
![Add references of the Gemfile](https://apidocs.io/illustration/ruby?step=addReference&workspaceFolder=Calculator%20Task-Ruby&workspaceName=CalculatorTask&projectName=calculator_task&gemName=calculator_task&gemVer=1.0)
|
40
|
+
|
41
|
+
### 3. Adding a new Rails Controller
|
42
|
+
|
43
|
+
Once the ``` TestApp ``` project is created, a folder named ``` controllers ``` will be visible in the *Project Explorer* under the following path: ``` TestApp > app > controllers ```. Right click on this folder and select ``` New -> Run Rails Generator... ```.
|
44
|
+
|
45
|
+
![Run Rails Generator on Controllers Folder](https://apidocs.io/illustration/ruby?step=addCode0&workspaceFolder=Calculator%20Task-Ruby&workspaceName=CalculatorTask&projectName=calculator_task&gemName=calculator_task&gemVer=1.0)
|
46
|
+
|
47
|
+
Selecting the said option will popup a small window where the generator names are displayed. Here, select the ``` controller ``` template.
|
48
|
+
|
49
|
+
![Create a new Controller](https://apidocs.io/illustration/ruby?step=addCode1&workspaceFolder=Calculator%20Task-Ruby&workspaceName=CalculatorTask&projectName=calculator_task&gemName=calculator_task&gemVer=1.0)
|
50
|
+
|
51
|
+
Next, a popup window will ask you for a Controller name and included Actions. For controller name provide ``` Hello ``` and include an action named ``` Index ``` and click ``` OK ```.
|
52
|
+
|
53
|
+
![Add a new Controller](https://apidocs.io/illustration/ruby?step=addCode2&workspaceFolder=Calculator%20Task-Ruby&workspaceName=CalculatorTask&projectName=calculator_task&gemName=calculator_task&gemVer=1.0)
|
54
|
+
|
55
|
+
A new controller class anmed ``` HelloController ``` will be created in a file named ``` hello_controller.rb ``` containing a method named ``` Index ```. In this method, add code for initialization and a sample for its usage.
|
56
|
+
|
57
|
+
![Initialize the library](https://apidocs.io/illustration/ruby?step=addCode3&workspaceFolder=Calculator%20Task-Ruby&workspaceName=CalculatorTask&projectName=calculator_task&gemName=calculator_task&gemVer=1.0)
|
58
|
+
|
59
|
+
## How to Test
|
60
|
+
|
61
|
+
You can test the generated SDK and the server with automatically generated test
|
62
|
+
cases as follows:
|
63
|
+
|
64
|
+
1. From terminal/cmd navigate to the root directory of the SDK.
|
65
|
+
2. Invoke: `bundle exec rake`
|
66
|
+
|
67
|
+
## Initialization
|
68
|
+
|
69
|
+
###
|
70
|
+
|
71
|
+
API client can be initialized as following.
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
|
75
|
+
client = CalculatorTask::CalculatorTaskClient.new
|
76
|
+
```
|
77
|
+
|
78
|
+
The added initlization code can be debugged by putting a breakpoint in the ``` Index ``` method and running the project in debug mode by selecting ``` Run -> Debug 'Development: TestApp' ```.
|
79
|
+
|
80
|
+
![Debug the TestApp](https://apidocs.io/illustration/ruby?step=addCode4&workspaceFolder=Calculator%20Task-Ruby&workspaceName=CalculatorTask&projectName=calculator_task&gemName=calculator_task&gemVer=1.0&initLine=client%2520%253D%2520CalculatorTaskClient.new)
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
# Class Reference
|
85
|
+
|
86
|
+
## <a name="list_of_controllers"></a>List of Controllers
|
87
|
+
|
88
|
+
* [SimpleCalculatorController](#simple_calculator_controller)
|
89
|
+
|
90
|
+
## <a name="simple_calculator_controller"></a>![Class: ](https://apidocs.io/img/class.png ".SimpleCalculatorController") SimpleCalculatorController
|
91
|
+
|
92
|
+
### Get singleton instance
|
93
|
+
|
94
|
+
The singleton instance of the ``` SimpleCalculatorController ``` class can be accessed from the API Client.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
simpleCalculator_controller = client.simple_calculator
|
98
|
+
```
|
99
|
+
|
100
|
+
### <a name="get_calculate"></a>![Method: ](https://apidocs.io/img/method.png ".SimpleCalculatorController.get_calculate") get_calculate
|
101
|
+
|
102
|
+
> Endpoint Calculate
|
103
|
+
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
def get_calculate(operation,
|
107
|
+
x,
|
108
|
+
y); end
|
109
|
+
```
|
110
|
+
|
111
|
+
#### Parameters
|
112
|
+
|
113
|
+
| Parameter | Tags | Description |
|
114
|
+
|-----------|------|-------------|
|
115
|
+
| operation | ``` Required ``` | the operation to apply |
|
116
|
+
| x | ``` Required ``` ``` DefaultValue ``` | LHS |
|
117
|
+
| y | ``` Required ``` ``` DefaultValue ``` | RHS |
|
118
|
+
|
119
|
+
|
120
|
+
#### Example Usage
|
121
|
+
|
122
|
+
```ruby
|
123
|
+
operation = CalculatorTask::OperationTypeEnum::ADD
|
124
|
+
x = 4
|
125
|
+
y = 6
|
126
|
+
|
127
|
+
result = simpleCalculator_controller.get_calculate(operation, x, y)
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
[Back to List of Controllers](#list_of_controllers)
|
133
|
+
|
134
|
+
|
135
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
require 'json'
|
8
|
+
require 'faraday'
|
9
|
+
require 'certifi'
|
10
|
+
require 'logging'
|
11
|
+
|
12
|
+
require_relative 'calculator_task/api_helper.rb'
|
13
|
+
require_relative 'calculator_task/calculator_task_client.rb'
|
14
|
+
|
15
|
+
# Http
|
16
|
+
require_relative 'calculator_task/http/http_call_back.rb'
|
17
|
+
require_relative 'calculator_task/http/http_client.rb'
|
18
|
+
require_relative 'calculator_task/http/http_method_enum.rb'
|
19
|
+
require_relative 'calculator_task/http/http_request.rb'
|
20
|
+
require_relative 'calculator_task/http/http_response.rb'
|
21
|
+
require_relative 'calculator_task/http/http_context.rb'
|
22
|
+
require_relative 'calculator_task/http/faraday_client.rb'
|
23
|
+
|
24
|
+
# Models
|
25
|
+
require_relative 'calculator_task/models/base_model.rb'
|
26
|
+
require_relative 'calculator_task/models/operation_type_enum.rb'
|
27
|
+
|
28
|
+
# Exceptions
|
29
|
+
require_relative 'calculator_task/exceptions/api_exception.rb'
|
30
|
+
|
31
|
+
require_relative 'calculator_task/configuration.rb'
|
32
|
+
|
33
|
+
# Controllers
|
34
|
+
require_relative 'calculator_task/controllers/base_controller.rb'
|
35
|
+
require_relative 'calculator_task/controllers/simple_calculator_controller.rb'
|
@@ -0,0 +1,275 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# API utility class
|
8
|
+
class APIHelper
|
9
|
+
# Serializes an array parameter (creates key value pairs).
|
10
|
+
# @param [String] The name of the parameter.
|
11
|
+
# @param [Array] The value of the parameter.
|
12
|
+
# @param [String] The format of the serialization.
|
13
|
+
def self.serialize_array(key, array, formatting: 'indexed')
|
14
|
+
tuples = []
|
15
|
+
|
16
|
+
if formatting == 'unindexed'
|
17
|
+
tuples += array.map { |element| ["#{key}[]", element] }
|
18
|
+
elsif formatting == 'indexed'
|
19
|
+
tuples += array.map.with_index do |element, index|
|
20
|
+
["#{key}[#{index}]", element]
|
21
|
+
end
|
22
|
+
elsif formatting == 'plain'
|
23
|
+
tuples += array.map { |element| [key, element] }
|
24
|
+
else
|
25
|
+
raise ArgumentError, 'Invalid format provided.'
|
26
|
+
end
|
27
|
+
tuples
|
28
|
+
end
|
29
|
+
|
30
|
+
# Replaces template parameters in the given url.
|
31
|
+
# @param [String] The query string builder to replace the template
|
32
|
+
# parameters.
|
33
|
+
# @param [Hash] The parameters to replace in the url.
|
34
|
+
def self.append_url_with_template_parameters(query_builder, parameters)
|
35
|
+
# perform parameter validation
|
36
|
+
unless query_builder.instance_of? String
|
37
|
+
raise ArgumentError, 'Given value for parameter \"query_builder\" is
|
38
|
+
invalid.'
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return if there are no parameters to replace.
|
42
|
+
return query_builder if parameters.nil?
|
43
|
+
|
44
|
+
# Iterate and append parameters.
|
45
|
+
parameters.each do |key, value|
|
46
|
+
replace_value = ''
|
47
|
+
|
48
|
+
if value.nil?
|
49
|
+
replace_value = ''
|
50
|
+
elsif value.instance_of? Array
|
51
|
+
value.map! { |element| CGI.escape(element.to_s) }
|
52
|
+
replace_value = value.join('/')
|
53
|
+
else
|
54
|
+
replace_value = CGI.escape(value.to_s)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Find the template parameter and replace it with its value.
|
58
|
+
query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
|
59
|
+
end
|
60
|
+
query_builder
|
61
|
+
end
|
62
|
+
|
63
|
+
# Appends the given set of parameters to the given query string.
|
64
|
+
# @param [String] The query string builder to add the query parameters to.
|
65
|
+
# @param [Hash] The parameters to append.
|
66
|
+
# @param [String] The format of array parameter serialization.
|
67
|
+
def self.append_url_with_query_parameters(query_builder, parameters,
|
68
|
+
array_serialization: 'indexed')
|
69
|
+
# Perform parameter validation.
|
70
|
+
unless query_builder.instance_of? String
|
71
|
+
raise ArgumentError, 'Given value for parameter \"query_builder\"
|
72
|
+
is invalid.'
|
73
|
+
end
|
74
|
+
|
75
|
+
# Return if there are no parameters to replace.
|
76
|
+
return query_builder if parameters.nil?
|
77
|
+
|
78
|
+
parameters.each do |key, value|
|
79
|
+
seperator = query_builder.include?('?') ? '&' : '?'
|
80
|
+
unless value.nil?
|
81
|
+
if value.instance_of? Array
|
82
|
+
value.compact!
|
83
|
+
query_builder += if array_serialization == 'csv'
|
84
|
+
"#{seperator}#{key}=#{value.map do |element|
|
85
|
+
CGI.escape(element.to_s)
|
86
|
+
end.join(',')}"
|
87
|
+
elsif array_serialization == 'psv'
|
88
|
+
"#{seperator}#{key}=#{value.map do |element|
|
89
|
+
CGI.escape(element.to_s)
|
90
|
+
end.join('|')}"
|
91
|
+
elsif array_serialization == 'tsv'
|
92
|
+
"#{seperator}#{key}=#{value.map do |element|
|
93
|
+
CGI.escape(element.to_s)
|
94
|
+
end.join("\t")}"
|
95
|
+
else
|
96
|
+
"#{seperator}#{APIHelper.serialize_array(
|
97
|
+
key, value, formatting: array_serialization
|
98
|
+
).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
|
99
|
+
.join('&')}"
|
100
|
+
end
|
101
|
+
else
|
102
|
+
query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
query_builder
|
107
|
+
end
|
108
|
+
|
109
|
+
# Validates and processes the given Url.
|
110
|
+
# @param [String] The given Url to process.
|
111
|
+
# @return [String] Pre-processed Url as string.
|
112
|
+
def self.clean_url(url)
|
113
|
+
# Perform parameter validation.
|
114
|
+
raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
|
115
|
+
|
116
|
+
# Ensure that the urls are absolute.
|
117
|
+
matches = url.match(%r{^(https?:\/\/[^\/]+)})
|
118
|
+
raise ArgumentError, 'Invalid Url format.' if matches.nil?
|
119
|
+
|
120
|
+
# Get the http protocol match.
|
121
|
+
protocol = matches[1]
|
122
|
+
|
123
|
+
# Check if parameters exist.
|
124
|
+
index = url.index('?')
|
125
|
+
|
126
|
+
# Remove redundant forward slashes.
|
127
|
+
query = url[protocol.length...(!index.nil? ? index : url.length)]
|
128
|
+
query.gsub!(%r{\/\/+}, '/')
|
129
|
+
|
130
|
+
# Get the parameters.
|
131
|
+
parameters = !index.nil? ? url[url.index('?')...url.length] : ''
|
132
|
+
|
133
|
+
# Return processed url.
|
134
|
+
protocol + query + parameters
|
135
|
+
end
|
136
|
+
|
137
|
+
# Parses JSON string.
|
138
|
+
# @param [String] A JSON string.
|
139
|
+
def self.json_deserialize(json)
|
140
|
+
return JSON.parse(json)
|
141
|
+
rescue StandardError
|
142
|
+
raise TypeError, 'Server responded with invalid JSON.'
|
143
|
+
end
|
144
|
+
|
145
|
+
# Removes elements with empty values from a hash.
|
146
|
+
# @param [Hash] The hash to clean.
|
147
|
+
def self.clean_hash(hash)
|
148
|
+
hash.delete_if { |_key, value| value.to_s.strip.empty? }
|
149
|
+
end
|
150
|
+
|
151
|
+
# Form encodes a hash of parameters.
|
152
|
+
# @param [Hash] The hash of parameters to encode.
|
153
|
+
# @return [Hash] A hash with the same parameters form encoded.
|
154
|
+
def self.form_encode_parameters(form_parameters)
|
155
|
+
encoded = {}
|
156
|
+
form_parameters.each do |key, value|
|
157
|
+
encoded.merge!(APIHelper.form_encode(value, key, formatting:
|
158
|
+
Configuration.array_serialization))
|
159
|
+
end
|
160
|
+
encoded
|
161
|
+
end
|
162
|
+
|
163
|
+
def self.custom_merge(a, b)
|
164
|
+
x = {}
|
165
|
+
a.each do |key, value_a|
|
166
|
+
b.each do |k, value_b|
|
167
|
+
next unless key == k
|
168
|
+
x[k] = []
|
169
|
+
if value_a.instance_of? Array
|
170
|
+
value_a.each do |v|
|
171
|
+
x[k].push(v)
|
172
|
+
end
|
173
|
+
else
|
174
|
+
x[k].push(value_a)
|
175
|
+
end
|
176
|
+
if value_b.instance_of? Array
|
177
|
+
value_b.each do |v|
|
178
|
+
x[k].push(v)
|
179
|
+
end
|
180
|
+
else
|
181
|
+
x[k].push(value_b)
|
182
|
+
end
|
183
|
+
a.delete(k)
|
184
|
+
b.delete(k)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
x.merge!(a)
|
188
|
+
x.merge!(b)
|
189
|
+
x
|
190
|
+
end
|
191
|
+
|
192
|
+
# Form encodes an object.
|
193
|
+
# @param [Dynamic] An object to form encode.
|
194
|
+
# @param [String] The name of the object.
|
195
|
+
# @return [Hash] A form encoded representation of the object in the form
|
196
|
+
# of a hash.
|
197
|
+
def self.form_encode(obj, instance_name, formatting: 'indexed')
|
198
|
+
retval = {}
|
199
|
+
|
200
|
+
serializable_types = [String, Numeric, TrueClass,
|
201
|
+
FalseClass, Date, DateTime]
|
202
|
+
|
203
|
+
# If this is a structure, resolve it's field names.
|
204
|
+
obj = obj.to_hash if obj.is_a? BaseModel
|
205
|
+
|
206
|
+
# Create a form encoded hash for this object.
|
207
|
+
if obj.nil?
|
208
|
+
nil
|
209
|
+
elsif obj.instance_of? Array
|
210
|
+
if formatting == 'indexed'
|
211
|
+
obj.each_with_index do |value, index|
|
212
|
+
retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
|
213
|
+
index.to_s + ']'))
|
214
|
+
end
|
215
|
+
elsif serializable_types.map { |x| obj[0].is_a? x }.any?
|
216
|
+
obj.each do |value|
|
217
|
+
abc = if formatting == 'unindexed'
|
218
|
+
APIHelper.form_encode(value, instance_name + '[]',
|
219
|
+
formatting: formatting)
|
220
|
+
else
|
221
|
+
APIHelper.form_encode(value, instance_name,
|
222
|
+
formatting: formatting)
|
223
|
+
end
|
224
|
+
retval = APIHelper.custom_merge(retval, abc)
|
225
|
+
# print retval
|
226
|
+
end
|
227
|
+
else
|
228
|
+
obj.each_with_index do |value, index|
|
229
|
+
retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
|
230
|
+
index.to_s + ']', formatting: formatting))
|
231
|
+
end
|
232
|
+
end
|
233
|
+
elsif obj.instance_of? Hash
|
234
|
+
obj.each do |key, value|
|
235
|
+
retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
|
236
|
+
key + ']', formatting: formatting))
|
237
|
+
end
|
238
|
+
else
|
239
|
+
retval[instance_name] = obj
|
240
|
+
end
|
241
|
+
retval
|
242
|
+
end
|
243
|
+
|
244
|
+
# Safely converts a string into an rfc3339 DateTime object
|
245
|
+
# @param [String] The datetime string
|
246
|
+
# @return [DateTime] A DateTime object of rfc3339 format
|
247
|
+
def self.rfc3339(date_time)
|
248
|
+
# missing timezone information
|
249
|
+
if date_time.end_with?('Z') || date_time.index('+')
|
250
|
+
DateTime.rfc3339(date_time)
|
251
|
+
else
|
252
|
+
DateTime.rfc3339(date_time + 'Z')
|
253
|
+
end
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
# Extend types to support to_bool.
|
259
|
+
module ToBoolean
|
260
|
+
def to_bool
|
261
|
+
return true if self == true || to_s.strip =~ /^(true|yes|y|1)$/i
|
262
|
+
false
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
# Extend NilClass type to support to_bool.
|
267
|
+
class NilClass; include ToBoolean; end
|
268
|
+
# Extend TrueClass type to support to_bool.
|
269
|
+
class TrueClass; include ToBoolean; end
|
270
|
+
# Extend FalseClass type to support to_bool.
|
271
|
+
class FalseClass; include ToBoolean; end
|
272
|
+
# Extend Numeric type to support to_bool.
|
273
|
+
class Numeric; include ToBoolean; end
|
274
|
+
# Extend String type to support to_bool.
|
275
|
+
class String; include ToBoolean; end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# calculator_task client class.
|
8
|
+
class CalculatorTaskClient
|
9
|
+
# Singleton access to simple_calculator controller.
|
10
|
+
# @return [SimpleCalculatorController] Returns the controller instance.
|
11
|
+
def simple_calculator
|
12
|
+
SimpleCalculatorController.instance
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns the configuration class for easy access.
|
16
|
+
# @return [Configuration] Returns the actual configuration class.
|
17
|
+
def config
|
18
|
+
Configuration
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
# CohesityManagementSdk
|
7
|
+
module CalculatorTask
|
8
|
+
# All configuration including auth info and base URI for the API access
|
9
|
+
# are configured in this class.
|
10
|
+
class Configuration
|
11
|
+
# The base Uri for API calls
|
12
|
+
@base_uri = 'http://examples.apimatic.io/apps/calculator'
|
13
|
+
|
14
|
+
# The attribute accessors for public properties.
|
15
|
+
class << self
|
16
|
+
attr_accessor :array_serialization
|
17
|
+
attr_accessor :base_uri
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# Base controller.
|
8
|
+
class BaseController
|
9
|
+
attr_accessor :http_client, :http_call_back
|
10
|
+
|
11
|
+
def initialize(http_client: nil, http_call_back: nil)
|
12
|
+
@http_client = http_client || FaradayClient.new
|
13
|
+
@http_call_back = http_call_back
|
14
|
+
|
15
|
+
@global_headers = {
|
16
|
+
'user-agent' => 'APIMATIC 2.0'
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_parameters(args)
|
21
|
+
args.each do |_name, value|
|
22
|
+
if value.nil?
|
23
|
+
raise ArgumentError, "Required parameter #{_name} cannot be nil."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute_request(request, binary: false)
|
29
|
+
@http_call_back.on_before_request(request) if @http_call_back
|
30
|
+
|
31
|
+
APIHelper.clean_hash(request.headers)
|
32
|
+
request.headers = @global_headers.clone.merge(request.headers)
|
33
|
+
|
34
|
+
response = if binary
|
35
|
+
@http_client.execute_as_binary(request)
|
36
|
+
else
|
37
|
+
@http_client.execute_as_string(request)
|
38
|
+
end
|
39
|
+
context = HttpContext.new(request, response)
|
40
|
+
|
41
|
+
@http_call_back.on_after_response(context) if @http_call_back
|
42
|
+
|
43
|
+
context
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_response(context)
|
47
|
+
raise APIException.new 'HTTP Response Not OK', context unless
|
48
|
+
context.response.status_code.between?(200, 208) # [200,208] = HTTP OK
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# SimpleCalculatorController
|
8
|
+
class SimpleCalculatorController < BaseController
|
9
|
+
@instance = SimpleCalculatorController.new
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :instance
|
13
|
+
end
|
14
|
+
|
15
|
+
def instance
|
16
|
+
self.class.instance
|
17
|
+
end
|
18
|
+
|
19
|
+
# Endpoint Calculate
|
20
|
+
# @param [OperationTypeEnum] operation Required parameter: the operation to
|
21
|
+
# apply
|
22
|
+
# @param [Float] x Required parameter: LHS
|
23
|
+
# @param [Float] y Required parameter: RHS
|
24
|
+
# @return Float response from the API call
|
25
|
+
def get_calculate(operation,
|
26
|
+
x,
|
27
|
+
y)
|
28
|
+
# Prepare query url.
|
29
|
+
_path_url = '/{operation}'
|
30
|
+
_path_url = APIHelper.append_url_with_template_parameters(
|
31
|
+
_path_url,
|
32
|
+
'operation' => operation
|
33
|
+
)
|
34
|
+
_query_builder = Configuration.base_uri.dup
|
35
|
+
_query_builder << _path_url
|
36
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
37
|
+
_query_builder,
|
38
|
+
{
|
39
|
+
'x' => x,
|
40
|
+
'y' => y
|
41
|
+
},
|
42
|
+
array_serialization: Configuration.array_serialization
|
43
|
+
)
|
44
|
+
_query_url = APIHelper.clean_url _query_builder
|
45
|
+
# Prepare and execute HttpRequest.
|
46
|
+
_request = @http_client.get(
|
47
|
+
_query_url
|
48
|
+
)
|
49
|
+
_context = execute_request(_request)
|
50
|
+
validate_response(_context)
|
51
|
+
# Return appropriate response type.
|
52
|
+
_context.response.raw_body.to_f
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# Class for exceptions when there is a network error, status code error, etc.
|
8
|
+
class APIException < StandardError
|
9
|
+
attr_reader :context, :response_code
|
10
|
+
|
11
|
+
# The constructor.
|
12
|
+
# @param [String] The reason for raising an exception.
|
13
|
+
# @param [HttpContext] The HttpContext of the API call.
|
14
|
+
def initialize(reason, context)
|
15
|
+
super(reason)
|
16
|
+
@context = context
|
17
|
+
@response_code = context.response.status_code
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'faraday/http_cache'
|
7
|
+
require 'faraday_middleware'
|
8
|
+
|
9
|
+
module CalculatorTask
|
10
|
+
# An implementation of HttpClient.
|
11
|
+
class FaradayClient < HttpClient
|
12
|
+
# The constructor.
|
13
|
+
def initialize(timeout: nil, cache: false,
|
14
|
+
max_retries: nil, retry_interval: nil)
|
15
|
+
@connection = Faraday.new do |faraday|
|
16
|
+
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
17
|
+
faraday.use FaradayMiddleware::FollowRedirects
|
18
|
+
faraday.request :multipart
|
19
|
+
faraday.request :url_encoded
|
20
|
+
faraday.ssl[:ca_file] = Certifi.where
|
21
|
+
faraday.request :retry, max: max_retries, interval: if max_retries &&
|
22
|
+
retry_interval
|
23
|
+
retry_interval
|
24
|
+
end
|
25
|
+
faraday.adapter Faraday.default_adapter
|
26
|
+
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
27
|
+
faraday.options[:open_timeout] = timeout if timeout
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Method overridden from HttpClient.
|
32
|
+
def execute_as_string(http_request)
|
33
|
+
response = @connection.send(
|
34
|
+
http_request.http_method.downcase,
|
35
|
+
http_request.query_url
|
36
|
+
) do |request|
|
37
|
+
request.headers = http_request.headers
|
38
|
+
unless http_request.parameters.empty?
|
39
|
+
request.body = http_request.parameters
|
40
|
+
end
|
41
|
+
end
|
42
|
+
convert_response(response)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Method overridden from HttpClient.
|
46
|
+
def execute_as_binary(http_request)
|
47
|
+
response = @connection.send(
|
48
|
+
http_request.http_method.downcase,
|
49
|
+
http_request.query_url
|
50
|
+
) do |request|
|
51
|
+
request.headers = http_request.headers
|
52
|
+
unless http_request.parameters.empty?
|
53
|
+
request.body = http_request.parameters
|
54
|
+
end
|
55
|
+
end
|
56
|
+
convert_response(response)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Method overridden from HttpClient.
|
60
|
+
def convert_response(response)
|
61
|
+
HttpResponse.new(response.status, response.headers, response.body)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# HttpCallBack allows defining callables for pre and post API calls.
|
8
|
+
class HttpCallBack
|
9
|
+
# A controller will call this method before making an HTTP Request.
|
10
|
+
# @param [HttpRequest] The HttpRequest object which the HttpClient
|
11
|
+
# will execute.
|
12
|
+
def on_before_request(_http_request)
|
13
|
+
raise NotImplementedError, 'This method needs
|
14
|
+
to be implemented in a child class.'
|
15
|
+
end
|
16
|
+
|
17
|
+
# A controller will call this method after making an HTTP Request.
|
18
|
+
# @param [HttpContext] The HttpContext of the API call.
|
19
|
+
def on_after_response(_http_context)
|
20
|
+
raise NotImplementedError, 'This method needs
|
21
|
+
to be implemented in a child class.'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# An interface for the methods that an HTTP Client must implement.
|
8
|
+
#
|
9
|
+
# This class should not be instantiated but should be used as a base class
|
10
|
+
# for HTTP Client classes.
|
11
|
+
class HttpClient
|
12
|
+
# Execute an HttpRequest when the response is expected to be a string.
|
13
|
+
# @param [HttpRequest] The HttpRequest to be executed.
|
14
|
+
def execute_as_string(_http_request)
|
15
|
+
raise NotImplementedError, 'This method needs
|
16
|
+
to be implemented in a child class.'
|
17
|
+
end
|
18
|
+
|
19
|
+
# Execute an HttpRequest when the response is expected to be binary.
|
20
|
+
# @param [HttpRequest] The HttpRequest to be executed.
|
21
|
+
def execute_as_binary(_http_request)
|
22
|
+
raise NotImplementedError, 'This method needs
|
23
|
+
to be implemented in a child class.'
|
24
|
+
end
|
25
|
+
|
26
|
+
# Converts the HTTP Response from the client to an HttpResponse object.
|
27
|
+
# @param [Dynamic] The response object received from the client.
|
28
|
+
def convert_response(_response)
|
29
|
+
raise NotImplementedError, 'This method needs
|
30
|
+
to be implemented in a child class.'
|
31
|
+
end
|
32
|
+
|
33
|
+
# Get a GET HttpRequest object.
|
34
|
+
# @param [String] The URL to send the request to.
|
35
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
36
|
+
def get(query_url,
|
37
|
+
headers: {})
|
38
|
+
HttpRequest.new(HttpMethodEnum::GET,
|
39
|
+
query_url,
|
40
|
+
headers: headers)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Get a HEAD HttpRequest object.
|
44
|
+
# @param [String] The URL to send the request to.
|
45
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
46
|
+
def head(query_url,
|
47
|
+
headers: {})
|
48
|
+
HttpRequest.new(HttpMethodEnum::HEAD,
|
49
|
+
query_url,
|
50
|
+
headers: headers)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Get a POST HttpRequest object.
|
54
|
+
# @param [String] The URL to send the request to.
|
55
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
56
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
57
|
+
def post(query_url,
|
58
|
+
headers: {},
|
59
|
+
parameters: {})
|
60
|
+
HttpRequest.new(HttpMethodEnum::POST,
|
61
|
+
query_url,
|
62
|
+
headers: headers,
|
63
|
+
parameters: parameters)
|
64
|
+
end
|
65
|
+
|
66
|
+
# Get a PUT HttpRequest object.
|
67
|
+
# @param [String] The URL to send the request to.
|
68
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
69
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
70
|
+
def put(query_url,
|
71
|
+
headers: {},
|
72
|
+
parameters: {})
|
73
|
+
HttpRequest.new(HttpMethodEnum::PUT,
|
74
|
+
query_url,
|
75
|
+
headers: headers,
|
76
|
+
parameters: parameters)
|
77
|
+
end
|
78
|
+
|
79
|
+
# Get a PATCH HttpRequest object.
|
80
|
+
# @param [String] The URL to send the request to.
|
81
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
82
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
83
|
+
def patch(query_url,
|
84
|
+
headers: {},
|
85
|
+
parameters: {})
|
86
|
+
HttpRequest.new(HttpMethodEnum::PATCH,
|
87
|
+
query_url,
|
88
|
+
headers: headers,
|
89
|
+
parameters: parameters)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Get a DELETE HttpRequest object.
|
93
|
+
# @param [String] The URL to send the request to.
|
94
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
95
|
+
def delete(query_url,
|
96
|
+
headers: {},
|
97
|
+
parameters: {})
|
98
|
+
HttpRequest.new(HttpMethodEnum::DELETE,
|
99
|
+
query_url,
|
100
|
+
headers: headers,
|
101
|
+
parameters: parameters)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# Represents an Http call in context.
|
8
|
+
class HttpContext
|
9
|
+
attr_accessor :request, :response
|
10
|
+
|
11
|
+
# The constructor.
|
12
|
+
# @param [HttpRequest] An HttpRequest object representing the HTTP request.
|
13
|
+
# @param [HttpResponse] An HttpResponse object representing the HTTP
|
14
|
+
# response.
|
15
|
+
def initialize(request, response)
|
16
|
+
@request = request
|
17
|
+
@response = response
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# HTTP Methods Enumeration.
|
8
|
+
class HttpMethodEnum
|
9
|
+
HTTPMETHODENUM = [GET = 'GET'.freeze, POST = 'POST'.freeze,
|
10
|
+
PUT = 'PUT'.freeze, PATCH = 'PATCH'.freeze,
|
11
|
+
DELETE = 'DELETE'.freeze, HEAD = 'HEAD'.freeze].freeze
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# Represents a single Http Request.
|
8
|
+
class HttpRequest
|
9
|
+
attr_accessor :http_method, :query_url, :headers,
|
10
|
+
:parameters, :username, :password
|
11
|
+
|
12
|
+
# The constructor.
|
13
|
+
# @param [HttpMethodEnum] The HTTP method.
|
14
|
+
# @param [String] The URL to send the request to.
|
15
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
16
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
17
|
+
def initialize(http_method,
|
18
|
+
query_url,
|
19
|
+
headers: {},
|
20
|
+
parameters: {})
|
21
|
+
@http_method = http_method
|
22
|
+
@query_url = query_url
|
23
|
+
@headers = headers
|
24
|
+
@parameters = parameters
|
25
|
+
end
|
26
|
+
|
27
|
+
# Add a header to the HttpRequest.
|
28
|
+
# @param [String] The name of the header.
|
29
|
+
# @param [String] The value of the header.
|
30
|
+
def add_header(name, value)
|
31
|
+
@headers[name] = value
|
32
|
+
end
|
33
|
+
|
34
|
+
# Add a parameter to the HttpRequest.
|
35
|
+
# @param [String] The name of the parameter.
|
36
|
+
# @param [String] The value of the parameter.
|
37
|
+
def add_parameter(name, value)
|
38
|
+
@parameters[name] = value
|
39
|
+
end
|
40
|
+
|
41
|
+
# Add a query parameter to the HttpRequest.
|
42
|
+
# @param [String] The name of the query parameter.
|
43
|
+
# @param [String] The value of the query parameter.
|
44
|
+
def add_query_parameter(name, value)
|
45
|
+
@query_url = APIHelper.append_url_with_query_parameters(@query_url,
|
46
|
+
name => value)
|
47
|
+
@query_url = APIHelper.clean_url(@query_url)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# Http response received.
|
8
|
+
class HttpResponse
|
9
|
+
attr_accessor :status_code, :headers, :raw_body
|
10
|
+
|
11
|
+
# The constructor
|
12
|
+
# @param [Integer] The status code returned by the server.
|
13
|
+
# @param [Hash] The headers sent by the server in the response.
|
14
|
+
# @param [String] The raw body of the response.
|
15
|
+
def initialize(status_code,
|
16
|
+
headers,
|
17
|
+
raw_body)
|
18
|
+
@status_code = status_code
|
19
|
+
@headers = headers
|
20
|
+
@raw_body = raw_body
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# Base model.
|
8
|
+
class BaseModel
|
9
|
+
# Returns a Hash representation of the current object.
|
10
|
+
def to_hash
|
11
|
+
hash = {}
|
12
|
+
instance_variables.each do |name|
|
13
|
+
value = instance_variable_get(name)
|
14
|
+
name = name[1..-1]
|
15
|
+
key = self.class.names.key?(name) ? self.class.names[name] : name
|
16
|
+
if value.instance_of? Array
|
17
|
+
hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
18
|
+
elsif value.instance_of? Hash
|
19
|
+
hash[key] = {}
|
20
|
+
value.each do |k, v|
|
21
|
+
hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
|
22
|
+
end
|
23
|
+
else
|
24
|
+
hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
|
25
|
+
end
|
26
|
+
end
|
27
|
+
hash
|
28
|
+
end
|
29
|
+
|
30
|
+
# Returns a JSON representation of the curent object.
|
31
|
+
def to_json(options = {})
|
32
|
+
hash = to_hash
|
33
|
+
hash.to_json(options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# calculator_task
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0 (
|
4
|
+
# https://apimatic.io ).
|
5
|
+
|
6
|
+
module CalculatorTask
|
7
|
+
# Calculator Operation
|
8
|
+
class OperationTypeEnum
|
9
|
+
OPERATION_TYPE_ENUM = [
|
10
|
+
# Addition
|
11
|
+
ADD = 'SUM'.freeze,
|
12
|
+
|
13
|
+
# Subtraction
|
14
|
+
SUBTRACT = 'SUBTRACT'.freeze,
|
15
|
+
|
16
|
+
# Multiplication
|
17
|
+
MULTIPLY = 'MULTIPLY'.freeze,
|
18
|
+
|
19
|
+
# Divide
|
20
|
+
DIVIDE = 'DIVIDE'.freeze
|
21
|
+
].freeze
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Calculator_Task
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- APIMatic SDK Generator
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-12-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logging
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.10'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.13.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.13.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.1'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 3.1.5
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '3.1'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 3.1.5
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: certifi
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '2016'
|
82
|
+
type: :runtime
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '2016'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: faraday-http-cache
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.2'
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 1.2.2
|
99
|
+
type: :runtime
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '1.2'
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 1.2.2
|
109
|
+
description: Simple Calculator API.
|
110
|
+
email: support@apimatic.io
|
111
|
+
executables: []
|
112
|
+
extensions: []
|
113
|
+
extra_rdoc_files: []
|
114
|
+
files:
|
115
|
+
- LICENSE
|
116
|
+
- README.md
|
117
|
+
- lib/calculator_task.rb
|
118
|
+
- lib/calculator_task/api_helper.rb
|
119
|
+
- lib/calculator_task/calculator_task_client.rb
|
120
|
+
- lib/calculator_task/configuration.rb
|
121
|
+
- lib/calculator_task/controllers/base_controller.rb
|
122
|
+
- lib/calculator_task/controllers/simple_calculator_controller.rb
|
123
|
+
- lib/calculator_task/exceptions/api_exception.rb
|
124
|
+
- lib/calculator_task/http/faraday_client.rb
|
125
|
+
- lib/calculator_task/http/http_call_back.rb
|
126
|
+
- lib/calculator_task/http/http_client.rb
|
127
|
+
- lib/calculator_task/http/http_context.rb
|
128
|
+
- lib/calculator_task/http/http_method_enum.rb
|
129
|
+
- lib/calculator_task/http/http_request.rb
|
130
|
+
- lib/calculator_task/http/http_response.rb
|
131
|
+
- lib/calculator_task/models/base_model.rb
|
132
|
+
- lib/calculator_task/models/operation_type_enum.rb
|
133
|
+
homepage: https://apimatic.io
|
134
|
+
licenses:
|
135
|
+
- MIT
|
136
|
+
metadata: {}
|
137
|
+
post_install_message:
|
138
|
+
rdoc_options: []
|
139
|
+
require_paths:
|
140
|
+
- lib
|
141
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '2.0'
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
requirements: []
|
152
|
+
rubyforge_project:
|
153
|
+
rubygems_version: 2.7.6
|
154
|
+
signing_key:
|
155
|
+
specification_version: 4
|
156
|
+
summary: calculator_task
|
157
|
+
test_files: []
|