beyond_api 0.10.0.pre → 0.13.0.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70c9bf9ccb3e7a42a71c8d5a092e0af6969842daf91a7219398b9f5516836cfe
4
- data.tar.gz: d976cda9fdcc8df93394b3b9ad678453db3634a096c6832208e8fe49c917198b
3
+ metadata.gz: be322cd30437303093e481de07cd8e3b8809c381d835b778ca03eccf66f7326f
4
+ data.tar.gz: 432767a471613ab986f3ca19c5c8c002673711bea0c71ec0c8048fbf4f8cc50e
5
5
  SHA512:
6
- metadata.gz: 94e86e146eb7ed0696efbb7bf7a61e1ade093ba00571ef140e0fb019c6708680d8a26b3b0bc8295e3f30a1327b362b44b0b56b7b474973a975fd212e61317c90
7
- data.tar.gz: 68cc2ad0ec1a9d855dc22c52ca4b5f9a1a76af244eeccc406bb7e384b72267c476f99db47652b34653a9d297836e7637ac9856e60eab09961eec7ea6e8733688
6
+ metadata.gz: f8a52e79a30aa30c85388b0d0d034fd49e35ce4896eef7ae0b51316aa7a3c1081ef3b9b564b1ec798be8af4af44d04b6bcefc226579b44138a98d1b463e23a65
7
+ data.tar.gz: 98be15b4608be4c35f0e9511cde6f824a2dfd97a292c92e62a24f2980750464a62952e4d84852c367df3258a7bc8036434162252e40993b089fa8fa72ca11dec
@@ -1,3 +1,43 @@
1
+ ### v0.13.0.pre
2
+
3
+ * features
4
+ * Add payment method definitions methods
5
+ * `PaymentMethodDefinitions#all`
6
+ * `PaymentMethodDefinitions#create`
7
+ * `PaymentMethodDefinitions#delete`
8
+ * `PaymentMethodDefinitions#find`
9
+ * `PaymentMethodDefinitions#update`
10
+ * Add possibility to log request `headers` and `bodies`
11
+
12
+ ### v0.12.1.pre
13
+
14
+ * bug-fixes
15
+ * Fix camelize function for hashes containing arrays
16
+
17
+ ### v0.12.0.pre
18
+
19
+ * features
20
+ * Add locations methods
21
+ * `Locations#all`
22
+ * `Locations#create`
23
+ * `Locations#delete`
24
+ * `Locations#find`
25
+ * `Locations#update`
26
+
27
+ * enhancements
28
+ * Use `autoload` instead of `require`
29
+
30
+ ### v0.11.1.pre
31
+
32
+ * bug-fixes
33
+ * Use `BeyondApi::Error` for authentication errors
34
+
35
+ ### v0.11.0.pre
36
+
37
+ * enhancements
38
+ * Improve error handling class
39
+ * Improve `BeyondApi::Error` class
40
+
1
41
  ### v0.10.0.pre
2
42
 
3
43
  * features
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beyond_api (0.10.0.pre)
4
+ beyond_api (0.13.0.pre)
5
5
  faraday (~> 0.15)
6
6
 
7
7
  GEM
@@ -1,23 +1,18 @@
1
1
  require "beyond_api/version"
2
2
 
3
- require "beyond_api/connection"
4
- require "beyond_api/request"
5
- require "beyond_api/session"
6
- require "beyond_api/error"
3
+ require "logger"
7
4
 
8
5
  require "beyond_api/ext"
9
6
  require "beyond_api/utils"
10
7
 
11
- require "logger"
12
-
13
8
  module BeyondApi
14
- def self.logger
15
- @@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
16
- end
9
+ autoload :Connection, "beyond_api/connection"
10
+ autoload :Error, "beyond_api/error"
11
+ autoload :Logger, "beyond_api/logger"
12
+ autoload :Request, "beyond_api/request"
13
+ autoload :Session, "beyond_api/session"
17
14
 
18
- def self.logger=(logger)
19
- @@logger = logger
20
- end
15
+ extend BeyondApi::Logger
21
16
 
22
17
  class << self
23
18
  attr_accessor :configuration
