xbsryzmvon 1.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,76 @@
1
+ # xbsryzmvon
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Xbsryzmvon
7
+ # All configuration including auth info and base URI for the API access
8
+ # are configured in this class.
9
+ class Configuration
10
+ # Set the array parameter serialization method.
11
+ # (allowed: indexed, unindexed, plain, csv, tsv, psv)
12
+ @array_serialization = 'indexed'
13
+
14
+ # An enum for SDK environments.
15
+ class Environment
16
+ ENVIRONMENT = [PRODUCTION = 0, TESTING = 1].freeze
17
+ end
18
+
19
+ # An enum for API servers.
20
+ class Server
21
+ SERVER = [DEFAULT = 0, AUTH_SERVER = 1].freeze
22
+ end
23
+
24
+ # The environment in which the SDK is running.
25
+ @environment = Environment::TESTING
26
+
27
+ # TODO: Set an appropriate value.
28
+ @port = '80'
29
+
30
+ # TODO: Set an appropriate value.
31
+ @suites = SuiteCodeEnum::HEARTS
32
+
33
+ # The username to use with basic authentication
34
+ @basic_auth_user_name = 'TODO: Replace'
35
+
36
+ # The password to use with basic authentication
37
+ @basic_auth_password = 'TODO: Replace'
38
+
39
+ # All the environments the SDK can run in.
40
+ @environments = {
41
+ Environment::PRODUCTION => {
42
+ Server::DEFAULT => 'http://apimatic.hopto.org:{suites}',
43
+ Server::AUTH_SERVER => 'http://apimaticauth.hopto.org:3000'
44
+ },
45
+ Environment::TESTING => {
46
+ Server::DEFAULT => 'http://localhost:3000',
47
+ Server::AUTH_SERVER => 'http://apimaticauth.xhopto.org:3000'
48
+ }
49
+ }
50
+
51
+ # Generates the appropriate base URI for the environment and the server.
52
+ # @param [Configuration::Server] The server enum for which the base URI is
53
+ # required.
54
+ # @return [String] The base URI.
55
+ def self.get_base_uri(server = Server::DEFAULT)
56
+ parameters = {
57
+ 'port' => port,
58
+ 'suites' => suites
59
+ }
60
+ APIHelper.append_url_with_template_parameters(
61
+ environments[environment][server], parameters
62
+ )
63
+ end
64
+
65
+ # The attribute accessors for public properties.
66
+ class << self
67
+ attr_accessor :array_serialization
68
+ attr_accessor :environment
69
+ attr_accessor :environments
70
+ attr_accessor :port
71
+ attr_accessor :suites
72
+ attr_accessor :basic_auth_user_name
73
+ attr_accessor :basic_auth_password
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,40 @@
1
+ # xbsryzmvon
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Xbsryzmvon
7
+ # APIController
8
+ class APIController < BaseController
9
+ @instance = APIController.new
10
+
11
+ class << self
12
+ attr_accessor :instance
13
+ end
14
+
15
+ def instance
16
+ self.class.instance
17
+ end
18
+
19
+ # TODO: type endpoint description here
20
+ # @return String response from the API call
21
+ def get_basic_auth_test
22
+ # Prepare query url.
23
+ _path_url = '/auth/basic'
24
+ _query_builder = Configuration.get_base_uri
25
+ _query_builder << _path_url
26
+ _query_url = APIHelper.clean_url _query_builder
27
+
28
+ # Prepare and execute HttpRequest.
29
+ _request = @http_client.get(
30
+ _query_url
31
+ )
32
+ BasicAuth.apply(_request)
33
+ _context = execute_request(_request)
34
+ validate_response(_context)
35
+
36
+ # Return appropriate response type.
37
+ _context.response.raw_body
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,51 @@
1
+ # xbsryzmvon
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Xbsryzmvon
7
+ # Base controller.
8
+ class BaseController
9
+ attr_accessor :http_client, :http_call_back
10
+
11
+ def initialize(http_client: nil, http_call_back: nil)
12
+ @http_client = http_client || FaradayClient.new
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 = @global_headers.clone.merge(request.headers)
33
+
34
+ response = if binary
35
+ @http_client.execute_as_binary(request)
36
+ else
37
+ @http_client.execute_as_string(request)
38
+ end
39
+ context = HttpContext.new(request, response)
40
+
41
+ @http_call_back.on_after_response(context) if @http_call_back
42
+
43
+ context
44
+ end
45
+
46
+ def validate_response(context)
47
+ raise APIException.new 'HTTP Response Not OK', context unless
48
+ context.response.status_code.between?(200, 208) # [200,208] = HTTP OK
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,20 @@
1
+ # xbsryzmvon
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Xbsryzmvon
7
+ # Class for exceptions when there is a network error, status code error, etc.
8
+ class APIException < StandardError
9
+ attr_reader :context, :response_code
10
+
11
+ # The constructor.
12
+ # @param [String] The reason for raising an exception.
13
+ # @param [HttpContext] The HttpContext of the API call.
14
+ def initialize(reason, context)
15
+ super(reason)
16
+ @context = context
17
+ @response_code = context.response.status_code
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,22 @@
1
+ # xbsryzmvon
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require 'base64'
7
+
8
+ module Xbsryzmvon
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(http_request)
15
+ username = Configuration.basic_auth_user_name
16
+ password = Configuration.basic_auth_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,62 @@
1
+ # xbsryzmvon
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ require 'faraday/http_cache'
7
+
8
+ module Xbsryzmvon
9
+ # An implementation of HttpClient.
10
+ class FaradayClient < HttpClient
11
+ # The constructor.
12
+ def initialize(timeout: nil, cache: false,
13
+ max_retries: nil, retry_interval: nil)
14
+ @connection = Faraday.new do |faraday|
15
+ faraday.use Faraday::HttpCache, serializer: Marshal if cache
16
+ faraday.request :multipart
17
+ faraday.request :url_encoded
18
+ faraday.ssl[:ca_file] = Certifi.where
19
+ faraday.adapter Faraday.default_adapter
20
+ faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
21
+ faraday.options[:open_timeout] = timeout if timeout
22
+ faraday.request :retry, max: max_retries, interval: if max_retries &&
23
+ retry_interval
24
+ retry_interval
25
+ end
26
+ end
27
+ end
28
+
29
+ # Method overridden from HttpClient.
30
+ def execute_as_string(http_request)
31
+ response = @connection.send(
32
+ http_request.http_method.downcase,
33
+ http_request.query_url
34
+ ) do |request|
35
+ request.headers = http_request.headers
36
+ unless http_request.parameters.empty?
37
+ request.body = http_request.parameters
38
+ end
39
+ end
40
+ convert_response(response)
41
+ end
42
+
43
+ # Method overridden from HttpClient.
44
+ def execute_as_binary(http_request)
45
+ response = @connection.send(
46
+ http_request.http_method.downcase,
47
+ http_request.query_url
48
+ ) do |request|
49
+ request.headers = http_request.headers
50
+ unless http_request.parameters.empty?
51
+ request.body = http_request.parameters
52
+ end
53
+ end
54
+ convert_response(response)
55
+ end
56
+
57
+ # Method overridden from HttpClient.
58
+ def convert_response(response)
59
+ HttpResponse.new(response.status, response.headers, response.body)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,24 @@
1
+ # xbsryzmvon
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Xbsryzmvon
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 [HttpContext] The HttpContext of the API call.
19
+ def on_after_response(_http_context)
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
+ # xbsryzmvon
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Xbsryzmvon
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,20 @@
1
+ # xbsryzmvon
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Xbsryzmvon
7
+ # Represents an Http call in context.
8
+ class HttpContext
9
+ attr_accessor :request, :response
10
+
11
+ # The constructor.
12
+ # @param [HttpRequest] An HttpRequest object representing the HTTP request.
13
+ # @param [HttpResponse] An HttpResponse object representing the HTTP
14
+ # response.
15
+ def initialize(request, response)
16
+ @request = request
17
+ @response = response
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ # xbsryzmvon
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Xbsryzmvon
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