automation-test 1.0
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.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +65 -0
- data/lib/apimatic_calculator/api_helper.rb +279 -0
- data/lib/apimatic_calculator/client.rb +35 -0
- data/lib/apimatic_calculator/configuration.rb +111 -0
- data/lib/apimatic_calculator/controllers/base_controller.rb +47 -0
- data/lib/apimatic_calculator/controllers/simple_calculator_controller.rb +45 -0
- data/lib/apimatic_calculator/exceptions/api_exception.rb +20 -0
- data/lib/apimatic_calculator/http/faraday_client.rb +89 -0
- data/lib/apimatic_calculator/http/http_call_back.rb +24 -0
- data/lib/apimatic_calculator/http/http_client.rb +104 -0
- data/lib/apimatic_calculator/http/http_method_enum.rb +13 -0
- data/lib/apimatic_calculator/http/http_request.rb +50 -0
- data/lib/apimatic_calculator/http/http_response.rb +29 -0
- data/lib/apimatic_calculator/models/base_model.rb +58 -0
- data/lib/apimatic_calculator/models/operation_type_enum.rb +23 -0
- data/lib/apimatic_calculator/utilities/date_time_helper.rb +156 -0
- data/lib/apimatic_calculator/utilities/file_wrapper.rb +16 -0
- data/lib/apimatic_calculator.rb +38 -0
- data/test/controllers/controller_test_base.rb +21 -0
- data/test/controllers/test_simple_calculator_controller.rb +34 -0
- data/test/http_response_catcher.rb +19 -0
- data/test/test_helper.rb +94 -0
- metadata +185 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
# apimatic_calculator
|
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 ApimaticCalculator
|
10
|
+
# An implementation of HttpClient.
|
11
|
+
class FaradayClient < HttpClient
|
12
|
+
# The constructor.
|
13
|
+
def initialize(timeout:, max_retries:, retry_interval:,
|
14
|
+
backoff_factor:, retry_statuses:, retry_methods:,
|
15
|
+
http_client_instance: nil, cache: false, verify: true)
|
16
|
+
if http_client_instance.nil?
|
17
|
+
create_connection(timeout: timeout, max_retries: max_retries,
|
18
|
+
retry_interval: retry_interval, backoff_factor: backoff_factor,
|
19
|
+
retry_statuses: retry_statuses, retry_methods: retry_methods,
|
20
|
+
cache: cache, verify: verify)
|
21
|
+
else
|
22
|
+
if http_client_instance.instance_variable_get('@connection').nil?
|
23
|
+
raise ArgumentError,
|
24
|
+
"`connection` cannot be nil in `#{self.class}`. Please specify a valid value."
|
25
|
+
end
|
26
|
+
@connection = http_client_instance.instance_variable_get('@connection')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Method to initialize connection.
|
31
|
+
def create_connection(timeout:, max_retries:, retry_interval:,
|
32
|
+
backoff_factor:, retry_statuses:, retry_methods:,
|
33
|
+
cache: false, verify: true)
|
34
|
+
@connection = Faraday.new do |faraday|
|
35
|
+
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
36
|
+
faraday.use FaradayMiddleware::FollowRedirects
|
37
|
+
faraday.use :gzip
|
38
|
+
faraday.request :multipart
|
39
|
+
faraday.request :url_encoded
|
40
|
+
faraday.ssl[:ca_file] = Certifi.where
|
41
|
+
faraday.ssl[:verify] = verify
|
42
|
+
faraday.request :retry, max: max_retries, interval: retry_interval,
|
43
|
+
backoff_factor: backoff_factor,
|
44
|
+
retry_statuses: retry_statuses,
|
45
|
+
methods: retry_methods
|
46
|
+
faraday.adapter Faraday.default_adapter
|
47
|
+
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
48
|
+
faraday.options[:timeout] = timeout if timeout.positive?
|
49
|
+
end
|
50
|
+
@connection
|
51
|
+
end
|
52
|
+
|
53
|
+
# Method overridden from HttpClient.
|
54
|
+
def execute_as_string(http_request)
|
55
|
+
response = @connection.send(
|
56
|
+
http_request.http_method.downcase,
|
57
|
+
http_request.query_url
|
58
|
+
) do |request|
|
59
|
+
request.headers = http_request.headers
|
60
|
+
unless http_request.http_method == HttpMethodEnum::GET &&
|
61
|
+
http_request.parameters.empty?
|
62
|
+
request.body = http_request.parameters
|
63
|
+
end
|
64
|
+
end
|
65
|
+
convert_response(response, http_request)
|
66
|
+
end
|
67
|
+
|
68
|
+
# Method overridden from HttpClient.
|
69
|
+
def execute_as_binary(http_request)
|
70
|
+
response = @connection.send(
|
71
|
+
http_request.http_method.downcase,
|
72
|
+
http_request.query_url
|
73
|
+
) do |request|
|
74
|
+
request.headers = http_request.headers
|
75
|
+
unless http_request.http_method == HttpMethodEnum::GET &&
|
76
|
+
http_request.parameters.empty?
|
77
|
+
request.body = http_request.parameters
|
78
|
+
end
|
79
|
+
end
|
80
|
+
convert_response(response, http_request)
|
81
|
+
end
|
82
|
+
|
83
|
+
# Method overridden from HttpClient.
|
84
|
+
def convert_response(response, http_request)
|
85
|
+
HttpResponse.new(response.status, response.reason_phrase,
|
86
|
+
response.headers, response.body, http_request)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# HttpCallBack allows defining callables for pre and post API calls.
|
8
|
+
class HttpCallBack
|
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 [HttpResponse] The HttpReponse of the API call.
|
19
|
+
def on_after_response(_http_response)
|
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
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
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,13 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
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
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
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,29 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# Http response received.
|
8
|
+
class HttpResponse
|
9
|
+
attr_reader :status_code, :reason_phrase, :headers, :raw_body, :request
|
10
|
+
|
11
|
+
# The constructor
|
12
|
+
# @param [Integer] The status code returned by the server.
|
13
|
+
# @param [String] The reason phrase returned by the server.
|
14
|
+
# @param [Hash] The headers sent by the server in the response.
|
15
|
+
# @param [String] The raw body of the response.
|
16
|
+
# @param [HttpRequest] The request that resulted in this response.
|
17
|
+
def initialize(status_code,
|
18
|
+
reason_phrase,
|
19
|
+
headers,
|
20
|
+
raw_body,
|
21
|
+
request)
|
22
|
+
@status_code = status_code
|
23
|
+
@reason_phrase = reason_phrase
|
24
|
+
@headers = headers
|
25
|
+
@raw_body = raw_body
|
26
|
+
@request = request
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# Base model.
|
8
|
+
class BaseModel
|
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
|
+
|
17
|
+
optional_fields = optionals if respond_to? 'optionals'
|
18
|
+
nullable_fields = nullables if respond_to? 'nullables'
|
19
|
+
if value.nil?
|
20
|
+
next unless nullable_fields.include?(name)
|
21
|
+
|
22
|
+
if !optional_fields.include?(name) && !nullable_fields.include?(name)
|
23
|
+
raise ArgumentError,
|
24
|
+
"`#{name}` cannot be nil in `#{self.class}`. Please specify a valid value."
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
hash[key] = nil
|
29
|
+
unless value.nil?
|
30
|
+
if respond_to?("to_#{name}")
|
31
|
+
if (value.instance_of? Array) || (value.instance_of? Hash)
|
32
|
+
params = [hash, key]
|
33
|
+
hash[key] = send("to_#{name}", *params)
|
34
|
+
else
|
35
|
+
hash[key] = send("to_#{name}")
|
36
|
+
end
|
37
|
+
elsif value.instance_of? Array
|
38
|
+
hash[key] = value.map { |v| v.is_a?(BaseModel) ? v.to_hash : v }
|
39
|
+
elsif value.instance_of? Hash
|
40
|
+
hash[key] = {}
|
41
|
+
value.each do |k, v|
|
42
|
+
hash[key][k] = v.is_a?(BaseModel) ? v.to_hash : v
|
43
|
+
end
|
44
|
+
else
|
45
|
+
hash[key] = value.is_a?(BaseModel) ? value.to_hash : value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
hash
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns a JSON representation of the curent object.
|
53
|
+
def to_json(options = {})
|
54
|
+
hash = to_hash
|
55
|
+
hash.to_json(options)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# Possible operators are sum, subtract, multiply, divide
|
8
|
+
class OperationTypeEnum
|
9
|
+
OPERATION_TYPE_ENUM = [
|
10
|
+
# Represents the sum operator
|
11
|
+
SUM = 'SUM'.freeze,
|
12
|
+
|
13
|
+
# Represents the subtract operator
|
14
|
+
SUBTRACT = 'SUBTRACT'.freeze,
|
15
|
+
|
16
|
+
# Represents the multiply operator
|
17
|
+
MULTIPLY = 'MULTIPLY'.freeze,
|
18
|
+
|
19
|
+
# Represents the divide operator
|
20
|
+
DIVIDE = 'DIVIDE'.freeze
|
21
|
+
].freeze
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'date'
|
7
|
+
module ApimaticCalculator
|
8
|
+
# A utility that supports dateTime conversion to different formats
|
9
|
+
class DateTimeHelper
|
10
|
+
# Safely converts a DateTime object into a rfc1123 format string
|
11
|
+
# @param [DateTime] The DateTime object
|
12
|
+
# @return [String] The rfc1123 formatted datetime string
|
13
|
+
def self.to_rfc1123(date_time)
|
14
|
+
date_time&.httpdate
|
15
|
+
end
|
16
|
+
|
17
|
+
# Safely converts a map of DateTime objects into a map of rfc1123 format string
|
18
|
+
# @param [hash] a map of DateTime objects
|
19
|
+
# @return [hash] a map of rfc1123 formatted datetime string
|
20
|
+
def self.to_rfc1123_map(date_time, hash, key)
|
21
|
+
return if date_time.nil?
|
22
|
+
|
23
|
+
hash[key] = {}
|
24
|
+
date_time.each do |k, v|
|
25
|
+
hash[key][k] =
|
26
|
+
if v.is_a?(BaseModel)
|
27
|
+
v.to_hash
|
28
|
+
else
|
29
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc1123(v) : v
|
30
|
+
end
|
31
|
+
end
|
32
|
+
hash[key]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Safely converts an array of DateTime objects into an array of rfc1123 format string
|
36
|
+
# @param [Array] an array of DateTime objects
|
37
|
+
# @return [Array] an array of rfc1123 formatted datetime string
|
38
|
+
def self.to_rfc1123_array(date_time, hash, key)
|
39
|
+
return if date_time.nil?
|
40
|
+
|
41
|
+
hash[key] = date_time.map do |v|
|
42
|
+
if v.is_a?(BaseModel)
|
43
|
+
v.to_hash
|
44
|
+
else
|
45
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc1123(v) : v
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Safely converts a DateTime object into a unix format string
|
51
|
+
# @param [DateTime] The DateTime object
|
52
|
+
# @return [String] The unix formatted datetime string
|
53
|
+
def self.to_unix(date_time)
|
54
|
+
date_time.to_time.utc.to_i unless date_time.nil?
|
55
|
+
end
|
56
|
+
|
57
|
+
# Safely converts a map of DateTime objects into a map of unix format string
|
58
|
+
# @param [hash] a map of DateTime objects
|
59
|
+
# @return [hash] a map of unix formatted datetime string
|
60
|
+
def self.to_unix_map(date_time, hash, key)
|
61
|
+
return if date_time.nil?
|
62
|
+
|
63
|
+
hash[key] = {}
|
64
|
+
date_time.each do |k, v|
|
65
|
+
hash[key][k] =
|
66
|
+
if v.is_a?(BaseModel)
|
67
|
+
v.to_hash
|
68
|
+
else
|
69
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_unix(v) : v
|
70
|
+
end
|
71
|
+
end
|
72
|
+
hash[key]
|
73
|
+
end
|
74
|
+
|
75
|
+
# Safely converts an array of DateTime objects into a map of unix format string
|
76
|
+
# @param [hash] an array of DateTime objects
|
77
|
+
# @return [hash] an array of unix formatted datetime string
|
78
|
+
def self.to_unix_array(date_time, hash, key)
|
79
|
+
return if date_time.nil?
|
80
|
+
|
81
|
+
hash[key] = date_time.map do |v|
|
82
|
+
if v.is_a?(BaseModel)
|
83
|
+
v.to_hash
|
84
|
+
else
|
85
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_unix(v) : v
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Safely converts a DateTime object into a rfc3339 format string
|
91
|
+
# @param [DateTime] The DateTime object
|
92
|
+
# @return [String] The rfc3339 formatted datetime string
|
93
|
+
def self.to_rfc3339(date_time)
|
94
|
+
date_time&.rfc3339
|
95
|
+
end
|
96
|
+
|
97
|
+
# Safely converts a map of DateTime objects into a map of rfc1123 format string
|
98
|
+
# @param [hash] a map of DateTime objects
|
99
|
+
# @return [hash] a map of rfc1123 formatted datetime string
|
100
|
+
def self.to_rfc3339_map(date_time, hash, key)
|
101
|
+
return if date_time.nil?
|
102
|
+
|
103
|
+
hash[key] = {}
|
104
|
+
date_time.each do |k, v|
|
105
|
+
hash[key][k] =
|
106
|
+
if v.is_a?(BaseModel)
|
107
|
+
v.to_hash
|
108
|
+
else
|
109
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc3339(v) : v
|
110
|
+
end
|
111
|
+
end
|
112
|
+
hash[key]
|
113
|
+
end
|
114
|
+
|
115
|
+
# Safely converts an array of DateTime objects into an array of rfc1123 format string
|
116
|
+
# @param [Array] an array of DateTime objects
|
117
|
+
# @return [Array] an array of rfc1123 formatted datetime string
|
118
|
+
def self.to_rfc3339_array(date_time, hash, key)
|
119
|
+
return if date_time.nil?
|
120
|
+
|
121
|
+
hash[key] = date_time.map do |v|
|
122
|
+
if v.is_a?(BaseModel)
|
123
|
+
v.to_hash
|
124
|
+
else
|
125
|
+
v.is_a?(DateTime) ? DateTimeHelper.to_rfc3339(v) : v
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Safely converts a rfc1123 format string into a DateTime object
|
131
|
+
# @param [String] The rfc1123 formatted datetime string
|
132
|
+
# @return [DateTime] A DateTime object
|
133
|
+
def self.from_rfc1123(date_time)
|
134
|
+
DateTime.httpdate(date_time)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Safely converts a unix format string into a DateTime object
|
138
|
+
# @param [String] The unix formatted datetime string
|
139
|
+
# @return [DateTime] A DateTime object
|
140
|
+
def self.from_unix(date_time)
|
141
|
+
Time.at(date_time.to_i).utc.to_datetime
|
142
|
+
end
|
143
|
+
|
144
|
+
# Safely converts a rfc3339 format string into a DateTime object
|
145
|
+
# @param [String] The rfc3339 formatted datetime string
|
146
|
+
# @return [DateTime] A DateTime object
|
147
|
+
def self.from_rfc3339(date_time)
|
148
|
+
# missing timezone information
|
149
|
+
if date_time.end_with?('Z') || date_time.index('+')
|
150
|
+
DateTime.rfc3339(date_time)
|
151
|
+
else
|
152
|
+
DateTime.rfc3339("#{date_time}Z")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# A utility to allow users to set the content-type for files
|
8
|
+
class FileWrapper
|
9
|
+
attr_reader :content_type, :file
|
10
|
+
|
11
|
+
def initialize(file, content_type: 'application/octet-stream')
|
12
|
+
@file = file
|
13
|
+
@content_type = content_type
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -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'
|
13
|
+
require_relative 'apimatic_calculator/client'
|
14
|
+
|
15
|
+
# Utilities
|
16
|
+
require_relative 'apimatic_calculator/utilities/file_wrapper'
|
17
|
+
require_relative 'apimatic_calculator/utilities/date_time_helper'
|
18
|
+
|
19
|
+
# Http
|
20
|
+
require_relative 'apimatic_calculator/http/http_call_back'
|
21
|
+
require_relative 'apimatic_calculator/http/http_client'
|
22
|
+
require_relative 'apimatic_calculator/http/faraday_client'
|
23
|
+
require_relative 'apimatic_calculator/http/http_method_enum'
|
24
|
+
require_relative 'apimatic_calculator/http/http_request'
|
25
|
+
require_relative 'apimatic_calculator/http/http_response'
|
26
|
+
|
27
|
+
# Models
|
28
|
+
require_relative 'apimatic_calculator/models/base_model'
|
29
|
+
require_relative 'apimatic_calculator/models/operation_type_enum'
|
30
|
+
|
31
|
+
# Exceptions
|
32
|
+
require_relative 'apimatic_calculator/exceptions/api_exception'
|
33
|
+
|
34
|
+
require_relative 'apimatic_calculator/configuration'
|
35
|
+
|
36
|
+
# Controllers
|
37
|
+
require_relative 'apimatic_calculator/controllers/base_controller'
|
38
|
+
require_relative 'apimatic_calculator/controllers/simple_calculator_controller'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'minitest/hell'
|
9
|
+
require 'minitest/pride'
|
10
|
+
require 'minitest/proveit'
|
11
|
+
require 'apimatic_calculator'
|
12
|
+
require_relative '../test_helper'
|
13
|
+
require_relative '../http_response_catcher'
|
14
|
+
|
15
|
+
class ControllerTestBase < Minitest::Test
|
16
|
+
parallelize_me!
|
17
|
+
include ApimaticCalculator
|
18
|
+
|
19
|
+
# Create configuration and set any test parameters
|
20
|
+
CONFIG = Configuration.new
|
21
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require_relative 'controller_test_base'
|
7
|
+
|
8
|
+
class SimpleCalculatorControllerTests < ControllerTestBase
|
9
|
+
# Called only once for the class before any test has executed
|
10
|
+
def setup
|
11
|
+
@response_catcher = HttpResponseCatcher.new
|
12
|
+
@controller = SimpleCalculatorController.new CONFIG, http_call_back: @response_catcher
|
13
|
+
end
|
14
|
+
|
15
|
+
# Check if multiplication works
|
16
|
+
def test_multiply()
|
17
|
+
# Parameters for the API call
|
18
|
+
options = {}
|
19
|
+
options['operation'] = 'MULTIPLY'
|
20
|
+
options['x'] = 4
|
21
|
+
options['y'] = 5
|
22
|
+
|
23
|
+
# Perform the API call through the SDK function
|
24
|
+
result = @controller.get_calculate(options)
|
25
|
+
|
26
|
+
# Test response code
|
27
|
+
assert_equal(200, @response_catcher.response.status_code)
|
28
|
+
|
29
|
+
# Test whether the captured response is as we expected
|
30
|
+
refute_nil(result)
|
31
|
+
assert_equal('20', @response_catcher.response.raw_body)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
class HttpResponseCatcher < ApimaticCalculator::HttpCallBack
|
7
|
+
attr_accessor :response
|
8
|
+
|
9
|
+
def on_before_request(request)
|
10
|
+
end
|
11
|
+
|
12
|
+
# Catching the response
|
13
|
+
def on_after_response(response)
|
14
|
+
@response = response
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
|