beyond_api 0.11.0.pre → 0.14.0.pre

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 78c3366e77c86e546074cbbc049e2161b231511deede234a92f96d315575ba45
4
- data.tar.gz: f8e08acff7d5f80be7ffd249c83d6116abd86ddfb216e5c25e955deaffe439be
3
+ metadata.gz: 7a3232a181c9e98adb48dde14f44f3fbf5cbd148716a4aebfaedd8395f67f1c1
4
+ data.tar.gz: 3165b0482c207a611d5b1c1cfe0631a730c7d23774f0551c34c6e29bfb571134
5
5
  SHA512:
6
- metadata.gz: f4f0be05bb0c55da87c1c650b86f112993ce8346f6178f3cf27d865d8415377924263d0b2ec648b8a1d8026c6a5a4250221a8dc68ba39bd154bfb43c0913649c
7
- data.tar.gz: 8400df3f3b61240c0516fc4d86e386eea7e67f88ca56324e68989f731d415e77ab9907817b092dc59c87f79794d96d1e7a76960e4785ebf0237b384ca6ed64e7
6
+ metadata.gz: ba4db6852f6ea76b6b27a5def080dd54b1e2a9767a050cbddfb463eb538deac413b22923f065a1b4da37f828866142acc7173a0242a30ebf80b5e530d0606acf
7
+ data.tar.gz: 3f48e09d7f4a934218fefeff168c67a5aaa097dd502fb8080969748dc8ac612ec7f4444596e3b6f73cfc234b37741063103beace5cfa59375eb6b4a689b5e130
data/CHANGELOG.md CHANGED
@@ -1,3 +1,45 @@
1
+ ### v0.14.0.pre
2
+
3
+ * deprecations
4
+ * Remove `Products#assign_variation_images_differentiator`
5
+
6
+ * features
7
+ * Add `Products#assign_variation_attribute_as_differentiator`
8
+
9
+ ### v0.13.0.pre
10
+
11
+ * features
12
+ * Add payment method definitions methods
13
+ * `PaymentMethodDefinitions#all`
14
+ * `PaymentMethodDefinitions#create`
15
+ * `PaymentMethodDefinitions#delete`
16
+ * `PaymentMethodDefinitions#find`
17
+ * `PaymentMethodDefinitions#update`
18
+ * Add possibility to log request `headers` and `bodies`
19
+
20
+ ### v0.12.1.pre
21
+
22
+ * bug-fixes
23
+ * Fix camelize function for hashes containing arrays
24
+
25
+ ### v0.12.0.pre
26
+
27
+ * features
28
+ * Add locations methods
29
+ * `Locations#all`
30
+ * `Locations#create`
31
+ * `Locations#delete`
32
+ * `Locations#find`
33
+ * `Locations#update`
34
+
35
+ * enhancements
36
+ * Use `autoload` instead of `require`
37
+
38
+ ### v0.11.1.pre
39
+
40
+ * bug-fixes
41
+ * Use `BeyondApi::Error` for authentication errors
42
+
1
43
  ### v0.11.0.pre
2
44
 
3
45
  * enhancements
data/Gemfile.lock CHANGED
@@ -1,42 +1,42 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beyond_api (0.11.0.pre)
4
+ beyond_api (0.14.0.pre)
5
5
  faraday (~> 0.15)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- coderay (1.1.2)
11
- concurrent-ruby (1.1.5)
12
- diff-lcs (1.3)
13
- dotenv (2.7.5)
14
- faker (2.4.0)
15
- i18n (~> 1.6.0)
16
- faraday (0.17.3)
10
+ coderay (1.1.3)
11
+ concurrent-ruby (1.1.8)
12
+ diff-lcs (1.4.4)
13
+ dotenv (2.7.6)
14
+ faker (2.17.0)
15
+ i18n (>= 1.6, < 2)
16
+ faraday (0.17.4)
17
17
  multipart-post (>= 1.2, < 3)
18
- i18n (1.6.0)
18
+ i18n (1.8.10)
19
19
  concurrent-ruby (~> 1.0)
20
- method_source (0.9.2)
20
+ method_source (1.0.0)
21
21
  multipart-post (2.1.1)
22
- pry (0.12.2)
23
- coderay (~> 1.1.0)
24
- method_source (~> 0.9.0)
22
+ pry (0.14.0)
23
+ coderay (~> 1.1)
24
+ method_source (~> 1.0)
25
25
  rake (10.5.0)