@@ -31,7 +26,8 @@ module BeyondApi
31
26
 
32
27
  class Configuration
33
28
  attr_accessor :client_id, :client_secret, :open_timeout, :timeout, :remove_response_links,
34
- :remove_response_key_underscores, :object_struct_responses, :raise_error_requests
29
+ :remove_response_key_underscores, :object_struct_responses, :raise_error_requests,
30
+ :log_headers, :log_bodies, :log_level
35
31
 
36
32
  def initialize
37
33
  @client_id = nil
@@ -42,6 +38,10 @@ module BeyondApi
42
38
  @remove_response_key_underscores = false
43
39
  @object_struct_responses = false
44
40
  @raise_error_requests = false
41
+
42
+ @log_level = :info
43
+ @log_headers = false
44
+ @log_bodies = false
45
45
  end
46
46
  end
47
47
  end
@@ -4,10 +4,15 @@ require 'faraday'
4
4
 
5
5
  module BeyondApi
6
6
  class Connection
7
+ LOGGER = ::BeyondApi.logger
8
+ LOGGER.level = Kernel.const_get("::Logger::#{BeyondApi.configuration.log_level.to_s.upcase}")
9
+
7
10
  def self.default
8
11
  Faraday.new(ssl: { verify: true }) do |faraday|
9
12
  faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
10
13
  faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
14
+ faraday.response :logger, LOGGER, { headers: BeyondApi.configuration.log_headers,
15
+ bodies: BeyondApi.configuration.log_bodies }
11
16
  faraday.headers['Accept'] = 'application/json'
12
17
  faraday.headers['Content-Type'] = 'application/json'
13
18
  faraday.request(:multipart)
@@ -20,6 +25,8 @@ module BeyondApi
20
25
  Faraday.new(ssl: { verify: true }) do |faraday|
21
26
  faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
22
27
  faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
28
+ faraday.response :logger, LOGGER, { headers: BeyondApi.configuration.log_headers,
29
+ bodies: BeyondApi.configuration.log_bodies }
23
30
  faraday.headers['Accept'] = 'application/json'
24
31
  faraday.adapter(:net_http)
