calpack 7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ # calpack
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module Calpack
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
+ # calpack
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module Calpack
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
+ # calpack
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ module Calpack
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
+ end
23
+ end
@@ -0,0 +1,33 @@
1
+ # calpack
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require 'json'
7
+ require 'test/unit'
8
+ require 'calpack.rb'
9
+ require_relative '../test_helper.rb'
10
+ require_relative '../http_response_catcher.rb'
11
+
12
+ class ControllerTestBase < Test::Unit::TestCase
13
+ include Calpack
14
+
15
+ class << self
16
+ attr_accessor :controller
17
+ end
18
+
19
+ # Called only once for a test class before any test has executed.
20
+ def self.startup
21
+ @@api_client = CalpackClient.new
22
+ @@request_timeout = 30
23
+ @@assert_precision = 0.01
24
+
25
+
26
+ end
27
+
28
+ # Called once before every test case.
29
+ def setup
30
+ @response_catcher = HttpResponseCatcher.new
31
+ self.class.controller.http_call_back = @response_catcher
32
+ end
33
+ end
@@ -0,0 +1,33 @@
1
+ # calpack
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 self.startup
11
+ self.controller = @@api_client.simple_calculator
12
+ end
13
+
14
+ # Check if multiplication works
15
+ def test_multiply()
16
+ # Parameters for the API call
17
+ options = {}
18
+ options['operation'] = 'MULTIPLY'
19
+ options['x'] = 4
20
+ options['y'] = 5
21
+
22
+ # Perform the API call through the SDK function
23
+ result = self.class.controller.get_calculate(options)
24
+
25
+ # Test response code
26
+ assert_equal(@response_catcher.response.status_code, 200)
27
+
28
+ # Test whether the captured response is as we expected
29
+ assert_not_nil(result)
30
+ assert_equal('20', @response_catcher.response.raw_body)
31
+ end
32
+
33
+ end
@@ -0,0 +1,20 @@
1
+ # calpack
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+
7
+ # HttpResponseCatcher
8
+ class HttpResponseCatcher < Calpack::HttpCallBack
9
+ attr_accessor :response
10
+
11
+ def on_before_request(request) end
12
+
13
+ # Catching the response
14
+ def on_after_response(context)
15
+ @response = context.response
16
+ end
17
+ end
18
+
19
+
20
+
@@ -0,0 +1,99 @@
1
+ # calpack
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0 (
4
+ # https://apimatic.io ).
5
+
6
+ require 'tempfile'
7
+ require 'open-uri'
8
+ # TestHelper Class
9
+ class TestHelper
10
+ @cache = Hash.new
11
+
12
+ # Class method to compare the received headers with the expected headers.
13
+ # @param [Hash] A hash of expected headers (keys in lower case).
14
+ # @param [Hash] A hash of received headers.
15
+ # @param [Boolean, optional] A flag which determines if we allow
16
+ # extra headers.
17
+ def self.match_headers(expected_headers,
18
+ received_headers,
19
+ allow_extra: true)
20
+ return false if (received_headers.length < expected_headers.length) ||
21
+ ((allow_extra == false) &&
22
+ (received_headers.length > expected_headers.length))
23
+
24
+ received_headers = Hash[received_headers.map { |k, v| [k.to_s.downcase, v] }]
25
+ expected_headers.each do |e_key, e_value|
26
+ return false unless received_headers.key?(e_key)
27
+ return false if (e_value != nil) &&
28
+ (e_value != received_headers[e_key])
29
+ end
30
+
31
+ true
32
+ end
33
+
34
+ # Class method to compare the received body with the expected body.
35
+ # @param [Dynamic] The expected body.
36
+ # @param [Dynamic] The received body.
37
+ # @param [Boolean, optional] A flag which determines if we check values
38
+ # in dictionaries.
39
+ # @param [Boolean, optional] A flag which determines if we check the order
40
+ # of array elements.
41
+ # @param [Boolean, optional] A flag which determines if we check the count
42
+ # of array elements.
43
+ def self.match_body(expected_body,
44
+ received_body,
45
+ check_values: false,
46
+ check_order: false,
47
+ check_count: false)
48
+ if expected_body.instance_of? Hash
49
+ return false unless received_body.instance_of? Hash
50
+ for key in expected_body.keys
51
+ return false unless received_body.keys.include? key
52
+ if check_values or expected_body[key].instance_of? Hash
53
+ return false unless TestHelper.match_body(expected_body[key],
54
+ received_body[key],
55
+ check_values: check_values,
56
+ check_order: check_order,
57
+ check_count: check_count)
58
+ end
59
+ end
60
+ elsif expected_body.instance_of? Array
61
+ return False unless received_body.instance_of? Array
62
+ if check_count == true && (expected_body.length != received_body.length)
63
+ return false
64
+ else
65
+ previous_matches = Array.new
66
+ expected_body.each.with_index do |expected_element, i|
67
+ matches = (received_body.map.with_index do |received_element, j|
68
+ j if TestHelper.match_body(expected_element,
69
+ received_element,
70
+ check_values: check_values,
71
+ check_order: check_order,
72
+ check_count: check_count)
73
+ end).compact
74
+ return false if matches.length == 0
75
+ if check_order == true
76
+ return false if i != 0 && matches.map { |x| previous_matches.map { |y| y > x }.all? }.all?
77
+ previous_matches = matches
78
+ end
79
+ end
80
+ end
81
+ elsif expected_body != received_body
82
+ return false
83
+ end
84
+ true
85
+ end
86
+
87
+ # Class method which takes a URL, downloads the file
88
+ # (if not already downloaded for this test session)
89
+ # and returns the path of the file.
90
+ # @param [String] The URL of the required file.
91
+ def self.get_file(url)
92
+ unless @cache.keys.include? url
93
+ @cache[url] = Tempfile.new('APIMatic')
94
+ @cache[url].binmode
95
+ @cache[url].write(open(url, { ssl_ca_cert: Certifi.where }).read)
96
+ end
97
+ @cache[url].path
98
+ end
99
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: calpack
3
+ version: !ruby/object:Gem::Version
4
+ version: '7.1'
5
+ platform: ruby
6
+ authors:
7
+ - APIMatic SDK Generator
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-28 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 hosted on APIMATIC
110
+ email: support@apimatic.io
111
+ executables: []
112
+ extensions: []
113
+ extra_rdoc_files: []
114
+ files:
115
+ - LICENSE
116
+ - README.md
117
+ - lib/calpack.rb
118
+ - lib/calpack/api_helper.rb
119
+ - lib/calpack/calpack_client.rb
120
+ - lib/calpack/configuration.rb
121
+ - lib/calpack/controllers/base_controller.rb
122
+ - lib/calpack/controllers/simple_calculator_controller.rb
123
+ - lib/calpack/exceptions/api_exception.rb
124
+ - lib/calpack/http/faraday_client.rb
125
+ - lib/calpack/http/http_call_back.rb
126
+ - lib/calpack/http/http_client.rb
127
+ - lib/calpack/http/http_context.rb
128
+ - lib/calpack/http/http_method_enum.rb
129
+ - lib/calpack/http/http_request.rb
130
+ - lib/calpack/http/http_response.rb
131
+ - lib/calpack/models/base_model.rb
132
+ - lib/calpack/models/operation_type_enum.rb
133
+ - test/controllers/controller_test_base.rb
134
+ - test/controllers/test_simple_calculator_controller.rb
135
+ - test/http_response_catcher.rb
136
+ - test/test_helper.rb
137
+ homepage: https://apimatic.io
138
+ licenses:
139
+ - MIT
140
+ metadata: {}
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - "~>"
148
+ - !ruby/object:Gem::Version
149
+ version: '2.0'
150
+ required_rubygems_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ requirements: []
156
+ rubyforge_project:
157
+ rubygems_version: 2.7.6
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: calpack
161
+ test_files: []