BATester 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +182 -0
- data/lib/ba_tester_with_custom_parameters.rb +40 -0
- data/lib/ba_tester_with_custom_parameters/api_helper.rb +289 -0
- data/lib/ba_tester_with_custom_parameters/client.rb +33 -0
- data/lib/ba_tester_with_custom_parameters/configuration.rb +130 -0
- data/lib/ba_tester_with_custom_parameters/controllers/api_controller.rb +33 -0
- data/lib/ba_tester_with_custom_parameters/controllers/base_controller.rb +49 -0
- data/lib/ba_tester_with_custom_parameters/exceptions/api_exception.rb +20 -0
- data/lib/ba_tester_with_custom_parameters/http/auth/basic_auth.rb +22 -0
- data/lib/ba_tester_with_custom_parameters/http/faraday_client.rb +67 -0
- data/lib/ba_tester_with_custom_parameters/http/http_call_back.rb +24 -0
- data/lib/ba_tester_with_custom_parameters/http/http_client.rb +104 -0
- data/lib/ba_tester_with_custom_parameters/http/http_method_enum.rb +13 -0
- data/lib/ba_tester_with_custom_parameters/http/http_request.rb +50 -0
- data/lib/ba_tester_with_custom_parameters/http/http_response.rb +29 -0
- data/lib/ba_tester_with_custom_parameters/models/base_model.rb +36 -0
- data/lib/ba_tester_with_custom_parameters/models/suite_code_enum.rb +23 -0
- data/lib/ba_tester_with_custom_parameters/utilities/file_wrapper.rb +17 -0
- data/test/controllers/controller_test_base.rb +21 -0
- data/test/controllers/test_api_controller.rb +29 -0
- data/test/http_response_catcher.rb +19 -0
- data/test/test_helper.rb +94 -0
- metadata +182 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
# ba_tester_with_custom_parameters
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module BaTesterWithCustomParameters
|
7
|
+
# ba_tester_with_custom_parameters client class.
|
8
|
+
class Client
|
9
|
+
attr_reader :config
|
10
|
+
|
11
|
+
# Access to client controller.
|
12
|
+
# @return [APIController] Returns the controller instance.
|
13
|
+
def client
|
14
|
+
@client ||= APIController.new config
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
18
|
+
backoff_factor: 1, environment: Environment::TESTING,
|
19
|
+
port: '80', suites: SuiteCodeEnum::HEARTS,
|
20
|
+
username: 'farhan', password: 'apimatic', config: nil)
|
21
|
+
@config = if config.nil?
|
22
|
+
Configuration.new(timeout: timeout, max_retries: max_retries,
|
23
|
+
retry_interval: retry_interval,
|
24
|
+
backoff_factor: backoff_factor,
|
25
|
+
environment: environment, port: port,
|
26
|
+
suites: suites, username: username,
|
27
|
+
password: password)
|
28
|
+
else
|
29
|
+
config
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,130 @@
|
|
1
|
+
# ba_tester_with_custom_parameters
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module BaTesterWithCustomParameters
|
7
|
+
# An enum for SDK environments.
|
8
|
+
class Environment
|
9
|
+
ENVIRONMENT = [
|
10
|
+
PRODUCTION = 'production'.freeze,
|
11
|
+
TESTING = 'testing'.freeze
|
12
|
+
].freeze
|
13
|
+
end
|
14
|
+
|
15
|
+
# An enum for API servers.
|
16
|
+
class Server
|
17
|
+
SERVER = [
|
18
|
+
DEFAULT = 'default'.freeze,
|
19
|
+
AUTH_SERVER = 'auth server'.freeze
|
20
|
+
].freeze
|
21
|
+
end
|
22
|
+
|
23
|
+
# All configuration including auth info and base URI for the API access
|
24
|
+
# are configured in this class.
|
25
|
+
class Configuration
|
26
|
+
# The attribute readers for properties.
|
27
|
+
attr_reader :http_client
|
28
|
+
attr_reader :timeout
|
29
|
+
attr_reader :max_retries
|
30
|
+
attr_reader :retry_interval
|
31
|
+
attr_reader :backoff_factor
|
32
|
+
attr_reader :environment
|
33
|
+
attr_reader :port
|
34
|
+
attr_reader :suites
|
35
|
+
attr_reader :username
|
36
|
+
attr_reader :password
|
37
|
+
|
38
|
+
class << self
|
39
|
+
attr_reader :environments
|
40
|
+
end
|
41
|
+
|
42
|
+
def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
|
43
|
+
backoff_factor: 1, environment: Environment::TESTING,
|
44
|
+
port: '80', suites: SuiteCodeEnum::HEARTS,
|
45
|
+
username: 'farhan', password: 'apimatic')
|
46
|
+
# The value to use for connection timeout
|
47
|
+
@timeout = timeout
|
48
|
+
|
49
|
+
# The number of times to retry an endpoint call if it fails
|
50
|
+
@max_retries = max_retries
|
51
|
+
|
52
|
+
# Pause in seconds between retries
|
53
|
+
@retry_interval = retry_interval
|
54
|
+
|
55
|
+
# The amount to multiply each successive retry's interval amount
|
56
|
+
# by in order to provide backoff
|
57
|
+
@backoff_factor = backoff_factor
|
58
|
+
|
59
|
+
# Current API environment
|
60
|
+
@environment = String(environment)
|
61
|
+
|
62
|
+
# port value
|
63
|
+
@port = port
|
64
|
+
|
65
|
+
# suites value
|
66
|
+
@suites = suites
|
67
|
+
|
68
|
+
# TODO: Replace
|
69
|
+
@username = username
|
70
|
+
|
71
|
+
# TODO: Replace
|
72
|
+
@password = password
|
73
|
+
|
74
|
+
# The Http Client to use for making requests.
|
75
|
+
@http_client = create_http_client
|
76
|
+
end
|
77
|
+
|
78
|
+
def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
|
79
|
+
backoff_factor: nil, environment: nil, port: nil,
|
80
|
+
suites: nil, username: nil, password: nil)
|
81
|
+
timeout ||= self.timeout
|
82
|
+
max_retries ||= self.max_retries
|
83
|
+
retry_interval ||= self.retry_interval
|
84
|
+
backoff_factor ||= self.backoff_factor
|
85
|
+
environment ||= self.environment
|
86
|
+
port ||= self.port
|
87
|
+
suites ||= self.suites
|
88
|
+
username ||= self.username
|
89
|
+
password ||= self.password
|
90
|
+
|
91
|
+
Configuration.new(timeout: timeout, max_retries: max_retries,
|
92
|
+
retry_interval: retry_interval,
|
93
|
+
backoff_factor: backoff_factor,
|
94
|
+
environment: environment, port: port, suites: suites,
|
95
|
+
username: username, password: password)
|
96
|
+
end
|
97
|
+
|
98
|
+
def create_http_client
|
99
|
+
FaradayClient.new(timeout: timeout, max_retries: max_retries,
|
100
|
+
retry_interval: retry_interval,
|
101
|
+
backoff_factor: backoff_factor)
|
102
|
+
end
|
103
|
+
|
104
|
+
# All the environments the SDK can run in.
|
105
|
+
ENVIRONMENTS = {
|
106
|
+
Environment::PRODUCTION => {
|
107
|
+
Server::DEFAULT => 'http://apimatic.hopto.org:{suites}',
|
108
|
+
Server::AUTH_SERVER => 'http://apimaticauth.hopto.org:3000'
|
109
|
+
},
|
110
|
+
Environment::TESTING => {
|
111
|
+
Server::DEFAULT => 'http://localhost:3000',
|
112
|
+
Server::AUTH_SERVER => 'http://apimaticauth.xhopto.org:3000'
|
113
|
+
}
|
114
|
+
}.freeze
|
115
|
+
|
116
|
+
# Generates the appropriate base URI for the environment and the server.
|
117
|
+
# @param [Configuration::Server] The server enum for which the base URI is
|
118
|
+
# required.
|
119
|
+
# @return [String] The base URI.
|
120
|
+
def get_base_uri(server = Server::DEFAULT)
|
121
|
+
parameters = {
|
122
|
+
'port' => { 'value' => port, 'encode' => false },
|
123
|
+
'suites' => { 'value' => suites, 'encode' => false }
|
124
|
+
}
|
125
|
+
APIHelper.append_url_with_template_parameters(
|
126
|
+
ENVIRONMENTS[environment][server], parameters
|
127
|
+
)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# ba_tester_with_custom_parameters
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module BaTesterWithCustomParameters
|
7
|
+
# APIController
|
8
|
+
class APIController < BaseController
|
9
|
+
def initialize(config, http_call_back: nil)
|
10
|
+
super(config, http_call_back: http_call_back)
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO: type endpoint description here
|
14
|
+
# @return [String] response from the API call
|
15
|
+
def get_basic_auth_test
|
16
|
+
# Prepare query url.
|
17
|
+
_query_builder = config.get_base_uri
|
18
|
+
_query_builder << '/auth/basic'
|
19
|
+
_query_url = APIHelper.clean_url _query_builder
|
20
|
+
|
21
|
+
# Prepare and execute HttpRequest.
|
22
|
+
_request = config.http_client.get(
|
23
|
+
_query_url
|
24
|
+
)
|
25
|
+
BasicAuth.apply(config, _request)
|
26
|
+
_response = execute_request(_request)
|
27
|
+
validate_response(_response)
|
28
|
+
|
29
|
+
# Return appropriate response type.
|
30
|
+
_response.raw_body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# ba_tester_with_custom_parameters
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module BaTesterWithCustomParameters
|
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' => 'APIMATIC 2.0'
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_parameters(args)
|
21
|
+
args.each do |_name, value|
|
22
|
+
if value.nil?
|
23
|
+
raise ArgumentError, "Required parameter #{_name} cannot be nil."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def execute_request(request, binary: false)
|
29
|
+
@http_call_back.on_before_request(request) if @http_call_back
|
30
|
+
|
31
|
+
APIHelper.clean_hash(request.headers)
|
32
|
+
request.headers.merge!(@global_headers)
|
33
|
+
|
34
|
+
response = if binary
|
35
|
+
config.http_client.execute_as_binary(request)
|
36
|
+
else
|
37
|
+
config.http_client.execute_as_string(request)
|
38
|
+
end
|
39
|
+
@http_call_back.on_after_response(response) if @http_call_back
|
40
|
+
|
41
|
+
response
|
42
|
+
end
|
43
|
+
|
44
|
+
def validate_response(response)
|
45
|
+
raise APIException.new 'HTTP Response Not OK', response unless
|
46
|
+
response.status_code.between?(200, 208) # [200,208] = HTTP OK
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# ba_tester_with_custom_parameters
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module BaTesterWithCustomParameters
|
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,22 @@
|
|
1
|
+
# ba_tester_with_custom_parameters
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
require 'base64'
|
7
|
+
|
8
|
+
module BaTesterWithCustomParameters
|
9
|
+
# Utility class for basic authorization.
|
10
|
+
class BasicAuth
|
11
|
+
# Add basic authentication to the request.
|
12
|
+
# @param [HttpRequest] The HttpRequest object to which authentication will
|
13
|
+
# be added.
|
14
|
+
def self.apply(config, http_request)
|
15
|
+
username = config.username
|
16
|
+
password = config.password
|
17
|
+
value = Base64.strict_encode64("#{username}:#{password}")
|
18
|
+
header_value = "Basic #{value}"
|
19
|
+
http_request.headers['Authorization'] = header_value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# ba_tester_with_custom_parameters
|
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 BaTesterWithCustomParameters
|
10
|
+
# An implementation of HttpClient.
|
11
|
+
class FaradayClient < HttpClient
|
12
|
+
# The constructor.
|
13
|
+
def initialize(timeout:, max_retries:, retry_interval:,
|
14
|
+
backoff_factor:, cache: false, verify: true)
|
15
|
+
@connection = Faraday.new do |faraday|
|
16
|
+
faraday.use Faraday::HttpCache, serializer: Marshal if cache
|
17
|
+
faraday.use FaradayMiddleware::FollowRedirects
|
18
|
+
faraday.use :gzip
|
19
|
+
faraday.request :multipart
|
20
|
+
faraday.request :url_encoded
|
21
|
+
faraday.ssl[:ca_file] = Certifi.where
|
22
|
+
faraday.ssl[:verify] = verify
|
23
|
+
faraday.request :retry, max: max_retries, interval: retry_interval,
|
24
|
+
backoff_factor: backoff_factor
|
25
|
+
faraday.adapter Faraday.default_adapter
|
26
|
+
faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
|
27
|
+
faraday.options[:timeout] = timeout if timeout > 0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Method overridden from HttpClient.
|
32
|
+
def execute_as_string(http_request)
|
33
|
+
response = @connection.send(
|
34
|
+
http_request.http_method.downcase,
|
35
|
+
http_request.query_url
|
36
|
+
) do |request|
|
37
|
+
request.headers = http_request.headers
|
38
|
+
unless http_request.http_method == HttpMethodEnum::GET &&
|
39
|
+
http_request.parameters.empty?
|
40
|
+
request.body = http_request.parameters
|
41
|
+
end
|
42
|
+
end
|
43
|
+
convert_response(response, http_request)
|
44
|
+
end
|
45
|
+
|
46
|
+
# Method overridden from HttpClient.
|
47
|
+
def execute_as_binary(http_request)
|
48
|
+
response = @connection.send(
|
49
|
+
http_request.http_method.downcase,
|
50
|
+
http_request.query_url
|
51
|
+
) do |request|
|
52
|
+
request.headers = http_request.headers
|
53
|
+
unless http_request.http_method == HttpMethodEnum::GET &&
|
54
|
+
http_request.parameters.empty?
|
55
|
+
request.body = http_request.parameters
|
56
|
+
end
|
57
|
+
end
|
58
|
+
convert_response(response, http_request)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Method overridden from HttpClient.
|
62
|
+
def convert_response(response, http_request)
|
63
|
+
HttpResponse.new(response.status, response.reason_phrase,
|
64
|
+
response.headers, response.body, http_request)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# ba_tester_with_custom_parameters
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module BaTesterWithCustomParameters
|
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
|
+
# ba_tester_with_custom_parameters
|
2
|
+
#
|
3
|
+
# This file was automatically generated by APIMATIC v2.0
|
4
|
+
# ( https://apimatic.io ).
|
5
|
+
|
6
|
+
module BaTesterWithCustomParameters
|
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
|