beyond_api 0.15.0.pre → 0.18.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: 438360193bc7064cbd6591e9dc088aeb81f162aac26bff0ac1f891f45b5b9993
4
- data.tar.gz: 57f358035cc7aa0ee5ee0795eecb3f887b5f534d470342348d70c6e6c6f1ac48
3
+ metadata.gz: e9b48b71a8bbe959b3250221b561ea742a3d82e0d80a0f0b9f4638cc2f57b5ed
4
+ data.tar.gz: 4c9353fd93cef022310c1b7ae1b147776d1e1bc6da94a751adc68f14852efb2a
5
5
  SHA512:
6
- metadata.gz: 284505c3dc6af706bd3851fe62c885ce2aec79c76a997b2c07f20a23d5745c3a7d16c337177de9579b25c0fe9440b2b9e04f5cfdd2ec377362effb2a98df7b0b
7
- data.tar.gz: eb9168f92793a47673646fcb8ac36bd6c5103596620a1003a143242a938ceba156429fe3760f41672c705a23f367ad2be40d6607c0f112ecdf16be1ead96a0b1
6
+ metadata.gz: e7cbc7f1f943fc00701e2f548756dfa0cc2808cc51096bf0c6a6be5bbf9b7edfcfd16b80ae351251feb3d26f9be0cba23df3fbf093ff4a69b5ff169b0087a297
7
+ data.tar.gz: 946ce5ce94a725e55ee7e1c172b4094b6146836c5e4f8cb28b4823c0426db1923044c4b4cc22f9f470ff55101a5698be694e82876a05f296510a07d91b465b02
data/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ ### v0.18.0.pre
2
+
3
+ * features
4
+ * Add new token retrieval/refresh methods
5
+ * `Token#authorization_code`
6
+ * `Token#refresh_token`
7
+ * `Token#client_credentials`
8
+ * Add alias methods for avoiding deprecation
9
+ * `refresh` -> `refresh_token`
10
+ * `create` -> `authorization_code`
11
+
12
+ ### v0.17.0.pre
13
+
14
+ * enhancements
15
+ * Add customizable pagination size when sending `paginated: false` parameter to `#all` requests.
16
+
17
+ ### v0.16.1.pre
18
+
19
+ * bug-fixes
20
+ * Fix method to retrieve resources without pagination
21
+
22
+ ### v0.16.0.pre
23
+
24
+ * features
25
+ * Add pickup options methods
26
+ * `PickupOptions#delete`
27
+ * `PickupOptions#find`
28
+ * `PickupOptions#sort`
29
+ * `PickupOptions#update`
30
+
1
31
  ### v0.15.0.pre
2
32
 
3
33
  * features
@@ -12,7 +42,7 @@
12
42
 
13
43
  * features
14
44
  * Add `Products#assign_variation_attribute_as_differentiator`
15
-
45
+
16
46
  ### v0.13.0.pre
17
47
 
18
48
  * features
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beyond_api (0.15.0.pre)
4
+ beyond_api (0.18.0.pre)
5
5
  faraday (~> 0.15)
6
6
 
7
7
  GEM
@@ -52,4 +52,4 @@ DEPENDENCIES
52
52
  yard (~> 0.9)
53
53
 
54
54
  BUNDLED WITH
55
- 2.1.4
55
+ 2.2.26
data/beyond_api.gemspec CHANGED
@@ -6,7 +6,7 @@ require "beyond_api/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "beyond_api"
8
8
  spec.version = BeyondApi::VERSION
9
- spec.authors = ["Unai Abrisketa", "Kathia Salazar", "German San Emeterio"]
9
+ spec.authors = ["Unai Abrisketa", "Kathia Salazar", "German San Emeterio", "Kenneth Gallego"]
10
10
 
11
11
  spec.summary = "Ruby client to access the Beyond API"
12
12
  spec.homepage = "https://github.com/ePages-de/beyond_api-ruby_client"
data/lib/beyond_api.rb CHANGED
@@ -27,7 +27,7 @@ module BeyondApi
27
27
  class Configuration
28
28
  attr_accessor :client_id, :client_secret, :open_timeout, :timeout, :remove_response_links,
29
29
  :remove_response_key_underscores, :object_struct_responses, :raise_error_requests,