26
- rspec (3.8.0)
27
- rspec-core (~> 3.8.0)
28
- rspec-expectations (~> 3.8.0)
29
- rspec-mocks (~> 3.8.0)
30
- rspec-core (3.8.2)
31
- rspec-support (~> 3.8.0)
32
- rspec-expectations (3.8.4)
26
+ rspec (3.10.0)
27
+ rspec-core (~> 3.10.0)
28
+ rspec-expectations (~> 3.10.0)
29
+ rspec-mocks (~> 3.10.0)
30
+ rspec-core (3.10.1)
31
+ rspec-support (~> 3.10.0)
32
+ rspec-expectations (3.10.1)
33
33
  diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.8.0)
35
- rspec-mocks (3.8.1)
34
+ rspec-support (~> 3.10.0)
35
+ rspec-mocks (3.10.2)
36
36
  diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.8.0)
38
- rspec-support (3.8.2)
39
- yard (0.9.20)
37
+ rspec-support (~> 3.10.0)
38
+ rspec-support (3.10.2)
39
+ yard (0.9.26)
40
40
 
41
41
  PLATFORMS
42
42
  ruby
data/lib/beyond_api.rb CHANGED
@@ -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,
@@ -2,16 +2,18 @@
2
2
 
3
3
  module BeyondApi
4
4
  class Error < StandardError
5
- attr_reader :error_id, :details, :trace_id, :full_message, :status_code
5
+ attr_reader :error_id, :details, :trace_id, :full_message, :status_code, :error, :error_description
6
6
 
7
7
  def initialize(data, status_code = nil)
8
- @error_id = data['errorId']
9
- @details = data['details']
10
- @trace_id = data['traceId']
11
- @full_message = data
12
- @status_code = status_code
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
13
15
 
14
- super(data['message'])
16
+ super(data['message'] || data['error_description'])
15
17
  end
16
18
  end
17
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
@@ -252,28 +253,25 @@ module BeyondApi
252
253
  end
253
254
 
254
255
  #
255
- # A +PUT+ request is used to assign a variation images differentiator for a variation product. The differentiator can be one of the variation attributes defined by the merchant, e.g. name, size, or color.
256
+ # A +POST+ request is used to assign a variation attribute as the variation images differentiator for a variation product.
256
257
  #
257
258
  # @beyond_api.scopes +prod:u+
258
259
  #
259
- # $ curl 'https://api-shop.beyondshop.cloud/api/products/30839efc-47f7-4d55-aa13-aac7532982b6/variation-images-differentiator' -i -X PUT \
260
+ # $ curl 'https://api-shop.beyondshop.cloud/api/products/f205294b-17dc-4f75-8b5e-5df72abb96df/variation-attributes/491fedf4-37a9-4bcf-98b8-cff2f82879b7/make-differentiator' -i -X POST \
260
261
  # -H 'Content-Type: application/hal+json' \
261
262
  # -H 'Accept: application/hal+json' \
262
- # -H 'Authorization: Bearer <Access token>' \
263
- # -d '{
264
- # "differentiator" : "size"
265
- # }'
263
+ # -H 'Authorization: Bearer <Access token>'
266
264
  #
267
265
  # @param product_id [String] the product UUID
268
- # @param differentiator [String] the differentiator
266
+ # @param variation_attribute_id [String] the variation attribute UUID
269
267
  #
270
268
  # @return [true]
271
269
  #
272
270
  # @example
273
- # session.products.assign_variation_images_differentiator("30839efc-47f7-4d55-aa13-aac7532982b6", "size")
271
+ # session.products.assign_variation_images_differentiator("f205294b-17dc-4f75-8b5e-5df72abb96df", "491fedf4-37a9-4bcf-98b8-cff2f82879b7")
274
272
  #
275
- def assign_variation_images_differentiator(product_id, differentiator)
276
- response, status = BeyondApi::Request.put(@session, "/products/#{product_id}/variation-images-differentiator", differentiator: differentiator)
273
+ def assign_variation_attribute_as_differentiator(product_id, variation_attribute_id)
274
+ response, status = BeyondApi::Request.post(@session, "/products/#{product_id}/variation-attributes/#{variation_attribute_id}/make-differentiator")
277
275
 
278
276
  handle_response(response, status, respond_with_true: true)
279
277
  end