apimaticcalculatortest1 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 12aaaa416a7b57f7caab350b4c3be4ad0debb92f98c53e2e9075e347b13d4d23
4
+ data.tar.gz: 0c53691827b3ed1f2b6801c2d5a33757c9e4c42a104ca73490c1b0d6d3714ccb
5
+ SHA512:
6
+ metadata.gz: fedf6a7a23ee1e2907a7ea329caba369b6c14fcc574d29e02c0fecd141909cae3eb6694dc6f2c3a93545fa110fdf6025667e024c87ca507783e77bb2174f82f4
7
+ data.tar.gz: 6e9a9b247c2d45b3ebf22607138d5203b22b527660f896657ce524a3501e6f17a2d49de3f2b4cc91cdf38affbe642e9f1c000baf25ae366578c9918a1906c67b
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 - 2020 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,186 @@
1
+ # Getting Started with APIMATIC Calculator
2
+
3
+ ## Getting Started
4
+
5
+ ### Introduction
6
+
7
+ Simple calculator API hosted on APIMATIC
8
+
9
+ ### Install the Package
10
+
11
+ Install the gem from the command line:
12
+
13
+ ```ruby
14
+ gem install apimaticcalculatortest1 -v 1.0.0
15
+ ```
16
+
17
+ Or add the gem to your Gemfile and run `bundle`:
18
+
19
+ ```ruby
20
+ gem 'apimaticcalculatortest1', '1.0.0'
21
+ ```
22
+
23
+ For additional gem details, see the [RubyGems page for the apimaticcalculatortest1 gem](https://rubygems.org/gems/apimaticcalculatortest1/versions/1.0.0).
24
+
25
+ ### Initialize the API Client
26
+
27
+ The following parameters are configurable for the API Client:
28
+
29
+ | Parameter | Type | Description |
30
+ | --- | --- | --- |
31
+ | `environment` | Environment | The API environment. <br> **Default: `Environment.PRODUCTION`** |
32
+ | `timeout` | `Float` | The value to use for connection timeout. <br> **Default: 60** |
33
+ | `max_retries` | `Integer` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
34
+ | `retry_interval` | `Float` | Pause in seconds between retries. <br> **Default: 1** |
35
+ | `backoff_factor` | `Float` | The amount to multiply each successive retry's interval amount by in order to provide backoff. <br> **Default: 1** |
36
+
37
+ The API client can be initialized as follows:
38
+
39
+ ```ruby
40
+ client = ApimaticCalculator::Client.new(
41
+ environment: Environment::PRODUCTION,
42
+ )
43
+ ```
44
+
45
+ ### Test the SDK
46
+
47
+ To run the tests, navigate to the root directory of the SDK in your terminal and execute the following command:
48
+
49
+ ```
50
+ rake
51
+ ```
52
+
53
+ ## Client Class Documentation
54
+
55
+ ### APIMATIC Calculator Client
56
+
57
+ The gateway for the SDK. This class acts as a factory for the Controllers and also holds the configuration of the SDK.
58
+
59
+ ### Controllers
60
+
61
+ | Name | Description |
62
+ | --- | --- |
63
+ | simple_calculator | Gets SimpleCalculatorController |
64
+
65
+ ## API Reference
66
+
67
+ ### List of APIs
68
+
69
+ * [Simple Calculator](#simple-calculator)
70
+
71
+ ### Simple Calculator
72
+
73
+ #### Overview
74
+
75
+ ##### Get instance
76
+
77
+ An instance of the `SimpleCalculatorController` class can be accessed from the API Client.
78
+
79
+ ```
80
+ simple_calculator_controller = client.simple_calculator
81
+ ```
82
+
83
+ #### Get Calculate
84
+
85
+ Calculates the expression using the specified operation.
86
+
87
+ :information_source: **Note** This endpoint does not require authentication.
88
+
89
+ ```ruby
90
+ def get_calculate(options = {})
91
+ ```
92
+
93
+ ##### Parameters
94
+
95
+ | Parameter | Type | Tags | Description |
96
+ | --- | --- | --- | --- |
97
+ | `operation` | [`OperationTypeEnum`](#operation-type) | Template, Required | The operator to apply on the variables |
98
+ | `x` | `Float` | Query, Required | The LHS value |
99
+ | `y` | `Float` | Query, Required | The RHS value |
100
+
101
+ ##### Response Type
102
+
103
+ `Float`
104
+
105
+ ##### Example Usage
106
+
107
+ ```ruby
108
+ collect = {}
109
+
110
+ operation = OperationTypeEnum::MULTIPLY
111
+ collect['operation'] = operation;
112
+
113
+ x = 222.14
114
+ collect['x'] = x;
115
+
116
+ y = 165.14
117
+ collect['y'] = y;
118
+
119
+ result = simple_calculator_controller.get_calculate(collect)
120
+ ```
121
+
122
+ ## Model Reference
123
+
124
+ ### Enumerations
125
+
126
+ * [Operation Type](#operation-type)
127
+
128
+ #### Operation Type
129
+
130
+ Possible operators are sum, subtract, multiply, divide
131
+
132
+ ##### Class Name
133
+
134
+ `OperationTypeEnum`
135
+
136
+ ##### Fields
137
+
138
+ | Name | Description |
139
+ | --- | --- |
140
+ | `SUM` | Represents the sum operator |
141
+ | `SUBTRACT` | Represents the subtract operator |
142
+ | `MULTIPLY` | Represents the multiply operator |
143
+ | `DIVIDE` | Represents the divide operator |
144
+
145
+ ## Utility Classes Documentation
146
+
147
+ ### ApiHelper Class
148
+
149
+ API utility class.
150
+
151
+ ### Methods
152
+
153
+ | Name | Return Type | Description |
154
+ | --- | --- | --- |
155
+ | json_deserialize | Hash | Deserializes a JSON string to a Ruby Hash. |
156
+ | rfc3339 | DateTime | Safely converts a string into an RFC3339 DateTime object. |
157
+
158
+ ## Common Code Documentation
159
+
160
+ ### HttpResponse
161
+
162
+ Http response received.
163
+
164
+ #### Properties
165
+
166
+ | Name | Type | Description |
167
+ | --- | --- | --- |
168
+ | status_code | Integer | The status code returned by the server. |
169
+ | reason_phrase | String | The reason phrase returned by the server. |
170
+ | headers | Hash | Response headers. |
171
+ | raw_body | String | Response body. |
172
+ | request | HttpRequest | The request that resulted in this response. |
173
+
174
+ ### HttpRequest
175
+
176
+ Represents a single Http Request.
177
+
178
+ #### Properties
179
+
180
+ | Name | Type | Tag | Description |
181
+ | --- | --- | --- | --- |
182
+ | http_method | HttpMethodEnum | | The HTTP method of the request. |
183
+ | query_url | String | | The endpoint URL for the API request. |
184
+ | headers | Hash | Optional | Request headers. |
185
+ | parameters | Hash | Optional | Request body. |
186
+
@@ -0,0 +1,38 @@
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 'faraday'
9
+ require 'certifi'
10
+ require 'logging'
11
+
12
+ require_relative 'apimatic_calculator/api_helper.rb'
13
+ require_relative 'apimatic_calculator/client.rb'
14
+
15
+ # Utilities
16
+ require_relative 'apimatic_calculator/utilities/file_wrapper.rb'
17
+
18
+ # Http
19
+ require_relative 'apimatic_calculator/http/http_call_back.rb'
20
+ require_relative 'apimatic_calculator/http/http_client.rb'
21
+ require_relative 'apimatic_calculator/http/faraday_client.rb'
22
+ require_relative 'apimatic_calculator/http/http_method_enum.rb'
23
+ require_relative 'apimatic_calculator/http/http_request.rb'
24
+ require_relative 'apimatic_calculator/http/http_response.rb'
25
+
26
+ # Models
27
+ require_relative 'apimatic_calculator/models/base_model.rb'
28
+ require_relative 'apimatic_calculator/models/operation_type_enum.rb'
29
+
30
+ # Exceptions
31
+ require_relative 'apimatic_calculator/exceptions/api_exception.rb'
32
+
33
+ require_relative 'apimatic_calculator/configuration.rb'
34
+
35
+ # Controllers
36
+ require_relative 'apimatic_calculator/controllers/base_controller.rb'
37
+ require_relative 'apimatic_calculator/controllers/simple_calculator' \
38
+ '_controller.rb'
@@ -0,0 +1,289 @@
1
+ # apimatic_calculator
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module ApimaticCalculator
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
+ parameters.each do |key, val|
45
+ if val.nil?
46
+ replace_value = ''
47
+ elsif val['value'].instance_of? Array
48
+ if val['encode'] == true
49
+ val['value'].map! { |element| CGI.escape(element.to_s) }
50
+ else
51
+ val['value'].map!(&:to_s)
52
+ end
53
+ replace_value = val['value'].join('/')
54
+ else
55
+ replace_value = if val['encode'] == true
56
+ CGI.escape(val['value'].to_s)
57
+ else
58
+ val['value'].to_s
59
+ end
60
+ end
61
+
62
+ # Find the template parameter and replace it with its value.
63
+ query_builder = query_builder.gsub('{' + key.to_s + '}', replace_value)
64
+ end
65
+ query_builder
66
+ end
67
+
68
+ # Appends the given set of parameters to the given query string.
69
+ # @param [String] The query string builder to add the query parameters to.
70
+ # @param [Hash] The parameters to append.
71
+ def self.append_url_with_query_parameters(query_builder, parameters)
72
+ # Perform parameter validation.
73
+ unless query_builder.instance_of? String
74
+ raise ArgumentError, 'Given value for parameter \"query_builder\"
75
+ is invalid.'
76
+ end
77
+
78
+ # Return if there are no parameters to replace.
79
+ return query_builder if parameters.nil?
80
+
81
+ array_serialization = 'indexed'
82
+
83
+ parameters.each do |key, value|
84
+ seperator = query_builder.include?('?') ? '&' : '?'
85
+ unless value.nil?
86
+ if value.instance_of? Array
87
+ value.compact!
88
+ query_builder += if array_serialization == 'csv'
89
+ "#{seperator}#{key}=#{value.map do |element|
90
+ CGI.escape(element.to_s)
91
+ end.join(',')}"
92
+ elsif array_serialization == 'psv'
93
+ "#{seperator}#{key}=#{value.map do |element|
94
+ CGI.escape(element.to_s)
95
+ end.join('|')}"
96
+ elsif array_serialization == 'tsv'
97
+ "#{seperator}#{key}=#{value.map do |element|
98
+ CGI.escape(element.to_s)
99
+ end.join("\t")}"
100
+ else
101
+ "#{seperator}#{APIHelper.serialize_array(
102
+ key, value, formatting: array_serialization
103
+ ).map { |k, v| "#{k}=#{CGI.escape(v.to_s)}" }
104
+ .join('&')}"
105
+ end
106
+ else
107
+ query_builder += "#{seperator}#{key}=#{CGI.escape(value.to_s)}"
108
+ end
109
+ end
110
+ end
111
+ query_builder
112
+ end
113
+
114
+ # Validates and processes the given Url.
115
+ # @param [String] The given Url to process.
116
+ # @return [String] Pre-processed Url as string.
117
+ def self.clean_url(url)
118
+ # Perform parameter validation.
119
+ raise ArgumentError, 'Invalid Url.' unless url.instance_of? String
120
+
121
+ # Ensure that the urls are absolute.
122
+ matches = url.match(%r{^(https?:\/\/[^\/]+)})
123
+ raise ArgumentError, 'Invalid Url format.' if matches.nil?
124
+
125
+ # Get the http protocol match.
126
+ protocol = matches[1]
127
+
128
+ # Check if parameters exist.
129
+ index = url.index('?')
130
+
131
+ # Remove redundant forward slashes.
132
+ query = url[protocol.length...(!index.nil? ? index : url.length)]
133
+ query.gsub!(%r{\/\/+}, '/')
134
+
135
+ # Get the parameters.
136
+ parameters = !index.nil? ? url[url.index('?')...url.length] : ''
137
+
138
+ # Return processed url.
139
+ protocol + query + parameters
140
+ end
141
+
142
+ # Parses JSON string.
143
+ # @param [String] A JSON string.
144
+ def self.json_deserialize(json)
145
+ return JSON.parse(json)
146
+ rescue StandardError
147
+ raise TypeError, 'Server responded with invalid JSON.'
148
+ end
149
+
150
+ # Removes elements with empty values from a hash.
151
+ # @param [Hash] The hash to clean.
152
+ def self.clean_hash(hash)
153
+ hash.delete_if { |_key, value| value.to_s.strip.empty? }
154
+ end
155
+
156
+ # Form encodes a hash of parameters.
157
+ # @param [Hash] The hash of parameters to encode.
158
+ # @return [Hash] A hash with the same parameters form encoded.
159
+ def self.form_encode_parameters(form_parameters)
160
+ array_serialization = 'indexed'
161
+ encoded = {}
162
+ form_parameters.each do |key, value|
163
+ encoded.merge!(APIHelper.form_encode(value, key, formatting:
164
+ array_serialization))
165
+ end
166
+ encoded
167
+ end
168
+
169
+ def self.custom_merge(a, b)
170
+ x = {}
171
+ a.each do |key, value_a|
172
+ b.each do |k, value_b|
173
+ next unless key == k
174
+ x[k] = []
175
+ if value_a.instance_of? Array
176
+ value_a.each do |v|
177
+ x[k].push(v)
178
+ end
179
+ else
180
+ x[k].push(value_a)
181
+ end
182
+ if value_b.instance_of? Array
183
+ value_b.each do |v|
184
+ x[k].push(v)
185
+ end
186
+ else
187
+ x[k].push(value_b)
188
+ end
189
+ a.delete(k)
190
+ b.delete(k)
191
+ end
192
+ end
193
+ x.merge!(a)
194
+ x.merge!(b)
195
+ x
196
+ end
197
+
198
+ # Form encodes an object.
199
+ # @param [Dynamic] An object to form encode.
200
+ # @param [String] The name of the object.
201
+ # @return [Hash] A form encoded representation of the object in the form
202
+ # of a hash.
203
+ def self.form_encode(obj, instance_name, formatting: 'indexed')
204
+ retval = {}
205
+
206
+ serializable_types = [String, Numeric, TrueClass,
207
+ FalseClass, Date, DateTime]
208
+
209
+ # If this is a structure, resolve it's field names.
210
+ obj = obj.to_hash if obj.is_a? BaseModel
211
+
212
+ # Create a form encoded hash for this object.
213
+ if obj.nil?
214
+ nil
215
+ elsif obj.instance_of? Array
216
+ if formatting == 'indexed'
217
+ obj.each_with_index do |value, index|
218
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
219
+ index.to_s + ']'))
220
+ end
221
+ elsif serializable_types.map { |x| obj[0].is_a? x }.any?
222
+ obj.each do |value|
223
+ abc = if formatting == 'unindexed'
224
+ APIHelper.form_encode(value, instance_name + '[]',
225
+ formatting: formatting)
226
+ else
227
+ APIHelper.form_encode(value, instance_name,
228
+ formatting: formatting)
229
+ end
230
+ retval = APIHelper.custom_merge(retval, abc)
231
+ end
232
+ else
233
+ obj.each_with_index do |value, index|
234
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
235
+ index.to_s + ']', formatting: formatting))
236
+ end
237
+ end
238
+ elsif obj.instance_of? Hash
239
+ obj.each do |key, value|
240
+ retval.merge!(APIHelper.form_encode(value, instance_name + '[' +
241
+ key.to_s + ']', formatting: formatting))
242
+ end
243
+ elsif obj.instance_of? File
244
+ retval[instance_name] = UploadIO.new(
245
+ obj, 'application/octet-stream', File.basename(obj.path)
246
+ )
247
+ else
248
+ retval[instance_name] = obj
249
+ end
250
+ retval
251
+ end
252
+
253
+ # Retrieves a field from a Hash/Array based on an Array of keys/indexes
254
+ # @param [Hash, Array] The hash to extract data from
255
+ # @param [Array<String, Integer>] The keys/indexes to use
256
+ # @return [Object] The extracted value
257
+ def self.map_response(obj, keys)
258
+ val = obj
259
+ begin
260
+ keys.each do |key|
261
+ val = if val.is_a? Array
262
+ if key.to_i.to_s == key
263
+ val[key.to_i]
264
+ else
265
+ val = nil
266
+ end
267
+ else
268
+ val.fetch(key.to_sym)
269
+ end
270
+ end
271
+ rescue NoMethodError, TypeError, IndexError
272
+ val = nil
273
+ end
274
+ val
275
+ end
276
+
277
+ # Safely converts a string into an rfc3339 DateTime object
278
+ # @param [String] The datetime string
279
+ # @return [DateTime] A DateTime object of rfc3339 format
280
+ def self.rfc3339(date_time)
281
+ # missing timezone information
282
+ if date_time.end_with?('Z') || date_time.index('+')
283
+ DateTime.rfc3339(date_time)
284
+ else
285
+ DateTime.rfc3339(date_time + 'Z')
286
+ end
287
+ end
288
+ end
289
+ end