30
- :log_headers, :log_bodies, :log_level
30
+ :log_headers, :log_bodies, :log_level, :all_pagination_size
31
31
 
32
32
  def initialize
33
33
  @client_id = nil
@@ -42,6 +42,8 @@ module BeyondApi
42
42
  @log_level = :info
43
43
  @log_headers = false
44
44
  @log_bodies = false
45
+
46
+ @all_pagination_size = 200
45
47
  end
46
48
  end
47
49
  end
@@ -68,9 +68,9 @@ module BeyondApi
68
68
  # tax_model: "GROSS",
69
69
  # currency: "EUR",
70
70
  # amount: 1
71
- # },
72
- # phone_number_required: true,
73
- # location_id: "cb554eb6-2768-4491-afd2-6bcd0aec0937"
71
+ # },
72
+ # phone_number_required: true,
73
+ # location_id: "cb554eb6-2768-4491-afd2-6bcd0aec0937"
74
74
  # }
75
75
  #
76
76
  # @pickup_option = session.pickup_options.create(body)
@@ -80,5 +80,137 @@ module BeyondApi
80
80
 
81
81
  handle_response(response, status)
82
82
  end
83
+
84
+ #
85
+ # A +DELETE+ request is used to delete a pickup option.
86
+ #
87
+ # $ curl 'https://api-shop.beyondshop.cloud/api/pickup-options/d253a31b-3892-4196-ae16-c5d8d6b05791' -i -X DELETE
88
+ #
89
+ # @beyond_api.scopes +shpz:d+
90
+ #
91
+ # @param pickup_option_id [String] the pickup option UUID
92
+ #
93
+ # @return true
94
+ #
95
+ # @example
96
+ # session.pickup_options.delete("d253a31b-3892-4196-ae16-c5d8d6b05791")
97
+ #
98
+ def delete(pickup_option_id)
99
+ response, status = BeyondApi::Request.delete(@session, "/pickup-options/#{pickup_option_id}")
100
+
101
+ handle_response(response, status, respond_with_true: true)
102
+ end
103
+
104
+ #
105
+ # A +GET+ request is used to retrieve the details of a pickup option.
106
+ #
107
+ # $ curl 'https://api-shop.beyondshop.cloud/api/pickup-options/76302c10-761f-43c1-9d18-52ad16bd52e8' -i -X GET \
108
+ # -H 'Content-Type: application/json' \
109
+ # -H 'Accept: application/hal+json' \
110
+ # -H 'Authorization: Bearer <Access token>'
111
+ #
112
+ # @beyond_api.scopes +shpz:r+
113
+ #
114
+ # @param pickup_option_id [String] the pickup option UUID
115
+ #
116
+ # @return [OpenStruct]
117
+ #
118
+ # @example
119
+ # @pickup_option = session.pickup_options.find("76302c10-761f-43c1-9d18-52ad16bd52e8")
120
+ #
121
+ def find(pickup_option_id)
122
+ response, status = BeyondApi::Request.get(@session, "/pickup-options/#{pickup_option_id}")
123
+
124
+ handle_response(response, status)
125
+ end
126
+
127
+ #
128
+ # A +PUT+ request is used to sort the pickup options. This is done by passing the self-links of the pickup options in the desired order. The request must contain URIs for all pickup options of the given page.
129
+ #
130
+ # $ curl 'https://api-shop.beyondshop.cloud/api/pickup-options' -i -X PUT \
131
+ # -H 'Content-Type: text/uri-list' \
132
+ # -H 'Authorization: Bearer <Access token>' \
133
+ # -d 'https://api-shop.beyondshop.cloud/api/pickup-options/bff3673f-91c1-4e09-a8ab-562a3a553fac
134
+ # https://api-shop.beyondshop.cloud/api/pickup-options/7b4d36fc-ac0f-44a3-8655-f2bd05c2a42d
135
+ # https://api-shop.beyondshop.cloud/api/pickup-options/630b63ee-c7d8-4953-9b7c-c874fd795154'
136
+ #
137
+ # @beyond_api.scopes +shpz:u+
138
+ #
139
+ # @param pickup_option_ids [Array] the pickup option UUIDs
140
+ #
141
+ # @return [OpenStruct]
142
+ #
143
+ # @example
144
+ # pickup_option_ids = [
145
+ # "bff3673f-91c1-4e09-a8ab-562a3a553fac",
146
+ # "7b4d36fc-ac0f-44a3-8655-f2bd05c2a42d",
147
+ # "630b63ee-c7d8-4953-9b7c-c874fd795154"
148
+ # ]
149
+ #
150
+ # session.pickup_options.sort(pickup_option_ids)
151
+ #
152
+ def sort(pickup_option_ids)
153
+ body = pickup_option_ids.map { |id| "#{@session.api_url}/pickup-options/#{id}" }
154
+ response, status = BeyondApi::Request.put(@session, "/pickup-options", body)
155
+
156
+ handle_response(response, status, respond_with_true: true)
157
+ end
158
+
159
+ #
160
+ # A +PUT+ request is used to update a pickup option.
161
+ #
162
+ # $ curl 'https://api-shop.beyondshop.cloud/api/pickup-options/5765b837-db5b-49a9-a659-68d00376e42a' -i -X PUT \
163
+ # -H 'Content-Type: application/json' \
164
+ # -H 'Accept: application/hal+json' \
165
+ # -H 'Authorization: Bearer <Access token>' \
166
+ # -d '{
167
+ # "name" : "New name",
168
+ # "description" : "We will send you an email when your items are ready for pickup. Please bring a copy of your order confirmation.",
169
+ # "taxClass" : "REGULAR",
170
+ # "freePickupValue" : {
171
+ # "currency" : "EUR",
172
+ # "amount" : 50
173
+ # },
174
+ # "fixedPrice" : {
175
+ # "taxModel" : "GROSS",
176
+ # "currency" : "EUR",
177
+ # "amount" : 1
178
+ # },
179
+ # "phoneNumberRequired" : true,
180
+ # "locationId" : "c9179393-abcc-450a-8cf4-875b39647ab6"
181
+ # }'
182
+ #
183
+ # @beyond_api.scopes +shpz:u+
184
+ #
185
+ # @param pickup_option_id [String] the pickup option UUID
186
+ # @param body [Hash] the request body
187
+ #
188
+ # @return [OpenStruct]
189
+ #
190
+ # @example
191
+ # body = {
192
+ # name: "New name",
193
+ # description: "We will send you an email when your items are ready for pickup. Please bring a copy of your order confirmation.",
194
+ # tax_class: "REGULAR",
195
+ # free_pickup_value: {
196
+ # currency: "EUR",
197
+ # amount: 50
198
+ # },
199
+ # fixed_price: {
200
+ # tax_model: "GROSS",
201
+ # currency: "EUR",
202
+ # amount: 1
203
+ # },
204
+ # phone_number_required: true,
205
+ # location_id: "c9179393-abcc-450a-8cf4-875b39647ab6"
206
+ # }
207
+ #
208
+ # @pickup_option = session.pickup_options.update("5765b837-db5b-49a9-a659-68d00376e42a", body)
209
+ #
210
+ def update(pickup_option_id, body)
211
+ response, status = BeyondApi::Request.put(@session, "/pickup-options/#{pickup_option_id}", body)
212
+
213
+ handle_response(response, status)
214
+ end
83
215
  end
