apimatic-testing-calculator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d56cd3c81f662e50f7de6075b95281519a80aef743334d82bdd67e59114f1b0d
4
+ data.tar.gz: bf6ee328846ab5ddd7a7f4ebed22d81309bc4957b56458d33002d013f03fab69
5
+ SHA512:
6
+ metadata.gz: 3546f22bc1ee68af0fff022cb4d385fc0cfa568aef7a8f6efb5ec90ecc2f984760809ac32f20550c0556b47fc63ed30836e26ca0da37743e3b89311e5c9f51d2
7
+ data.tar.gz: d0c93e843f3be421fc2c93948385ab6c6dcf53635ea8c7936e4241b1acb3af594ad9155531d6231c4befbac82d273f133a28337af26e4d1bc727830b4112677c
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
@@ -0,0 +1,135 @@
1
+ # Getting started
2
+
3
+ Calculator API built with APIMATIC
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 apimatic_testing_calculator.gemspec ``` to build the gem.
11
+ 3. Once built, the gem can be installed on the current work environment using ``` gem install apimatic_testing_calculator-1.0.0.gem ```
12
+
13
+ ![Building Gem](https://apidocs.io/illustration/ruby?step=buildSDK&workspaceFolder=MyCalculator-Ruby&workspaceName=MyCalculator-Ruby&projectName=apimatic_testing_calculator&gemName=apimatic_testing_calculator&gemVer=1.0.0)
14
+
15
+ ## How to Use
16
+
17
+ The following section explains how to use the ApimaticTestingCalculator 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=MyCalculator-Ruby&workspaceName=ApimaticTestingCalculator&projectName=apimatic_testing_calculator&gemName=apimatic_testing_calculator&gemVer=1.0.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=MyCalculator-Ruby&workspaceName=ApimaticTestingCalculator&projectName=apimatic_testing_calculator&gemName=apimatic_testing_calculator&gemVer=1.0.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=MyCalculator-Ruby&workspaceName=ApimaticTestingCalculator&projectName=apimatic_testing_calculator&gemName=apimatic_testing_calculator&gemVer=1.0.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 ApimaticTestingCalculator 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 'apimatic_testing_calculator', '~> 1.0.0' ```
38
+
39
+ ![Add references of the Gemfile](https://apidocs.io/illustration/ruby?step=addReference&workspaceFolder=MyCalculator-Ruby&workspaceName=ApimaticTestingCalculator&projectName=apimatic_testing_calculator&gemName=apimatic_testing_calculator&gemVer=1.0.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=MyCalculator-Ruby&workspaceName=ApimaticTestingCalculator&projectName=apimatic_testing_calculator&gemName=apimatic_testing_calculator&gemVer=1.0.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=MyCalculator-Ruby&workspaceName=ApimaticTestingCalculator&projectName=apimatic_testing_calculator&gemName=apimatic_testing_calculator&gemVer=1.0.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=MyCalculator-Ruby&workspaceName=ApimaticTestingCalculator&projectName=apimatic_testing_calculator&gemName=apimatic_testing_calculator&gemVer=1.0.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=MyCalculator-Ruby&workspaceName=ApimaticTestingCalculator&projectName=apimatic_testing_calculator&gemName=apimatic_testing_calculator&gemVer=1.0.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 = ApimaticTestingCalculator::ApimaticTestingCalculatorClient.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=MyCalculator-Ruby&workspaceName=ApimaticTestingCalculator&projectName=apimatic_testing_calculator&gemName=apimatic_testing_calculator&gemVer=1.0.0&initLine=client%2520%253D%2520ApimaticTestingCalculatorClient.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
+ > Calculates the result for the specified operation and variables.
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 operator to be applied on the provided variables. |
116
+ | x | ``` Required ``` ``` DefaultValue ``` | The LHS value |
117
+ | y | ``` Required ``` ``` DefaultValue ``` | The RHS value |
118
+
119
+
120
+ #### Example Usage
121
+
122
+ ```ruby
123
+ operation = ApimaticTestingCalculator::OperationTypeEnum::SUM
124
+ x = 20
125
+ y = 30
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,37 @@
1
+ # apimatic_testing_calculator
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v2.0 ( https://apimatic.io ).
5
+
6
+ require 'date'
7
+ require 'json'
8
+ require 'faraday'
9
+ require 'certifi'
10
+ require 'logging'
11
+
12
+ require_relative 'apimatic_testing_calculator/api_helper.rb'
13
+ require_relative 'apimatic_testing_calculator/apimatic_testing_calculator' \
14
+ '_client.rb'
15
+
16
+ # Http
17
+ require_relative 'apimatic_testing_calculator/http/http_call_back.rb'
18
+ require_relative 'apimatic_testing_calculator/http/http_client.rb'
19
+ require_relative 'apimatic_testing_calculator/http/http_method_enum.rb'
20
+ require_relative 'apimatic_testing_calculator/http/http_request.rb'
21
+ require_relative 'apimatic_testing_calculator/http/http_response.rb'
22
+ require_relative 'apimatic_testing_calculator/http/http_context.rb'
23
+ require_relative 'apimatic_testing_calculator/http/faraday_client.rb'
24
+
25
+ # Models
26
+ require_relative 'apimatic_testing_calculator/models/base_model.rb'
27
+ require_relative 'apimatic_testing_calculator/models/operation_type_enum.rb'
28
+
29
+ # Exceptions
30
+ require_relative 'apimatic_testing_calculator/exceptions/api_exception.rb'
31
+
32
+ require_relative 'apimatic_testing_calculator/configuration.rb'
33
+
34
+ # Controllers
35
+ require_relative 'apimatic_testing_calculator/controllers/base_controller.rb'
36
+ require_relative 'apimatic_testing_calculator/controllers/simple_calculator' \
37
+ '_controller.rb'
@@ -0,0 +1,275 @@
1
+ # apimatic_testing_calculator
2
+ #
3
+ # This file was automatically generated by
4
+ # APIMATIC v2.0 ( https://apimatic.io ).
5
+
6
+ module ApimaticTestingCalculator
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