commerce 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.
@@ -0,0 +1,11 @@
1
+ # This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ module Commerce
4
+ class CustomHeaderAuth
5
+ # Add custom authentication to the request.
6
+ # @param [HttpRequest] The HttpRequest object to which authentication will be added.
7
+ def self.apply(http_request)
8
+ http_request.add_header("X-Authorization", Commerce.api_key)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,41 @@
1
+ # This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ module Commerce
4
+ class FaradayClient < HttpClient
5
+ # The constructor.
6
+ def initialize(timeout)
7
+ @connection = Faraday.new do |faraday|
8
+ faraday.request :multipart
9
+ faraday.request :url_encoded
10
+ faraday.ssl[:ca_file] = Certifi.where
11
+ faraday.adapter Faraday.default_adapter
12
+ faraday.options[:open_timeout] = timeout
13
+ end
14
+ end
15
+
16
+ # Method overridden from HttpClient.
17
+ def execute_as_string(http_request)
18
+ response = @connection.send(http_request.http_method.downcase, http_request.query_url) do |request|
19
+ request.headers = http_request.headers
20
+ request.body = http_request.parameters
21
+ end
22
+
23
+ return convert_response(response)
24
+ end
25
+
26
+ # Method overridden from HttpClient.
27
+ def execute_as_binary(http_request)
28
+ response = @connection.send(http_request.http_method.downcase, http_request.query_url) do |request|
29
+ request.headers = http_request.headers
30
+ request.body = http_request.parameters
31
+ end
32
+
33
+ return convert_response(response)
34
+ end
35
+
36
+ # Method overridden from HttpClient.
37
+ def convert_response(response)
38
+ return HttpResponse.new(response.status, response.headers, response.body)
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ # This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ module Commerce
4
+ class HttpCallBack
5
+ # A controller will call this method before making an HTTP Request.
6
+ # @param [HttpRequest] The HttpRequest object which the HttpClient will execute.
7
+ def on_before_request(http_request)
8
+ raise NotImplementedError, "This method needs to be implemented in a child class."
9
+ end
10
+
11
+ # A controller will call this method after making an HTTP Request.
12
+ # @param [HttpContext] The HttpContext of the API call.
13
+ def on_after_response(http_context)
14
+ raise NotImplementedError, "This method needs to be implemented in a child class."
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,82 @@
1
+ # This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ module Commerce
4
+ class HttpClient
5
+ # Execute an HttpRequest when the response is expected to be a string.
6
+ # @param [HttpRequest] The HttpRequest to be executed.
7
+ def execute_as_string(http_request)
8
+ raise NotImplementedError, "This method needs to be implemented in a child class."
9
+ end
10
+
11
+ # Execute an HttpRequest when the response is expected to be binary.
12
+ # @param [HttpRequest] The HttpRequest to be executed.
13
+ def execute_as_binary(http_request)
14
+ raise NotImplementedError, "This method needs to be implemented in a child class."
15
+ end
16
+
17
+ # Converts the HTTP Response from the client to an HttpResponse object.
18
+ # @param [Dynamic] The response object received from the client.
19
+ def convert_response(response)
20
+ raise NotImplementedError, "This method needs to be implemented in a child class."
21
+ end
22
+
23
+ # Get a GET HttpRequest object.
24
+ # @param [String] The URL to send the request to.
25
+ # @param [Hash, Optional] The headers for the HTTP Request.
26
+ def GET(query_url,
27
+ headers: {})
28
+ return HttpRequest.new(HttpMethodEnum::GET,
29
+ query_url,
30
+ headers: headers)
31
+ end
32
+
33
+ # Get a POST 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 parameters for the HTTP Request.
37
+ def POST(query_url,
38
+ headers: {},
39
+ parameters: {})
40
+ return HttpRequest.new(HttpMethodEnum::POST,
41
+ query_url,
42
+ headers: headers,
43
+ parameters: parameters)
44
+ end
45
+
46
+ # Get a PUT 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 parameters for the HTTP Request.
50
+ def PUT(query_url,
51
+ headers: {},
52
+ parameters: {})
53
+ return HttpRequest.new(HttpMethodEnum::PUT,
54
+ query_url,
55
+ headers: headers,
56
+ parameters: parameters)
57
+ end
58
+
59
+ # Get a PATCH 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
+ def PATCH(query_url,
64
+ headers: {},
65
+ parameters: {})
66
+ return HttpRequest.new(HttpMethodEnum::PATCH,
67
+ query_url,
68
+ headers: headers,
69
+ parameters: parameters)
70
+ end
71
+
72
+ # Get a DELETE HttpRequest object.
73
+ # @param [String] The URL to send the request to.
74
+ # @param [Hash, Optional] The headers for the HTTP Request.
75
+ def DELETE(query_url,
76
+ headers: {})
77
+ return HttpRequest.new(HttpMethodEnum::DELETE,
78
+ query_url,
79
+ headers: headers)
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,15 @@
1
+ # This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ module Commerce
4
+ class HttpContext
5
+ attr_accessor :request, :response
6
+
7
+ # The constructor.
8
+ # @param [HttpRequest] An HttpRequest object representing the HTTP request.
9
+ # @param [HttpResponse] An HttpResponse object representing the HTTP response.
10
+ def initialize(request, response)
11
+ @request = request
12
+ @response = response
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ # This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ module Commerce
4
+ class HttpMethodEnum
5
+ HTTPMETHODENUM = [GET = "GET", POST = "POST", PUT = "PUT", PATCH = "PATCH", DELETE = "DELETE"]
6
+ end
7
+ end
@@ -0,0 +1,44 @@
1
+ # This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ module Commerce
4
+ class HttpRequest
5
+ attr_accessor :http_method, :query_url, :headers, :parameters, :username, :password
6
+
7
+ # The constructor.
8
+ # @param [HttpMethodEnum] The HTTP method.
9
+ # @param [String] The URL to send the request to.
10
+ # @param [Hash, Optional] The headers for the HTTP Request.
11
+ # @param [Hash, Optional] The parameters for the HTTP Request.
12
+ def initialize(http_method,
13
+ query_url,
14
+ headers: {},
15
+ parameters: {})
16
+ @http_method = http_method
17
+ @query_url = query_url
18
+ @headers = headers
19
+ @parameters = parameters
20
+ end
21
+
22
+ # Add a header to the HttpRequest.
23
+ # @param [String] The name of the header.
24
+ # @param [String] The value of the header.
25
+ def add_header(name, value)
26
+ @headers[name] = value
27
+ end
28
+
29
+ # Add a parameter to the HttpRequest.
30
+ # @param [String] The name of the parameter.
31
+ # @param [String] The value of the parameter.
32
+ def add_parameter(name, value)
33
+ @parameters[name] = value
34
+ end
35
+
36
+ # Add a query parameter to the HttpRequest.
37
+ # @param [String] The name of the query parameter.
38
+ # @param [String] The value of the query parameter.
39
+ def add_query_parameter(name, value)
40
+ @query_url = APIHelper.append_url_with_query_parameters(@query_url, {name => value})
41
+ @query_url = APIHelper.clean_url(@query_url)
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,21 @@
1
+ # This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
2
+
3
+ module Commerce
4
+ class HttpResponse
5
+ attr_accessor :status_code, :headers, :raw_body, :array
6
+
7
+ # The constructor.
8
+ # @param [Integer] The status code returned by the server.
9
+ # @param [Hash] The headers sent by the server in the response.
10
+ # @param [String] The raw body of the response.
11
+ def initialize(status_code,
12
+ headers,
13
+ raw_body)
14
+ @status_code = status_code
15
+ @headers = headers
16
+ @raw_body = raw_body
17
+ @array = JSON.parse(raw_body.strip)
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,113 @@
1
+ module Commerce
2
+ class Order < BaseController
3
+
4
+ def self.all( _query_parameters = [])
5
+
6
+ _query_builder = Commerce.api_base.dup
7
+ _query_builder << '/orders'
8
+
9
+
10
+ _query_builder = APIHelper.append_url_with_query_parameters _query_builder, _query_parameters
11
+
12
+ _query_url = APIHelper.clean_url _query_builder
13
+
14
+
15
+ _request = @@http_client.GET _query_url
16
+
17
+ CustomHeaderAuth.apply(_request)
18
+
19
+ _request.headers = @@global_headers.clone.merge(_request.headers)
20
+
21
+ _response = @@http_client.execute_as_string(_request)
22
+
23
+ context = HttpContext.new(_request, _response)
24
+
25
+ return context.response.array
26
+
27
+ end
28
+
29
+ def self.fulfillment(id, _query_parameters = [])
30
+
31
+ _query_builder = Commerce.api_base.dup
32
+ _query_builder << '/orders/{id}/fulfillment'
33
+
34
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
35
+ 'id' => id
36
+ }
37
+
38
+
39
+ _query_url = APIHelper.clean_url _query_builder
40
+
41
+
42
+ _request = @@http_client.GET _query_url
43
+
44
+ CustomHeaderAuth.apply(_request)
45
+
46
+ _request.headers = @@global_headers.clone.merge(_request.headers)
47
+
48
+ _response = @@http_client.execute_as_string(_request)
49
+
50
+ context = HttpContext.new(_request, _response)
51
+
52
+ return context.response.array
53
+
54
+ end
55
+
56
+ def self.payments(id, _query_parameters = [])
57
+
58
+ _query_builder = Commerce.api_base.dup
59
+ _query_builder << '/orders/{id}/payments'
60
+
61
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
62
+ 'id' => id
63
+ }
64
+
65
+
66
+ _query_url = APIHelper.clean_url _query_builder
67
+
68
+
69
+ _request = @@http_client.GET _query_url
70
+
71
+ CustomHeaderAuth.apply(_request)
72
+
73
+ _request.headers = @@global_headers.clone.merge(_request.headers)
74
+
75
+ _response = @@http_client.execute_as_string(_request)
76
+
77
+ context = HttpContext.new(_request, _response)
78
+
79
+ return context.response.array
80
+
81
+ end
82
+
83
+ def self.receipt(id, _query_parameters = [])
84
+
85
+ _query_builder = Commerce.api_base.dup
86
+ _query_builder << '/orders/{id}/receipt'
87
+
88
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
89
+ 'id' => id
90
+ }
91
+
92
+
93
+ _query_url = APIHelper.clean_url _query_builder
94
+
95
+
96
+ _request = @@http_client.GET _query_url
97
+
98
+ CustomHeaderAuth.apply(_request)
99
+
100
+ _request.headers = @@global_headers.clone.merge(_request.headers)
101
+
102
+ _response = @@http_client.execute_as_string(_request)
103
+
104
+ context = HttpContext.new(_request, _response)
105
+
106
+ return context.response.array
107
+
108
+ end
109
+
110
+
111
+ end
112
+
113
+ end
@@ -0,0 +1,60 @@
1
+ module Commerce
2
+ class Product < BaseController
3
+
4
+ def self.all( _query_parameters = [])
5
+
6
+ _query_builder = Commerce.api_base.dup
7
+ _query_builder << '/products'
8
+
9
+
10
+ _query_builder = APIHelper.append_url_with_query_parameters _query_builder, _query_parameters
11
+
12
+ _query_url = APIHelper.clean_url _query_builder
13
+
14
+
15
+ _request = @@http_client.GET _query_url
16
+
17
+ CustomHeaderAuth.apply(_request)
18
+
19
+ _request.headers = @@global_headers.clone.merge(_request.headers)
20
+
21
+ _response = @@http_client.execute_as_string(_request)
22
+
23
+ context = HttpContext.new(_request, _response)
24
+
25
+ return context.response.array
26
+
27
+ end
28
+
29
+ def self.retrieve(identifier, _query_parameters = [])
30
+
31
+ _query_builder = Commerce.api_base.dup
32
+ _query_builder << '/products/{identifier}'
33
+
34
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
35
+ 'identifier' => identifier
36
+ }
37
+
38
+ _query_builder = APIHelper.append_url_with_query_parameters _query_builder, _query_parameters
39
+
40
+ _query_url = APIHelper.clean_url _query_builder
41
+
42
+
43
+ _request = @@http_client.GET _query_url
44
+
45
+ CustomHeaderAuth.apply(_request)
46
+
47
+ _request.headers = @@global_headers.clone.merge(_request.headers)
48
+
49
+ _response = @@http_client.execute_as_string(_request)
50
+
51
+ context = HttpContext.new(_request, _response)
52
+
53
+ return context.response.array
54
+
55
+ end
56
+
57
+
58
+ end
59
+
60
+ end
@@ -0,0 +1,85 @@
1
+ module Commerce
2
+ class Service < BaseController
3
+
4
+ def self.locale_list_countries( _query_parameters = [])
5
+
6
+ _query_builder = Commerce.api_base.dup
7
+ _query_builder << '/services/locale/countries'
8
+
9
+
10
+
11
+ _query_url = APIHelper.clean_url _query_builder
12
+
13
+
14
+ _request = @@http_client.GET _query_url
15
+
16
+ CustomHeaderAuth.apply(_request)
17
+
18
+ _request.headers = @@global_headers.clone.merge(_request.headers)
19
+
20
+ _response = @@http_client.execute_as_string(_request)
21
+
22
+ context = HttpContext.new(_request, _response)
23
+
24
+ return context.response.array
25
+
26
+ end
27
+
28
+ def self.locale_list_shipping_countries(checkout_token_id, _query_parameters = [])
29
+
30
+ _query_builder = Commerce.api_base.dup
31
+ _query_builder << '/services/locale/{checkout_token_id}/countries'
32
+
33
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
34
+ 'checkout_token_id' => checkout_token_id
35
+ }
36
+
37
+
38
+ _query_url = APIHelper.clean_url _query_builder
39
+
40
+
41
+ _request = @@http_client.GET _query_url
42
+
43
+ CustomHeaderAuth.apply(_request)
44
+
45
+ _request.headers = @@global_headers.clone.merge(_request.headers)
46
+
47
+ _response = @@http_client.execute_as_string(_request)
48
+
49
+ context = HttpContext.new(_request, _response)
50
+
51
+ return context.response.array
52
+
53
+ end
54
+
55
+ def self.locale_list_subdivisions(country_code, _query_parameters = [])
56
+
57
+ _query_builder = Commerce.api_base.dup
58
+ _query_builder << '/services/locale/{country_code}/subdivisions'
59
+
60
+ _query_builder = APIHelper.append_url_with_template_parameters _query_builder, {
61
+ 'country_code' => country_code
62
+ }
63
+
64
+
65
+ _query_url = APIHelper.clean_url _query_builder
66
+
67
+
68
+ _request = @@http_client.GET _query_url
69
+
70
+ CustomHeaderAuth.apply(_request)
71
+
72
+ _request.headers = @@global_headers.clone.merge(_request.headers)
73
+
74
+ _response = @@http_client.execute_as_string(_request)
75
+
76
+ context = HttpContext.new(_request, _response)
77
+
78
+ return context.response.array
79
+
80
+ end
81
+
82
+
83
+ end
84
+
85
+ end