84
216
  end
@@ -98,8 +98,8 @@ module BeyondApi
98
98
  # }
99
99
  # },
100
100
  # "shippingPeriod" : {
101
- # "minDays" : 2,
102
- # "maxDays" : 4,
101
+ # "min" : 2,
102
+ # "max" : 4,
103
103
  # "displayUnit" : "WEEKS"
104
104
  # }
105
105
  # }'
@@ -157,8 +157,8 @@ module BeyondApi
157
157
  # }
158
158
  # },
159
159
  # "shippingPeriod": {
160
- # "minDays": 2,
161
- # "maxDays": 4,
160
+ # "min": 2,
161
+ # "max": 4,
162
162
  # "displayUnit": "WEEKS"
163
163
  # }
164
164
  # }
@@ -17,31 +17,32 @@ module BeyondApi
17
17
  raise InvalidSessionError.new("Session api_url cannot be nil") if session.api_url.nil?
18
18
  end
19
19
 
20
- def create(code)
21
- response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
22
- grant_type: "authorization_code",
23
- code: code)
24
-
25
- handle_response(response, status)
20
+ def authorization_code(code)
21
+ handle_token_call("authorization_code", code: code)
26
22
  end
27
23
 
28
- def refresh
29
- response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
30
- grant_type: "refresh_token",
31
- refresh_token: @session.refresh_token)
32
-
33
- handle_response(response, status)
24
+ def refresh_token
25
+ handle_token_call("refresh_token", refresh_token: @session.refresh_token)
34
26
  end