25
32
  faraday.basic_auth(BeyondApi.configuration.client_id,
@@ -1,14 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BeyondApi
4
- class Error
5
- attr_reader :error_id, :details, :message, :trace_id
4
+ class Error < StandardError
5
+ attr_reader :error_id, :details, :trace_id, :full_message, :status_code, :error, :error_description
6
6
 
7
- def initialize(data)
8
- @error_id = data['errorId']
9
- @details = data['details']
10
- @message = data['message']
11
- @trace_id = data['traceId']
7
+ def initialize(data, status_code = nil)
8
+ @error_id = data['errorId']
9
+ @details = data['details']
10
+ @trace_id = data['traceId']
11
+ @error = data['error']
12
+ @error_description = data['error_description']
13
+ @full_message = data
14
+ @status_code = status_code
15
+
16
+ super(data['message'] || data['error_description'])
12
17
  end
13
18
  end
14
19
  end
@@ -4,7 +4,14 @@ class Hash
4
4
  def deep_transform_keys(&block)
5
5
  result = {}
6
6
  each do |key, value|
7
- result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value
7
+ result[yield(key)] = case value
8
+ when Hash
9
+ value.deep_transform_keys(&block)
10
+ when Array
11
+ value.camelize_keys
12
+ else
13
+ value
14
+ end
8
15
  end
9
16
  result
10
17
  end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BeyondApi
4
+ module Logger
5
+ def logger
6
+ @@logger ||= defined?(Rails) ? ::Rails.logger : ::Logger.new($stdout)
7
+ end
8
+
9
+ def logger=(logger)
10
+ @@logger = logger
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,175 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "beyond_api/utils"
4
+
5
+ module BeyondApi
6
+ class PaymentMethodDefinitions < Base
7
+ include BeyondApi::Utils
8
+
9
+ #
10
+ # A +POST+ request is used to create a payment method definition on system level.
11
+ #
12
+ # $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions' -i -X POST \
13
+ # -H 'Content-Type: application/json' \
14
+ # -H 'Accept: application/hal+json' \
15
+ # -H 'Authorization: Bearer <Access token>' \
16
+ # -d '{
17
+ # "name": "credit-card",
18
+ # "referralUriTemplate": "https://example.com/merchants",
19
+ # "statusUriTemplate": "https://example.com/merchants/{shopId}/status",
20
+ # "disconnectUriTemplate": "https://example.com/merchants/{shopId}/disconnect",
21
+ # "createPaymentUriTemplate": "https://example.com/payments",
22
+ # "capturePaymentUriTemplate": "https://example.com/payments/{paymentId}/capture",
23
+ # "refundPaymentUriTemplate": "https://example.com/payments/{paymentId}/refund",
24
+ # "sandbox": "true",
25
+ # "workflow": "PAYMENT_ON_BUY",
26
+ # "captureWorkflow": "CAPTURE_ON_ORDER",
27
+ # "refund": "NO_REFUND",
28
+ # "logos": [{
29
+ # "setName" : "official",
30
+ # "variant" : "STOREFRONT",
31
+ # "uri" : "https://example.com/static/storefront.png"
32
+ # }],
33
+ # "officialName": {"de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
34
+ # "en-US" : "Allow your customers to pay by credit card."
35
+ # },
36
+ # "officialDescription": {
37
+ # "de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
38
+ # "en-US" : "Allow your customers to pay by credit card."
39
+ # },
40
+ # "defaultName": {
41
+ # "de-DE" : "Kreditkarte",
42
+ # "en-US" : "Credit card"
43
+ # },
44
+ # "defaultDescription": {"de-DE" : "Bezahlen Sie mit Kreditkarte.","en-US" : "Pay by credit card."}}'
45
+ #
46
+ # @beyond_api.scopes +paym:m+
47
+ #
48
+ # @param body [Hash] the request body
49
+ #
50
+ # @return [OpenStruct]
51
+ #
52
+ # @example
53
+ # @payment_method_definitions = session.payment_method_definitions.create(body)
54
+ #
55
+ def create(body)
56
+ response, status = BeyondApi::Request.post(@session, "/payment-method-definitions", body)
57
+
58
+ handle_response(response, status)
59
+ end
60
+
61
+ #
62
+ # A +GET+ request is used to list all payment method definitions on system level.
63
+ #
64
+ # $ curl 'https://api-shop.beyondshop.cloud/api/payment-method-definitions' -i -X GET \
65
+ # -H 'Accept: application/hal+json' \
66
+ # -H 'Authorization: Bearer <Access token>'
67
+ #
68
+ # @beyond_api.scopes +paym:m+
69
+ #
70
+ # @option params [Boolean] :paginated
71
+ # @option params [Integer] :size the page size
72
+ # @option params [Integer] :page the page number
73
+ #
74
+ # @return [OpenStruct]
75
+ #
76
+ # @example
77
+ # @payment_method_definitions = session.payment_method_definitions.all(size: 100, page: 0)
78
+ #
79
+ def all(params = {})
80
+ handle_all_request("/payment-method-definitions", :payment_method_definitions, params)
81
+ end
82
+
83
+ #
84
+ # A +GET+ request is used to deactivate a payment method.
85
+ #
86
+ # $ curl 'https://api-shop.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X GET \
87
+ # -H 'Accept: application/hal+json' \
88
+ # -H 'Authorization: Bearer <Access token>'
89
+ #
90
+ # @beyond_api.scopes +pymt:u+
91
+ #
92
+ # @param payment_method_definition_id [String] the payment method definition UUID
93
+ #
94
+ # @return [OpenStruct]
95
+ #
96
+ # @example
97
+ # @payment_method_definition = session.payment_methods.find("credit-card")
98
+ #
99
+ def find(payment_method_definition_id)
100
+ response, status = BeyondApi::Request.get(@session, "/payment-method-definitions/#{payment_method_definition_id}")
101
+
102
+ handle_response(response, status)
103
+ end
104
+
105
+ #
106
+ # A +PUT+ request is used to update a payment method definition on system level.
107
+ #
108
+ # $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X PUT \
109
+ # -H 'Content-Type: application/json' \
110
+ # -H 'Accept: application/hal+json' \
111
+ # -H 'Authorization: Bearer <Access token>' \
112
+ # -d '{
113
+ # "name": "credit-card-updated",
114
+ # "referralUriTemplate": "https://example.com/merchants",
115
+ # "statusUriTemplate": "https://example.com/merchants/{shopId}/status",
116
+ # "disconnectUriTemplate": "https://example.com/merchants/{shopId}/disconnect",
117
+ # "createPaymentUriTemplate": "https://example.com/payments",
118
+ # "capturePaymentUriTemplate": "https://example.com/payments/{paymentId}/capture",
119
+ # "refundPaymentUriTemplate": "https://example.com/payments/{paymentId}/refund",
120
+ # "workflow": "PAYMENT_ON_SELECTION",
121
+ # "captureWorkflow": "CAPTURE_ON_DEMAND",
122
+ # "refund": "NO_REFUND",
123
+ # "logos": [{
124
+ # "setName" : "official",
125
+ # "variant" : "STOREFRONT",
126
+ # "uri" : "https://example.com/static/storefront.png"
127
+ # }],
128
+ # "officialName": {"de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
129
+ # "en-US" : "Allow your customers to pay by credit card."
130
+ # },
131
+ # "officialDescription": {
132
+ # "de-DE" : "Ermögliche deinen Kunden, mit Kreditkarte zu bezahlen.",
133
+ # "en-US" : "Allow your customers to pay by credit card."
134
+ # },
135
+ # "defaultName": {
136
+ # "de-DE" : "Kreditkarte",
137
+ # "en-US" : "Credit card"
138
+ # },
139
+ # "defaultDescription": {"de-DE" : "Bezahlen Sie mit Kreditkarte.","en-US" : "Pay by credit card."}}'
140
+ #
141
+ # @beyond_api.scopes +paym:m+
142
+ #
143
+ # @param payment_method_definition_id [String] the payment method definition UUID
144
+ # @param body [Hash] the request body
145
+ #
146
+ # @return [OpenStruct]
147
+ #
148
+ # @example
149
+ # @payment_method_definition = session.payment_method_definitions.update("credit_card", body)
150
+ #
151
+ def update(payment_method_definition_id, body)
152
+ response, status = BeyondApi::Request.put(@session, "/payment-method-definitions/#{payment_method_definition_id}")
153
+
154
+ handle_response(response, status)
155
+ end
156
+
157
+ #
158
+ # A +DELETE+ request is used to delete a payment method definition on system level.
159
+ #
160
+ # $ curl 'https://system.beyondshop.cloud/api/payment-method-definitions/credit-card' -i -X DELETE \
161
+ # -H 'Accept: application/hal+json' \
162
+ # -H 'Authorization: Bearer <Access token>'
163
+ #
164
+ # @return true
165
+ #
166
+ # @example
167
+ # session.payment_method_definitions.delete("credit-card")
168
+ #
169
+ def delete(payment_method_definition_id)
170
+ response, status = BeyondApi::Request.delete(@session, "/payment-method-definitions/#{payment_method_definition_id}", body)
171
+
172
+ handle_response(response, status, respond_with_true: true)
173
+ end
174
+ end
175
+ end
@@ -1,16 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "beyond_api/utils"
4
- require "beyond_api/resources/products/attachments"
5
- require "beyond_api/resources/products/availability"
6
- require "beyond_api/resources/products/cross_sells"
7
- require "beyond_api/resources/products/custom_attributes"
8
- require "beyond_api/resources/products/images"
9
- require "beyond_api/resources/products/searches"
10
- require "beyond_api/resources/products/variation_properties"
11
- require "beyond_api/resources/products/videos"
12
4
 
13
5
  module BeyondApi
6
+ autoload :ProductAttachments, "beyond_api/resources/products/attachments"
7
+ autoload :ProductAvailability, "beyond_api/resources/products/availability"
8
+ autoload :ProductCrossSells, "beyond_api/resources/products/cross_sells"
9
+ autoload :ProductCustomAttributes, "beyond_api/resources/products/custom_attributes"
10
+ autoload :ProductImages, "beyond_api/resources/products/images"
11
+ autoload :ProductSearches, "beyond_api/resources/products/searches"
12
+ autoload :ProductVariationProperties, "beyond_api/resources/products/variation_properties"
13
+ autoload :ProductVideos, "beyond_api/resources/products/videos"
14
+
14
15
  class Products < Base
15
16
  include BeyondApi::ProductAttachments
16
17
  include BeyondApi::ProductAvailability
@@ -3,133 +3,20 @@
3
3
  require "beyond_api/utils"
4
4
 
5
5
  module BeyondApi
6
+ autoload :ShopAddress, "beyond_api/resources/shops/address"
7
+ autoload :ShopAttributes, "beyond_api/resources/shops/attributes"
8
+ autoload :ShopImages, "beyond_api/resources/shops/images"
9
+ autoload :ShopLegals, "beyond_api/resources/shops/legals"
10
+ autoload :ShopLocations, "beyond_api/resources/shops/locations"
11
+
6
12
  class Shop < Base
13
+ include BeyondApi::ShopAddress
14
+ include BeyondApi::ShopAttributes
15
+ include BeyondApi::ShopImages
16
+ include BeyondApi::ShopLegals
17
+ include BeyondApi::ShopLocations
7
18
  include BeyondApi::Utils
8
19
 
9
- #
10
- # A +GET+ request is used to retrieve the details of a shop’s address.
11
- #
12
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/address' -i -X GET
13
- #
14
- # @return [OpenStruct]
15
- #
16
- # @example
17
- # session.shop.address
18
- #
19
- def address
20
- response, status = BeyondApi::Request.get(@session, "/shop/address")
21
-
22
- handle_response(response, status)
23
- end
24
-
25
- #
26
- # A +GET+ request is used to retrieve a particular shop attribute by its name.
27
- #
28
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X GET \
29
- # -H 'Authorization: Bearer <Access token>'
30
- #
31
- # @beyond_api.scopes +shat:r+
32
- #
33
- # @param attribute_name [String] the attribute name
34
- #
35
- # @return [OpenStruct]
36
- #
37
- # @example
38
- # @shop_attribute = session.shop.attribute("second-unknown-attribute-name")
39
- #
40
- def attribute(attribute_name)
41
- response, status = BeyondApi::Request.get(@session, "/shop/attributes/#{attribute_name}")
42
-
43
- handle_response(response, status)
44
- end
45
-
46
- #
47
- # A +GET+ request is used to retrieve a list of all shop attributes.
48
- #
49
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes' -i -X GET \
50
- # -H 'Authorization: Bearer <Access token>'
51
- #
52
- # @beyond_api.scopes +shat:r+
53
- #
54
- # @option params [Integer] :size the page size
55
- # @option params [Integer] :page the page number
56
- #
57
- # @return [OpenStruct]
58
- #
59
- # @example
60
- # @shop_attributes = session.shop.attributes(size: 5, page: 1)
61
- #
62
- def attributes(params = {})
63
- response, status = BeyondApi::Request.get(@session, "/shop/attributes", params)
64
-
65
- handle_response(response, status)
66
- end
67
-
68
- #
69
- # A +POST+ request is used to create a shop attribute.
70
- #
71
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes' -i -X POST \
72
- # -H 'Content-Type: application/json' \
73
- # -H 'Authorization: Bearer <Access token>' \
74
- # -d '{
75
- # "name" : "second-unknown-attribute-name",
76
- # "value" : "correct-value",
77
- # "public" : false
78
- # }'
79
- #
80
- # @beyond_api.scopes +shat:c+
81
- #
82
- # @param body [Hash] the request body
83
- #
84
- # @return [OpenStruct]
85
- #
86
- # @example
87
- # body = {
88
- # "name" => "second-unknown-attribute-name",
89
- # "value" => "correct-value",
90
- # "public" => false
91
- # }
92
- #
93
- # session.shop.create_attribute(body)
94
- #
95
- def create_attribute(body)
96
- response, status = BeyondApi::Request.post(@session, "/shop/attributes", body)
97
-
98
- handle_response(response, status)
99
- end
100
-
101
- #
102
- # A +POST+ request is used to create a shop image.
103
- #
104
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images' -i -X POST \
105
- # -H 'Content-Type: application/json' \
106
- # -H 'Accept: application/hal+json' \
107
- # -H 'Authorization: Bearer <Access token>' \
108
- # -d '{
109
- # "dataUri" : "file.png?hash=212-2323-4343",
110
- # "label" : "logo"
111
- # }'
112
- #
113
- # @beyond_api.scopes +shim:c+
114
- #
115
- # @param body [Hash] the request body
116
- #
117
- # @return true
118
- #
119
- # @example
120
- # body = {
121
- # "data_uri" => "file.png?hash=212-2323-4343",
122
- # "label" => "logo"
123
- # }
124
- #
125
- # session.shop.create_image(body)
126
- #
127
- def create_image(body)
128
- response, status = BeyondApi::Request.post(@session, "/shop/images", body)
129
-
130
- handle_response(response, status, respond_with_true: true)
131
- end
132
-
133
20
  #
134
21
  # A +GET+ request is used to retrieve the details of a shop.
135
22
  #
@@ -147,168 +34,6 @@ module BeyondApi
147
34
  handle_response(response, status)
148
35
  end
149
36
 
150
- #
151
- # A +DELETE+ request is used to delete an shop attribute.
152
- #
153
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X DELETE \
154
- # -H 'Authorization: Bearer <Access token>'
155
- #
156
- # @beyond_api.scopes +shat:d+
157
- #
158
- # @param attribute_name [String] the attribute name
159
- #
160
- # @return true
161
- #
162
- # @example
163
- # session.shop.delete_attribute("second-unknown-attribute-name")
164
- #
165
- def delete_attribute(attribute_name)
166
- response, status = BeyondApi::Request.delete(@session, "/shop/attributes/#{attribute_name}")
167
-
168
- handle_response(response, status, respond_with_true: true)
169
- end
170
-
171
- #
172
- # A +DELETE+ request is used to delete a shop image.
173
- #
174
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images/6a7646dc-7f26-4730-a98f-52f9b63978fb' -i -X DELETE \
175
- # -H 'Content-Type: application/json' \
176
- # -H 'Accept: application/hal+json' \
177
- # -H 'Authorization: Bearer <Access token>'
178
- #
179
- # @beyond_api.scopes +shim:d+
180
- #
181
- # @param image_id [String] the image UUID
182
- #
183
- # @return true
184
- #
185
- # @example
186
- # session.shop.delete_image("6a7646dc-7f26-4730-a98f-52f9b63978fb")
187
- #
188
- def delete_image(image_id)
189
- response, status = BeyondApi::Request.delete(@session, "/shop/images/#{image_id}")
190
-
191
- handle_response(response, status, respond_with_true: true)
192
- end
193
-
194
- #
195
- # A +GET+ request is used to retrieve a single shop image.
196
- #
197
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images/2feee7ac-f1cb-4faf-9488-f3ce07394141' -i -X GET \
198
- # -H 'Accept: application/hal+json'
199
- #
200
- # @param image_id [String] the image UUID
201
- #
202
- # @return [OpenStruct]
203
- #
204
- # @example
205
- # @image = session.shop.image("2feee7ac-f1cb-4faf-9488-f3ce07394141")
206
- #
207
- def image(image_id)
208
- response, status = BeyondApi::Request.get(@session, "/shop/images/#{image_id}")
209
-
210
- handle_response(response, status)
211
- end
212
-
213
- #
214
- # A +GET+ request is used to retrieve the images of a shop.
215
- #
216
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images' -i -X GET \
217
- # -H 'Accept: application/hal+json'
218
- #
219
- # @option params [Integer] :size the page size
220
- # @option params [Integer] :page the page number
221
- #
222
- # @return [OpenStruct]
223
- #
224
- # @example
225
- # @images = session.shop.images(size: 5, page: 1)
226
- #
227
- def images(params = {})
228
- response, status = BeyondApi::Request.get(@session, "/shop/images", params)
229
-
230
- handle_response(response, status)
231
- end
232
-
233
- #
234
- # A +GET+ request is used to retrieve a specific part of the legal content information.
235
- #
236
- # $ curl 'https://api-shop.beyondshop.cloud/api/legal-content/right-of-withdrawal' -i -X GET \
237
- # -H 'Content-Type: application/json' \
238
- # -H 'Accept: application/json'
239
- #
240
- # @param legal_content_type [String] the legal content type
241
- #
242
- # @return [OpenStruct]
243
- #
244
- # @example
245
- # @legal_content = session.shop.legal_content("right-of-withdrawal")
246
- #
247
- def legal_content(legal_content_type)
248
- response, status = BeyondApi::Request.get(@session, "/legal-content/#{legal_content_type}")
249
-
250
- handle_response(response, status)
251
- end
252
-
253
- #
254
- # A +GET+ request is used to retrieve the legal content of a shop.
255
- #
256
- # $ curl 'https://api-shop.beyondshop.cloud/api/legal-content' -i -X GET \
257
- # -H 'Content-Type: application/json' \
258
- # -H 'Accept: application/json'
259
- #
260
- # @option params [Integer] :size the page size
261
- # @option params [Integer] :page the page number
262
- #
263
- # @return [OpenStruct]
264
- #
265
- # @example
266
- # @legal_content = session.shop.legal_contents(size: 5, page: 1)
267
- #
268
- def legal_contents(params = {})
269
- response, status = BeyondApi::Request.get(@session, "/legal-content", params)
270
-
271
- handle_response(response, status)
272
- end
273
-
274
- #
275
- # A +GET+ request is used to retrieve the details of the legal resource.
276
- #
277
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/legal' -i -X GET \
278
- # -H 'Authorization: Bearer <Access token>'
279
- #
280
- # @beyond_api.scopes +legl:r+
281
- #
282
- # @return [OpenStruct]
283
- #
284
- # @example
285
- # @legal_details = session.shop.legal_details
286
- #
287
- def legal_details
288
- response, status = BeyondApi::Request.get(@session, "/shop/legal")
289
-
290
- handle_response(response, status)
291
- end
292
-
293
- #
294
- # A +GET+ request is issued to search for shop images by label.
295
- #
296
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/images/search/find-by-label?label=logo' -i -X GET \
297
- # -H 'Accept: application/hal+json'
298
- #
299
- # @param label [String] the image label
300
- #
301
- # @return [OpenStruct]
302
- #
303
- # @example
304
- # session.shop.search_images_by_label("logo")
305
- #
306
- def search_images_by_label(label)
307
- response, status = BeyondApi::Request.get(@session, "/shop/images/search/find-by-label", { label: label })
308
-
309
- handle_response(response, status)
310
- end
311
-
312
37
  #
313
38
  # A +PATCH+ request is used to change attributes of a shop.
314
39
  #
@@ -360,157 +85,5 @@ module BeyondApi
360
85
 
361
86
  handle_response(response, status)
362
87
  end
363
-
364
- #
365
- # A +PATCH+ request is used to patch a shop’s address partially with json content type.
366
- #
367
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/address' -i -X PATCH \
368
- # -H 'Content-Type: application/json' \
369
- # -H 'Accept: application/hal+json' \
370
- # -H 'Authorization: Bearer <Access token>' \
371
- # -d '{
372
- # "city" : "Barcelona"
373
- # }'
374
- #
375
- # @beyond_api.scopes +shad:u+
376
- #
377
- # @param body [Hash] the request body
378
- #
379
- # @return [OpenStruct]
380
- #
381
- # @example
382
- # body = {
383
- # "city" => "Barcelona"
384
- # }
385
- #
386
- # session.shop.update_address(body)
387
- #
388
- def update_address(body)
389
- response, status = BeyondApi::Request.patch(@session, "/shop/address", body)
390
-
391
- handle_response(response, status)
392
- end
393
-
394
- #
395
- # A +PUT+ request is used to update a shop attribute. This operation is idempotent and will create a new shop attribute if required.
396
- #
397
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/attributes/second-unknown-attribute-name' -i -X PUT \
398
- # -H 'Content-Type: application/json' \
399
- # -H 'Authorization: Bearer <Access token>' \
400
- # -d '{
401
- # "value" : "new-value",
402
- # "public" : false
403
- # }'
404
- #
405
- # @beyond_api.scopes +shat:u+
406
- #
407
- # @param attribute_name [String] the attribute name
408
- # @param body [Hash] the request body
409
- #
410
- # @return [OpenStruct]
411
- #
412
- # @example
413
- # body = {
414
- # "value" => "new-value",
415
- # "public" => false
416
- # }
417
- #
418
- # session.shop.update_attribute("second-unknown-attribute-name", body)
419
- #
420
- def update_attribute(attribute_name, body)
421
- response, status = BeyondApi::Request.put(@session, "/shop/attributes/#{attribute_name}", body)
422
-
423
- handle_response(response, status)
424
- end
425
-
426
- #
427
- # A +PUT+ request is used to update the content of a specific part of the legal content information. Changes on the properties type and mandatory will be ignored.
428
- #
429
- # $ curl 'https://api-shop.beyondshop.cloud/api/legal-content/legal-notice' -i -X PUT \
430
- # -H 'Content-Type: application/json' \
431
- # -H 'Accept: application/json' \
432
- # -H 'Authorization: Bearer <Access token>' \
433
- # -d '{
434
- # "content" : "new legal content"
435
- # }'
436
- #
437
- # @beyond_api.scopes +lcnt:u+
438
- #
439
- # @param body [Hash] the request body
440
- #
441
- # @return [OpenStruct]
442
- #
443
- # @example
444
- # session.shop.update_legal_content(body)
445
- #
446
- def update_legal_content(body)
447
- response, status = BeyondApi::Request.put(@session, "/legal-content/legal-notice")
448
-
449
- handle_response(response, status)
450
- end
451
-
452
- #
453
- # A +PATCH+ request is used to update a legal resource partially with json content type.
454
- #
455
- # $ curl 'https://api-shop.beyondshop.cloud/api/shop/legal' -i -X PATCH \
456
- # -H 'Content-Type: application/json' \
457
- # -H 'Accept: application/hal+json' \
458
- # -H 'Authorization: Bearer <Access token>' \
459
- # -d '{
460
- # "vatId" : "GB 111111111"
461
- # }'
462
- #
463
- # @beyond_api.scopes +legl:u+
464
- #
465
- # @param body [Hash] the request body
466
- #
467
- # @return [OpenStruct]
468
- #
469
- # @example
470
- # body = {
471
- # "vat_id" => "GB 111111111"
472
- # }
473
- #
474
- # session.shop.update_legal_details(body)
475
- #
476
- def update_legal_details(body)
477
- response, status = BeyondApi::Request.patch(@session, "/shop/legal")
478
-
479
- handle_response(response, status)
480
- end
481
-
482
- #
483
- # A +POST+ request is used to upload a shop image. The body of the request must contain the content of the image.
484
- #
485
- # $ curl --data-binary '@/home/epages/sample.png' 'https://api-shop.beyondshop.cloud/api/shop/images?fileName=sample.png&label=invoice logo' -X POST \
486
- # -H 'Content-Type: image/png' \
487
- # -H 'Authorization: Bearer <Access token>'
488
- #
489
- # @beyond_api.scopes +shim:c+
490
- #
491
- # @param image_path [String] the image path
492
- # @param image_name [String] the image name
493
- # @param label [String] the image label
494
- #
495
- # @return true
496
- #
497
- # @example
498
- # session.shop.upload_image("/home/epages/sample.png", "sample.png", "invoice logo")
499
- #
500
- def upload_image(image_path, image_name, label)
501
- content_type = case File.extname(image_path)
502
- when ".png"
503
- "image/png"
504
- when ".jpg", ".jpeg"
505
- "image/jpeg"
506
- when ".gif"
507
- "image/gif"
508
- end
509
- image_binary = File.binread(image_path)
510
-
511
- response, status = BeyondApi::Request.upload(@session, "/shop/images", image_binary, content_type, { file_name: image_name, label: label })
512
-
513
- handle_response(response, status, respond_with_true: true)
514
- end
515
88
  end
516
89
  end