apimatic_calculator_test_ruby 1.0.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 +110 -0
- data/lib/apimatic_calculator/api_helper.rb +449 -0
- data/lib/apimatic_calculator/client.rb +35 -0
- data/lib/apimatic_calculator/configuration.rb +115 -0
- data/lib/apimatic_calculator/controllers/base_controller.rb +59 -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/exceptions/validation_exception.rb +18 -0
- data/lib/apimatic_calculator/http/faraday_client.rb +98 -0
- data/lib/apimatic_calculator/http/http_call_back.rb +24 -0
- data/lib/apimatic_calculator/http/http_client.rb +123 -0
- data/lib/apimatic_calculator/http/http_method_enum.rb +13 -0
- data/lib/apimatic_calculator/http/http_request.rb +54 -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 +39 -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 +239 -0
@@ -0,0 +1,115 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# An enum for SDK environments.
|
8
|
+
class Environment
|
9
|
+
# PRODUCTION: This environment connect to the LIVE calculator API
|
10
|
+
ENVIRONMENT = [
|
11
|
+
PRODUCTION = 'production'.freeze
|
12
|
+
].freeze
|
13
|
+
end
|
14
|
+
|
15
|
+
# An enum for API servers.
|
16
|
+
class Server
|
17
|
+
SERVER = [
|
18
|
+
CALCULATOR = 'Calculator'.freeze
|
19
|
+
].freeze
|
20
|
+
end
|
21
|
+
|
22
|
+
# All configuration including auth info and base URI for the API access
|
23
|
+
# are configured in this class.
|
24
|
+
class Configuration
|
25
|
+
# The attribute readers for properties.
|
26
|
+
attr_reader :http_client, :connection, :adapter, :timeout, :max_retries, :retry_interval,
|
27
|
+
:backoff_factor, :retry_statuses, :retry_methods, :environment
|
28
|
+
|
29
|
+
class << self
|
30
|
+
attr_reader :environments
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(connection: nil, adapter: :net_http_persistent, timeout: 60,
|
34
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
35
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
36
|
+
retry_methods: %i[get put],
|
37
|
+
environment: Environment::PRODUCTION)
|
38
|
+
# The Faraday connection object passed by the SDK user for making requests
|
39
|
+
@connection = connection
|
40
|
+
|
41
|
+
# The Faraday adapter object passed by the SDK user for performing http requests
|
42
|
+
@adapter = adapter
|
43
|
+
|
44
|
+
# The value to use for connection timeout
|
45
|
+
@timeout = timeout
|
46
|
+
|
47
|
+
# The number of times to retry an endpoint call if it fails
|
48
|
+
@max_retries = max_retries
|
49
|
+
|
50
|
+
# Pause in seconds between retries
|
51
|
+
@retry_interval = retry_interval
|
52
|
+
|
53
|
+
# The amount to multiply each successive retry's interval amount
|
54
|
+
# by in order to provide backoff
|
55
|
+
@backoff_factor = backoff_factor
|
56
|
+
|
57
|
+
# A list of HTTP statuses to retry
|
58
|
+
@retry_statuses = retry_statuses
|
59
|
+
|
60
|
+
# A list of HTTP methods to retry
|
61
|
+
@retry_methods = retry_methods
|
62
|
+
|
63
|
+
# Current API environment
|
64
|
+
@environment = String(environment)
|
65
|
+
|
66
|
+
# The Http Client to use for making requests.
|
67
|
+
@http_client = create_http_client
|
68
|
+
end
|
69
|
+
|
70
|
+
def clone_with(connection: nil, adapter: nil, timeout: nil,
|
71
|
+
max_retries: nil, retry_interval: nil, backoff_factor: nil,
|
72
|
+
retry_statuses: nil, retry_methods: nil, environment: nil)
|
73
|
+
connection ||= self.connection
|
74
|
+
adapter ||= self.adapter
|
75
|
+
timeout ||= self.timeout
|
76
|
+
max_retries ||= self.max_retries
|
77
|
+
retry_interval ||= self.retry_interval
|
78
|
+
backoff_factor ||= self.backoff_factor
|
79
|
+
retry_statuses ||= self.retry_statuses
|
80
|
+
retry_methods ||= self.retry_methods
|
81
|
+
environment ||= self.environment
|
82
|
+
|
83
|
+
Configuration.new(connection: connection, adapter: adapter,
|
84
|
+
timeout: timeout, max_retries: max_retries,
|
85
|
+
retry_interval: retry_interval,
|
86
|
+
backoff_factor: backoff_factor,
|
87
|
+
retry_statuses: retry_statuses,
|
88
|
+
retry_methods: retry_methods, environment: environment)
|
89
|
+
end
|
90
|
+
|
91
|
+
def create_http_client
|
92
|
+
FaradayClient.new(timeout: timeout, max_retries: max_retries,
|
93
|
+
retry_interval: retry_interval,
|
94
|
+
backoff_factor: backoff_factor,
|
95
|
+
retry_statuses: retry_statuses,
|
96
|
+
retry_methods: retry_methods, connection: connection,
|
97
|
+
adapter: adapter)
|
98
|
+
end
|
99
|
+
|
100
|
+
# All the environments the SDK can run in.
|
101
|
+
ENVIRONMENTS = {
|
102
|
+
Environment::PRODUCTION => {
|
103
|
+
Server::CALCULATOR => 'https://examples.apimatic.io/apps/calculator'
|
104
|
+
}
|
105
|
+
}.freeze
|
106
|
+
|
107
|
+
# Generates the appropriate base URI for the environment and the server.
|
108
|
+
# @param [Configuration::Server] The server enum for which the base URI is
|
109
|
+
# required.
|
110
|
+
# @return [String] The base URI.
|
111
|
+
def get_base_uri(server = Server::CALCULATOR)
|
112
|
+
ENVIRONMENTS[environment][server].clone
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# BaseController.
|
8
|
+
class BaseController
|
9
|
+
attr_accessor :config, :http_call_back
|
10
|
+
|
11
|
+
def initialize(config, http_call_back: nil)
|
12
|
+
@config = config
|
13
|
+
@http_call_back = http_call_back
|
14
|
+
|
15
|
+
@global_headers = {
|
16
|
+
'user-agent' => get_user_agent
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_parameters(args)
|
21
|
+
args.each do |_name, value|
|
22
|
+
raise ArgumentError, "Required parameter #{_name} cannot be nil." if value.nil?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def validate_parameters_types(args)
|
27
|
+
args.each do |_name, type|
|
28
|
+
key, val = type.first
|
29
|
+
APIHelper.validate_types(key, val) unless key.nil?
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def execute_request(request, binary: false)
|
34
|
+
@http_call_back&.on_before_request(request)
|
35
|
+
|
36
|
+
APIHelper.clean_hash(request.headers)
|
37
|
+
request.headers.merge!(@global_headers)
|
38
|
+
|
39
|
+
response = if binary
|
40
|
+
config.http_client.execute_as_binary(request)
|
41
|
+
else
|
42
|
+
config.http_client.execute_as_string(request)
|
43
|
+
end
|
44
|
+
@http_call_back&.on_after_response(response)
|
45
|
+
|
46
|
+
response
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate_response(response)
|
50
|
+
raise APIException.new 'HTTP Response Not OK', response unless
|
51
|
+
response.status_code.between?(200, 208) # [200,208] = HTTP OK
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_user_agent
|
55
|
+
user_agent = 'APIMATIC 3.0'
|
56
|
+
user_agent
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# SimpleCalculatorController
|
8
|
+
class SimpleCalculatorController < BaseController
|
9
|
+
def initialize(config, http_call_back: nil)
|
10
|
+
super(config, http_call_back: http_call_back)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Calculates the expression using the specified operation.
|
14
|
+
# @param [OperationTypeEnum] operation Required parameter: The operator to
|
15
|
+
# apply on the variables
|
16
|
+
# @param [Float] x Required parameter: The LHS value
|
17
|
+
# @param [Float] y Required parameter: The RHS value
|
18
|
+
# @return [Float] response from the API call
|
19
|
+
def get_calculate(options = {})
|
20
|
+
# Prepare query url.
|
21
|
+
_query_builder = config.get_base_uri
|
22
|
+
_query_builder << '/{operation}'
|
23
|
+
_query_builder = APIHelper.append_url_with_template_parameters(
|
24
|
+
_query_builder,
|
25
|
+
'operation' => { 'value' => options['operation'], 'encode' => true }
|
26
|
+
)
|
27
|
+
_query_builder = APIHelper.append_url_with_query_parameters(
|
28
|
+
_query_builder,
|
29
|
+
'x' => options['x'],
|
30
|
+
'y' => options['y']
|
31
|
+
)
|
32
|
+
_query_url = APIHelper.clean_url _query_builder
|
33
|
+
|
34
|
+
# Prepare and execute HttpRequest.
|
35
|
+
_request = config.http_client.get(
|
36
|
+
_query_url
|
37
|
+
)
|
38
|
+
_response = execute_request(_request)
|
39
|
+
validate_response(_response)
|
40
|
+
|
41
|
+
# Return appropriate response type.
|
42
|
+
_response.raw_body.to_f
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# Class for exceptions when there is a network error, status code error, etc.
|
8
|
+
class APIException < StandardError
|
9
|
+
attr_reader :response, :response_code
|
10
|
+
|
11
|
+
# The constructor.
|
12
|
+
# @param [String] The reason for raising an exception.
|
13
|
+
# @param [HttpResponse] The HttpReponse of the API call.
|
14
|
+
def initialize(reason, response)
|
15
|
+
super(reason)
|
16
|
+
@response = response
|
17
|
+
@response_code = response.status_code
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# apimatic_calculator
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module ApimaticCalculator
|
7
|
+
# Class for exceptions when there is a schema validation error.
|
8
|
+
class ValidationException < StandardError
|
9
|
+
attr_reader :reason
|
10
|
+
|
11
|
+
# The constructor.
|
12
|
+
# @param [String] The reason for raising an exception.
|
13
|
+
def initialize(value, template)
|
14
|
+
@reason = "The value #{value} provided doesn't validate against the schema #{template}"
|
15
|
+
super(reason)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,98 @@
|
|
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/retry'
|
8
|
+
require 'faraday/multipart'
|
9
|
+
require 'faraday/follow_redirects'
|
10
|
+
require 'faraday/gzip'
|
11
|
+
require 'faraday/net_http_persistent'
|
12
|
+
|
13
|
+
module ApimaticCalculator
|
14
|
+
# An implementation of HttpClient.
|
15
|
+
class FaradayClient < HttpClient
|
16
|
+
# The attribute readers for properties.
|
17
|
+
attr_reader :connection
|
18
|
+
|
19
|
+
# The constructor.
|
20
|
+
def initialize(timeout:, max_retries:, retry_interval:,
|
21
|
+
backoff_factor:, retry_statuses:, retry_methods:,
|
22
|
+
connection:, adapter:, cache: false, verify: true)
|
23
|
+
@connection = if connection.nil?
|
24
|
+
create_connection(timeout: timeout, max_retries: max_retries,
|
25
|
+
retry_interval: retry_interval, backoff_factor: backoff_factor,
|
26
|
+
retry_statuses: retry_statuses, retry_methods: retry_methods,
|
27
|
+
adapter: adapter, cache: cache, verify: verify)
|
28
|
+
else
|
29
|
+
connection
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Method to initialize connection.
|
34
|
+
def create_connection(timeout:, max_retries:, retry_interval:,
|
35
|
+
backoff_factor:, retry_statuses:, retry_methods:,
|
36
|
+
adapter:, cache: false, verify: true)
|
37
|
+
Faraday.new do |faraday|
|
38
|
+
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
39
|
+
faraday.use Faraday::FollowRedirects::Middleware
|
40
|
+
faraday.request :gzip
|
41
|
+
faraday.request :multipart
|
42
|
+
faraday.request :url_encoded
|
43
|
+
faraday.ssl[:ca_file] = Certifi.where
|
44
|
+
faraday.ssl[:verify] = verify
|
45
|
+
faraday.request :retry, max: max_retries, interval: retry_interval,
|
46
|
+
backoff_factor: backoff_factor,
|
47
|
+
retry_statuses: retry_statuses,
|
48
|
+
methods: retry_methods,
|
49
|
+
retry_if: proc { |env, _exc|
|
50
|
+
env.request.context['forced_retry'] ||= false
|
51
|
+
}
|
52
|
+
faraday.adapter adapter
|
53
|
+
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
54
|
+
faraday.options[:timeout] = timeout if timeout.positive?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Method overridden from HttpClient.
|
59
|
+
def execute_as_string(http_request)
|
60
|
+
response = @connection.send(
|
61
|
+
http_request.http_method.downcase,
|
62
|
+
http_request.query_url
|
63
|
+
) do |request|
|
64
|
+
request.headers = http_request.headers.map { |k, v| [k.to_s, v.to_s] }
|
65
|
+
request.options.context ||= {}
|
66
|
+
request.options.context.merge!(http_request.context)
|
67
|
+
unless http_request.http_method == HttpMethodEnum::GET &&
|
68
|
+
http_request.parameters.empty?
|
69
|
+
request.body = http_request.parameters
|
70
|
+
end
|
71
|
+
end
|
72
|
+
convert_response(response, http_request)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Method overridden from HttpClient.
|
76
|
+
def execute_as_binary(http_request)
|
77
|
+
response = @connection.send(
|
78
|
+
http_request.http_method.downcase,
|
79
|
+
http_request.query_url
|
80
|
+
) do |request|
|
81
|
+
request.headers = http_request.headers
|
82
|
+
request.options.context ||= {}
|
83
|
+
request.options.context.merge!(http_request.context)
|
84
|
+
unless http_request.http_method == HttpMethodEnum::GET &&
|
85
|
+
http_request.parameters.empty?
|
86
|
+
request.body = http_request.parameters
|
87
|
+
end
|
88
|
+
end
|
89
|
+
convert_response(response, http_request)
|
90
|
+
end
|
91
|
+
|
92
|
+
# Method overridden from HttpClient.
|
93
|
+
def convert_response(response, http_request)
|
94
|
+
HttpResponse.new(response.status, response.reason_phrase,
|
95
|
+
response.headers, response.body, http_request)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
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,123 @@
|
|
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
|
+
# @param [Hash, Optional] The context for the HTTP Request.
|
37
|
+
def get(query_url,
|
38
|
+
headers: {},
|
39
|
+
context: {})
|
40
|
+
HttpRequest.new(HttpMethodEnum::GET,
|
41
|
+
query_url,
|
42
|
+
headers: headers,
|
43
|
+
context: context)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Get a HEAD HttpRequest object.
|
47
|
+
# @param [String] The URL to send the request to.
|
48
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
49
|
+
# @param [Hash, Optional] The context for the HTTP Request.
|
50
|
+
def head(query_url,
|
51
|
+
headers: {},
|
52
|
+
context: {})
|
53
|
+
HttpRequest.new(HttpMethodEnum::HEAD,
|
54
|
+
query_url,
|
55
|
+
headers: headers,
|
56
|
+
context: context)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Get a POST HttpRequest object.
|
60
|
+
# @param [String] The URL to send the request to.
|
61
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
62
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
63
|
+
# @param [Hash, Optional] The context for the HTTP Request.
|
64
|
+
def post(query_url,
|
65
|
+
headers: {},
|
66
|
+
parameters: {},
|
67
|
+
context: {})
|
68
|
+
HttpRequest.new(HttpMethodEnum::POST,
|
69
|
+
query_url,
|
70
|
+
headers: headers,
|
71
|
+
parameters: parameters,
|
72
|
+
context: context)
|
73
|
+
end
|
74
|
+
|
75
|
+
# Get a PUT HttpRequest object.
|
76
|
+
# @param [String] The URL to send the request to.
|
77
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
78
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
79
|
+
# @param [Hash, Optional] The context for the HTTP Request.
|
80
|
+
def put(query_url,
|
81
|
+
headers: {},
|
82
|
+
parameters: {},
|
83
|
+
context: {})
|
84
|
+
HttpRequest.new(HttpMethodEnum::PUT,
|
85
|
+
query_url,
|
86
|
+
headers: headers,
|
87
|
+
parameters: parameters,
|
88
|
+
context: context)
|
89
|
+
end
|
90
|
+
|
91
|
+
# Get a PATCH HttpRequest object.
|
92
|
+
# @param [String] The URL to send the request to.
|
93
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
94
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
95
|
+
# @param [Hash, Optional] The context for the HTTP Request.
|
96
|
+
def patch(query_url,
|
97
|
+
headers: {},
|
98
|
+
parameters: {},
|
99
|
+
context: {})
|
100
|
+
HttpRequest.new(HttpMethodEnum::PATCH,
|
101
|
+
query_url,
|
102
|
+
headers: headers,
|
103
|
+
parameters: parameters,
|
104
|
+
context: context)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Get a DELETE HttpRequest object.
|
108
|
+
# @param [String] The URL to send the request to.
|
109
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
110
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
111
|
+
# @param [Hash, Optional] The context for the HTTP Request.
|
112
|
+
def delete(query_url,
|
113
|
+
headers: {},
|
114
|
+
parameters: nil,
|
115
|
+
context: {})
|
116
|
+
HttpRequest.new(HttpMethodEnum::DELETE,
|
117
|
+
query_url,
|
118
|
+
headers: headers,
|
119
|
+
parameters: parameters,
|
120
|
+
context: context)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
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,54 @@
|
|
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
|
+
:context
|
12
|
+
|
13
|
+
# The constructor.
|
14
|
+
# @param [HttpMethodEnum] The HTTP method.
|
15
|
+
# @param [String] The URL to send the request to.
|
16
|
+
# @param [Hash, Optional] The headers for the HTTP Request.
|
17
|
+
# @param [Hash, Optional] The parameters for the HTTP Request.
|
18
|
+
# @param [Hash, Optional] The context for the HTTP Request.
|
19
|
+
def initialize(http_method,
|
20
|
+
query_url,
|
21
|
+
headers: {},
|
22
|
+
parameters: {},
|
23
|
+
context: {})
|
24
|
+
@http_method = http_method
|
25
|
+
@query_url = query_url
|
26
|
+
@headers = headers
|
27
|
+
@parameters = parameters
|
28
|
+
@context = context
|
29
|
+
end
|
30
|
+
|
31
|
+
# Add a header to the HttpRequest.
|
32
|
+
# @param [String] The name of the header.
|
33
|
+
# @param [String] The value of the header.
|
34
|
+
def add_header(name, value)
|
35
|
+
@headers[name] = value
|
36
|
+
end
|
37
|
+
|
38
|
+
# Add a parameter to the HttpRequest.
|
39
|
+
# @param [String] The name of the parameter.
|
40
|
+
# @param [String] The value of the parameter.
|
41
|
+
def add_parameter(name, value)
|
42
|
+
@parameters[name] = value
|
43
|
+
end
|
44
|
+
|
45
|
+
# Add a query parameter to the HttpRequest.
|
46
|
+
# @param [String] The name of the query parameter.
|
47
|
+
# @param [String] The value of the query parameter.
|
48
|
+
def add_query_parameter(name, value)
|
49
|
+
@query_url = APIHelper.append_url_with_query_parameters(@query_url,
|
50
|
+
name => value)
|
51
|
+
@query_url = APIHelper.clean_url(@query_url)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
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..]
|
15
|
+
key = self.class.names.key?(name) ? self.class.names[name] : name
|
16
|
+
|
17
|
+
optional_fields = self.class.optionals
|
18
|
+
nullable_fields = self.class.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
|