35
27
 
36
28
  def client_credentials
29
+ handle_token_call("client_credentials")
30
+ end
31
+
32
+ alias_method :refresh, :refresh_token
33
+ alias_method :create, :authorization_code
34
+
35
+ private
36
+
37
+ def handle_token_call(grant_type, params = {})
38
+ params.merge!(grant_type: grant_type)
39
+
37
40
  response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
38
- grant_type: "client_credentials")
41
+ params)
39
42
 
40
43
  handle_response(response, status)
41
44
  end
42
45
 
43
- private
44
-
45
46
  def handle_response(response, status)
46
47
  if status.between?(200, 299)
47
48
  @session.access_token = response["access_token"]
@@ -45,14 +45,18 @@ module BeyondApi
45
45
  end
46
46
 
47
47
  def handle_all_request(url, resource, params = {})
48
+ paginated_size = BeyondApi.configuration.all_pagination_size
49
+
48
50
  if params[:paginated] == false
49
- result = all_paginated(url, { page: 0, size: 1000 })
51
+ result = all_paginated(url, params.merge(page: 0, size: paginated_size))
50
52
 
51
53
  (1..result[:page][:total_pages] - 1).each do |page|
52
- result[:embedded][resource].concat(all_paginated(url, { page: page, size: 1000 })[:embedded][resource])
54
+ result[:embedded][resource].concat(all_paginated(url, params.merge(page: page, size: paginated_size))[:embedded][resource])
53
55
  end
54
56
 
55
- result.is_a?(Hash) ? result.delete(:page) : result.delete_field(:page)
57
+ result[:page][:size] = result[:page][:total_elements]
58
+ result[:page][:total_pages] = 1
59
+ result[:page][:number] = 0
56
60
 
57
61
  result
58
62
  else
@@ -1,3 +1,3 @@
1
1
  module BeyondApi
2
- VERSION = "0.15.0.pre".freeze
2
+ VERSION = "0.18.0.pre".freeze
3
3
  end
@@ -12,6 +12,9 @@ BeyondApi.setup do |config|
12
12
  # Configure the request timeout in seconds. Default is 5 seconds.
13
13
  # config.timeout = 5.seconds
14
14
 
15
+ # Configure the pagination size when `paginated: false` is sent on `.all()` requests. Value must be between 1 and 1000.
16
+ # config.all_pagination_size = 200
17
+
15
18
  # ==> Log configuration
16
19
 
17
20
  # Configure the log level. Must be one of :debug, :info, :warn, :error,
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beyond_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0.pre
4
+ version: 0.18.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unai Abrisketa
8
8
  - Kathia Salazar
9
9
  - German San Emeterio
10
- autorequire:
10
+ - Kenneth Gallego
11
+ autorequire:
11
12
  bindir: exe
12
13
  cert_chain: []
13
- date: 2021-06-18 00:00:00.000000000 Z
14
+ date: 2021-08-20 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: bundler
@@ -110,8 +111,8 @@ dependencies:
110
111
  - - "~>"
111
112
  - !ruby/object:Gem::Version
112
113
  version: '0.15'
113
- description:
114
- email:
114
+ description:
115
+ email:
115
116
  executables: []
116
117
  extensions: []
117
118
  extra_rdoc_files: []
@@ -183,7 +184,7 @@ files:
183
184
  homepage: https://github.com/ePages-de/beyond_api-ruby_client
184
185
  licenses: []
185
186
  metadata: {}
186
- post_install_message:
187
+ post_install_message:
187
188
  rdoc_options: []
188
189
  require_paths:
189
190
  - lib
@@ -198,8 +199,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
199
  - !ruby/object:Gem::Version
199
200
  version: 1.3.1
200
201
  requirements: []
201
- rubygems_version: 3.0.3
202
- signing_key:
202
+ rubygems_version: 3.2.26
203
+ signing_key:
203
204
  specification_version: 4
204
205
  summary: Ruby client to access the Beyond API
205
206
  test_files: []