My-first-api-matic 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.
@@ -0,0 +1,34 @@
1
+ # youtube
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Youtube
7
+ # youtube 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: 2,
19
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
20
+ retry_methods: %i[get put],
21
+ environment: Environment::PRODUCTION, config: nil)
22
+ @config = if config.nil?
23
+ Configuration.new(timeout: timeout, max_retries: max_retries,
24
+ retry_interval: retry_interval,
25
+ backoff_factor: backoff_factor,
26
+ retry_statuses: retry_statuses,
27
+ retry_methods: retry_methods,
28
+ environment: environment)
29
+ else
30
+ config
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,110 @@
1
+ # youtube
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Youtube
7
+ # An enum for SDK environments.
8
+ class Environment
9
+ ENVIRONMENT = [
10
+ PRODUCTION = 'production'.freeze
11
+ ].freeze
12
+ end
13
+
14
+ # An enum for API servers.
15
+ class Server
16
+ SERVER = [
17
+ DEFAULT = 'default'.freeze
18
+ ].freeze
19
+ end
20
+
21
+ # All configuration including auth info and base URI for the API access
22
+ # are configured in this class.
23
+ class Configuration
24
+ # The attribute readers for properties.
25
+ attr_reader :http_client
26
+ attr_reader :timeout
27
+ attr_reader :max_retries
28
+ attr_reader :retry_interval
29
+ attr_reader :backoff_factor
30
+ attr_reader :retry_statuses
31
+ attr_reader :retry_methods
32
+ attr_reader :environment
33
+
34
+ class << self
35
+ attr_reader :environments
36
+ end
37
+
38
+ def initialize(timeout: 60, max_retries: 0, retry_interval: 1,
39
+ backoff_factor: 2,
40
+ retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
41
+ retry_methods: %i[get put],
42
+ environment: Environment::PRODUCTION)
43
+ # The value to use for connection timeout
44
+ @timeout = timeout
45
+
46
+ # The number of times to retry an endpoint call if it fails
47
+ @max_retries = max_retries
48
+
49
+ # Pause in seconds between retries
50
+ @retry_interval = retry_interval
51
+
52
+ # The amount to multiply each successive retry's interval amount
53
+ # by in order to provide backoff
54
+ @backoff_factor = backoff_factor
55
+
56
+ # A list of HTTP statuses to retry
57
+ @retry_statuses = retry_statuses
58
+
59
+ # A list of HTTP methods to retry
60
+ @retry_methods = retry_methods
61
+
62
+ # Current API environment
63
+ @environment = String(environment)
64
+
65
+ # The Http Client to use for making requests.
66
+ @http_client = create_http_client
67
+ end
68
+
69
+ def clone_with(timeout: nil, max_retries: nil, retry_interval: nil,
70
+ backoff_factor: nil, retry_statuses: nil, retry_methods: nil,
71
+ environment: nil)
72
+ timeout ||= self.timeout
73
+ max_retries ||= self.max_retries
74
+ retry_interval ||= self.retry_interval
75
+ backoff_factor ||= self.backoff_factor
76
+ retry_statuses ||= self.retry_statuses
77
+ retry_methods ||= self.retry_methods
78
+ environment ||= self.environment
79
+
80
+ Configuration.new(timeout: timeout, max_retries: max_retries,
81
+ retry_interval: retry_interval,
82
+ backoff_factor: backoff_factor,
83
+ retry_statuses: retry_statuses,
84
+ retry_methods: retry_methods, environment: environment)
85
+ end
86
+
87
+ def create_http_client
88
+ FaradayClient.new(timeout: timeout, max_retries: max_retries,
89
+ retry_interval: retry_interval,
90
+ backoff_factor: backoff_factor,
91
+ retry_statuses: retry_statuses,
92
+ retry_methods: retry_methods)
93
+ end
94
+
95
+ # All the environments the SDK can run in.
96
+ ENVIRONMENTS = {
97
+ Environment::PRODUCTION => {
98
+ Server::DEFAULT => 'https://localhost:5001'
99
+ }
100
+ }.freeze
101
+
102
+ # Generates the appropriate base URI for the environment and the server.
103
+ # @param [Configuration::Server] The server enum for which the base URI is
104
+ # required.
105
+ # @return [String] The base URI.
106
+ def get_base_uri(server = Server::DEFAULT)
107
+ ENVIRONMENTS[environment][server].clone
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,59 @@
1
+ # youtube
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Youtube
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
+ # get list of 5 random forcasts
14
+ # @param [String] param Optional parameter: default string parameter
15
+ # @return [Mixed] response from the API call
16
+ def get_forcast(param: 'String.Empty')
17
+ # Prepare query url.
18
+ _query_builder = config.get_base_uri(Server::DEFAULT)
19
+ _query_builder << '/WeatherForecast'
20
+ _query_builder = APIHelper.append_url_with_query_parameters(
21
+ _query_builder,
22
+ 'param' => param
23
+ )
24
+ _query_url = APIHelper.clean_url _query_builder
25
+
26
+ # Prepare headers.
27
+ _headers = {
28
+ 'accept' => 'application/json'
29
+ }
30
+
31
+ # Prepare and execute HttpRequest.
32
+ _request = config.http_client.get(
33
+ _query_url,
34
+ headers: _headers
35
+ )
36
+ _response = execute_request(_request)
37
+
38
+ # Validate response against endpoint and global error codes.
39
+ if _response.status_code == 400
40
+ raise ProblemDetailsException.new(
41
+ 'Test error message',
42
+ _response
43
+ )
44
+ elsif _response.status_code == 404
45
+ raise APIException.new(
46
+ 'not found',
47
+ _response
48
+ )
49
+ end
50
+ validate_response(_response)
51
+
52
+ # Return appropriate response type.
53
+ decoded = APIHelper.json_deserialize(_response.raw_body) unless
54
+ _response.raw_body.nil? ||
55
+ _response.raw_body.to_s.strip.empty?
56
+ decoded
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,55 @@
1
+ # youtube
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Youtube
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
+ if response.status_code == 401
46
+ raise ProblemDetailsException.new(
47
+ 'dfgdfgdfgdfgdsfg',
48
+ response
49
+ )
50
+ end
51
+ raise APIException.new 'HTTP Response Not OK', response unless
52
+ response.status_code.between?(200, 208) # [200,208] = HTTP OK
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,20 @@
1
+ # youtube
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Youtube
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,44 @@
1
+ # youtube
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Youtube
7
+ # ProblemDetails class.
8
+ class ProblemDetailsException < APIException
9
+ # TODO: Write general description for this method
10
+ # @return [String]
11
+ attr_reader :type
12
+
13
+ # TODO: Write general description for this method
14
+ # @return [String]
15
+ attr_reader :title
16
+
17
+ # TODO: Write general description for this method
18
+ # @return [Integer]
19
+ attr_reader :status
20
+
21
+ # TODO: Write general description for this method
22
+ # @return [String]
23
+ attr_reader :trace_id
24
+
25
+ # The constructor.
26
+ # @param [String] The reason for raising an exception.
27
+ # @param [HttpResponse] The HttpReponse of the API call.
28
+ def initialize(reason, response)
29
+ super(reason, response)
30
+ hash = APIHelper.json_deserialize(@response.raw_body)
31
+ unbox(hash)
32
+ end
33
+
34
+ # Populates this object by extracting properties from a hash.
35
+ # @param [Hash] The deserialized response sent by the server in the
36
+ # response body.
37
+ def unbox(hash)
38
+ @type = hash['type']
39
+ @title = hash['title']
40
+ @status = hash['status']
41
+ @trace_id = hash['traceId']
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,70 @@
1
+ # youtube
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 Youtube
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
+ cache: false, verify: true)
16
+ @connection = Faraday.new do |faraday|
17
+ faraday.use Faraday::HttpCache, serializer: Marshal if cache
18
+ faraday.use FaradayMiddleware::FollowRedirects
19
+ faraday.use :gzip
20
+ faraday.request :multipart
21
+ faraday.request :url_encoded
22
+ faraday.ssl[:ca_file] = Certifi.where
23
+ faraday.ssl[:verify] = verify
24
+ faraday.request :retry, max: max_retries, interval: retry_interval,
25
+ backoff_factor: backoff_factor,
26
+ retry_statuses: retry_statuses,
27
+ methods: retry_methods
28
+ faraday.adapter Faraday.default_adapter
29
+ faraday.options[:params_encoder] = Faraday::FlatParamsEncoder
30
+ faraday.options[:timeout] = timeout if timeout > 0
31
+ end
32
+ end
33
+
34
+ # Method overridden from HttpClient.
35
+ def execute_as_string(http_request)
36
+ response = @connection.send(
37
+ http_request.http_method.downcase,
38
+ http_request.query_url
39
+ ) do |request|
40
+ request.headers = http_request.headers
41
+ unless http_request.http_method == HttpMethodEnum::GET &&
42
+ http_request.parameters.empty?
43
+ request.body = http_request.parameters
44
+ end
45
+ end
46
+ convert_response(response, http_request)
47
+ end
48
+
49
+ # Method overridden from HttpClient.
50
+ def execute_as_binary(http_request)
51
+ response = @connection.send(
52
+ http_request.http_method.downcase,
53
+ http_request.query_url
54
+ ) do |request|
55
+ request.headers = http_request.headers
56
+ unless http_request.http_method == HttpMethodEnum::GET &&
57
+ http_request.parameters.empty?
58
+ request.body = http_request.parameters
59
+ end
60
+ end
61
+ convert_response(response, http_request)
62
+ end
63
+
64
+ # Method overridden from HttpClient.
65
+ def convert_response(response, http_request)
66
+ HttpResponse.new(response.status, response.reason_phrase,
67
+ response.headers, response.body, http_request)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,24 @@
1
+ # youtube
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Youtube
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
+ # youtube
2
+ #
3
+ # This file was automatically generated by APIMATIC v2.0
4
+ # ( https://apimatic.io ).
5
+
6
+ module Youtube
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