Skip to content

Commit aa54719

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 4d197d1 + df11dab commit aa54719

File tree

10 files changed

+70
-29
lines changed

10 files changed

+70
-29
lines changed

CHANGELOG.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
### v0.18.1.pre
2+
3+
* bug-fixes
4+
* Prevent logging `code` and `refresh_token` on `/api/token` calls
5+
6+
### v0.18.0.pre
7+
8+
* features
9+
* Add new token retrieval/refresh methods
10+
* `Token#authorization_code`
11+
* `Token#refresh_token`
12+
* `Token#client_credentials`
13+
* Add alias methods for avoiding deprecation
14+
* `refresh` -> `refresh_token`
15+
* `create` -> `authorization_code`
16+
17+
### v0.17.0.pre
18+
19+
* enhancements
20+
* Add customizable pagination size when sending `paginated: false` parameter to `#all` requests.
21+
22+
### v0.16.1.pre
23+
24+
* bug-fixes
25+
* Fix method to retrieve resources without pagination
26+
127
### v0.16.0.pre
228

329
* features
@@ -21,7 +47,7 @@
2147

2248
* features
2349
* Add `Products#assign_variation_attribute_as_differentiator`
24-
50+
2551
### v0.13.0.pre
2652

2753
* features

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
beyond_api (0.16.0.pre)
4+
beyond_api (0.18.1.pre)
55
faraday (~> 0.15)
66

77
GEM
@@ -52,4 +52,4 @@ DEPENDENCIES
5252
yard (~> 0.9)
5353

5454
BUNDLED WITH
55-
2.1.4
55+
2.2.26

beyond_api.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require "beyond_api/version"
66
Gem::Specification.new do |spec|
77
spec.name = "beyond_api"
88
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"]
1010

1111
spec.summary = "Ruby client to access the Beyond API"
1212
spec.homepage = "https://github.com/ePages-de/beyond_api-ruby_client"

lib/beyond_api.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def self.setup
2727
class Configuration
2828
attr_accessor :client_id, :client_secret, :open_timeout, :timeout, :remove_response_links,
2929
: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
3131

3232
def initialize
3333
@client_id = nil
@@ -42,6 +42,8 @@ def initialize
4242
@log_level = :info
4343
@log_headers = false
4444
@log_bodies = false
45+
46+
@all_pagination_size = 200
4547
end
4648
end
4749
end

lib/beyond_api/connection.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def self.token
2626
faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
2727
faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
2828
faraday.response :logger, LOGGER, { headers: BeyondApi.configuration.log_headers,
29-
bodies: BeyondApi.configuration.log_bodies }
29+
bodies: BeyondApi.configuration.log_bodies } do |logger|
30+
logger.filter(/(code=)([a-zA-Z0-9]+)/, '\1[FILTERED]')
31+
logger.filter(/(refresh_token=)([a-zA-Z0-9.\-\_]+)/, '\1[FILTERED]')
32+
end
3033
faraday.headers['Accept'] = 'application/json'
3134
faraday.adapter(:net_http)
3235
faraday.basic_auth(BeyondApi.configuration.client_id,

lib/beyond_api/resources/products.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ def all(params = {})
9898
# }
9999
# },
100100
# "shippingPeriod" : {
101-
# "minDays" : 2,
102-
# "maxDays" : 4,
101+
# "min" : 2,
102+
# "max" : 4,
103103
# "displayUnit" : "WEEKS"
104104
# }
105105
# }'
@@ -157,8 +157,8 @@ def all(params = {})
157157
# }
158158
# },
159159
# "shippingPeriod": {
160-
# "minDays": 2,
161-
# "maxDays": 4,
160+
# "min": 2,
161+
# "max": 4,
162162
# "displayUnit": "WEEKS"
163163
# }
164164
# }

lib/beyond_api/resources/token.rb

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,32 @@ def initialize(session)
1717
raise InvalidSessionError.new("Session api_url cannot be nil") if session.api_url.nil?
1818
end
1919

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)
2622
end
2723

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)
3426
end
3527

3628
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+
3740
response, status = BeyondApi::Request.token(@session.api_url + "/oauth/token",
38-
grant_type: "client_credentials")
41+
params)
3942

4043
handle_response(response, status)
4144
end
4245

43-
private
44-
4546
def handle_response(response, status)
4647
if status.between?(200, 299)
4748
@session.access_token = response["access_token"]

lib/beyond_api/utils.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ def sanitize_key(key)
4545
end
4646

4747
def handle_all_request(url, resource, params = {})
48+
paginated_size = BeyondApi.configuration.all_pagination_size
49+
4850
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))
5052

5153
(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])
5355
end
5456

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
5660

5761
result
5862
else

lib/beyond_api/version.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# frozen_string_literal: true
2+
13
module BeyondApi
2-
VERSION = "0.16.0.pre".freeze
4+
VERSION = "0.18.1.pre"
35
end

lib/generators/templates/beyond_api_initializer.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
# Configure the request timeout in seconds. Default is 5 seconds.
1313
# config.timeout = 5.seconds
1414

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+
1518
# ==> Log configuration
1619

1720
# Configure the log level. Must be one of :debug, :info, :warn, :error,

0 commit comments

Comments
 (0)