beyond_api 0.16.0.pre → 0.18.2.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +33 -0
  3. data/CHANGELOG.md +38 -1
  4. data/Gemfile +2 -0
  5. data/Gemfile.lock +30 -2
  6. data/Rakefile +4 -2
  7. data/beyond_api.gemspec +13 -9
  8. data/bin/console +2 -1
  9. data/lib/beyond_api/connection.rb +7 -4
  10. data/lib/beyond_api/error.rb +6 -6
  11. data/lib/beyond_api/ext.rb +16 -16
  12. data/lib/beyond_api/request.rb +4 -4
  13. data/lib/beyond_api/resources/carts.rb +52 -23
  14. data/lib/beyond_api/resources/categories_view.rb +16 -6
  15. data/lib/beyond_api/resources/newsletter_target.rb +10 -4
  16. data/lib/beyond_api/resources/orders.rb +152 -33
  17. data/lib/beyond_api/resources/payment_method_definitions.rb +11 -4
  18. data/lib/beyond_api/resources/product_attribute_definitions.rb +16 -4
  19. data/lib/beyond_api/resources/products/attachments.rb +0 -2
  20. data/lib/beyond_api/resources/products/availability.rb +20 -11
  21. data/lib/beyond_api/resources/products/cross_sells.rb +0 -1
  22. data/lib/beyond_api/resources/products/custom_attributes.rb +0 -1
  23. data/lib/beyond_api/resources/products/images.rb +12 -9
  24. data/lib/beyond_api/resources/products/searches.rb +2 -2
  25. data/lib/beyond_api/resources/products/variation_properties.rb +0 -1
  26. data/lib/beyond_api/resources/products/videos.rb +4 -3
  27. data/lib/beyond_api/resources/products.rb +32 -13
  28. data/lib/beyond_api/resources/products_view.rb +21 -5
  29. data/lib/beyond_api/resources/script_tags.rb +21 -5
  30. data/lib/beyond_api/resources/shipping_zones.rb +53 -12
  31. data/lib/beyond_api/resources/shop.rb +9 -2
  32. data/lib/beyond_api/resources/shops/address.rb +0 -1
  33. data/lib/beyond_api/resources/shops/attributes.rb +0 -1
  34. data/lib/beyond_api/resources/shops/images.rb +12 -9
  35. data/lib/beyond_api/resources/shops/legals.rb +14 -7
  36. data/lib/beyond_api/resources/shops/locations.rb +0 -1
  37. data/lib/beyond_api/resources/signers.rb +12 -3
  38. data/lib/beyond_api/resources/token.rb +20 -18
  39. data/lib/beyond_api/resources/users.rb +73 -15
  40. data/lib/beyond_api/resources/variations/availability.rb +17 -5
  41. data/lib/beyond_api/resources/variations/images.rb +32 -15
  42. data/lib/beyond_api/resources/variations.rb +14 -3
  43. data/lib/beyond_api/resources/webhook_subscriptions.rb +30 -8
  44. data/lib/beyond_api/session.rb +7 -1
  45. data/lib/beyond_api/utils.rb +44 -38
  46. data/lib/beyond_api/version.rb +3 -1
  47. data/lib/beyond_api.rb +6 -2
  48. data/lib/generators/beyond_api/install_generator.rb +1 -1
  49. data/lib/generators/templates/beyond_api_initializer.rb +3 -0
  50. metadata +59 -15
@@ -4,13 +4,23 @@ module BeyondApi
4
4
  module Utils
5
5
  extend self
6
6
 
7
- def handle_response(response, status, respond_with_true: false)
8
- if status.between?(200, 299)
9
- return true if respond_with_true
10
- response = sanitize_response(response)
11
- BeyondApi.configuration.object_struct_responses ? to_object_struct(response) : response
7
+ def handle_all_request(url, resource, params = {})
8
+ paginated_size = BeyondApi.configuration.all_pagination_size
9
+
10
+ if params[:paginated] == false
11
+ result = all_paginated(url, params.merge(page: 0, size: paginated_size))
12
+
13
+ (1..result[:page][:total_pages] - 1).each do |page|
14
+ result[:embedded][resource].concat(all_paginated(url, params.merge(page: page, size: paginated_size))[:embedded][resource])
15
+ end
16
+
17
+ result[:page][:size] = result[:page][:total_elements]
18
+ result[:page][:total_pages] = 1
19
+ result[:page][:number] = 0
20
+
21
+ result
12
22
  else
13
- handle_error(response, status)
23
+ all_paginated(url, params)
14
24
  end
15
25
  end
16
26
 
@@ -20,60 +30,56 @@ module BeyondApi
20
30
  BeyondApi.configuration.raise_error_requests ? raise(error) : error
21
31
  end
22
32
 
23
- def to_object_struct(data)
24
- if data.is_a? Hash
25
- return OpenStruct.new(data.map { |key, val| [key, to_object_struct(val)] }.to_h)
26
- elsif data.is_a? Array
27
- return data.map { |o| to_object_struct(o) }
33
+ def handle_response(response, status, respond_with_true: false)
34
+ if status.between?(200, 299)
35
+ return true if respond_with_true
36
+
37
+ response = sanitize_response(response)
38
+ BeyondApi.configuration.object_struct_responses ? to_object_struct(response) : response
28
39
  else
29
- return data
40
+ handle_error(response, status)
30
41
  end
31
42
  end
32
43
 
44
+ def sanitize_key(key)
45
+ key.chars.first == "_" ? key[1..-1] : key
46
+ end
47
+
33
48
  def sanitize_response(hash)
34
49
  {}.tap do |h|
35
50
  hash.each do |key, value|
36
51
  next if key == "_links" && BeyondApi.configuration.remove_response_links
52
+
37
53
  key = sanitize_key(key) if BeyondApi.configuration.remove_response_key_underscores
38
54
  h[key.underscore.to_sym] = transform(value)
39
55
  end
40
56
  end
41
57
  end
42
58
 
43
- def sanitize_key(key)
44
- key.chars.first == "_" ? key[1..-1] : key
45
- end
46
-
47
- def handle_all_request(url, resource, params = {})
48
- if params[:paginated] == false
49
- result = all_paginated(url, { page: 0, size: 1000 })
50
-
51
- (1..result[:page][:total_pages] - 1).each do |page|
52
- result[:embedded][resource].concat(all_paginated(url, { page: page, size: 1000 })[:embedded][resource])
53
- end
54
-
55
- result.is_a?(Hash) ? result.delete(:page) : result.delete_field(:page)
56
-
57
- result
59
+ def to_object_struct(data)
60
+ if data.is_a? Hash
61
+ return OpenStruct.new(data.map { |key, val| [key, to_object_struct(val)] }.to_h)
62
+ elsif data.is_a? Array
63
+ return data.map { |o| to_object_struct(o) }
58
64
  else
59
- all_paginated(url, params)
65
+ return data
60
66
  end
61
67
  end
62
68
 
63
69
  private
64
70
 
65
- def transform(thing)
66
- case thing
67
- when Hash; sanitize_response(thing)
68
- when Array; thing.map { |v| transform(v) }
69
- else; thing
70
- end
71
- end
71
+ def all_paginated(url, params = {})
72
+ response, status = BeyondApi::Request.get(@session, url, params)
72
73
 
73
- def all_paginated(url, params = {})
74
- response, status = BeyondApi::Request.get(@session, url, params)
74
+ handle_response(response, status)
75
+ end
75
76
 
76
- handle_response(response, status)
77
+ def transform(thing)
78
+ case thing
79
+ when Hash; sanitize_response(thing)
80
+ when Array; thing.map { |v| transform(v) }
81
+ else; thing
77
82
  end
83
+ end
78
84
  end
79
85
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BeyondApi
2
- VERSION = "0.16.0.pre".freeze
4
+ VERSION = "0.18.2.pre"
3
5
  end
data/lib/beyond_api.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "beyond_api/version"
2
4
 
3
5
  require "logger"
@@ -25,9 +27,9 @@ module BeyondApi
25
27
  end
26
28
 
27
29
  class Configuration
28
- attr_accessor :client_id, :client_secret, :open_timeout, :timeout, :remove_response_links,
30
+ attr_accessor :client_id, :client_secret, :open_timeout, :timeout, :remove_response_links,
29
31
  :remove_response_key_underscores, :object_struct_responses, :raise_error_requests,
30
- :log_headers, :log_bodies, :log_level
32
+ :log_headers, :log_bodies, :log_level, :all_pagination_size
31
33
 
32
34
  def initialize
33
35
  @client_id = nil
@@ -42,6 +44,8 @@ module BeyondApi
42
44
  @log_level = :info
43
45
  @log_headers = false
44
46
  @log_bodies = false
47
+
48
+ @all_pagination_size = 200
45
49
  end
46
50
  end
47
51
  end
@@ -3,7 +3,7 @@
3
3
  module BeyondApi
4
4
  module Generators
5
5
  class InstallGenerator < Rails::Generators::Base
6
- source_root File.expand_path("../../templates", __FILE__)
6
+ source_root File.expand_path("../templates", __dir__)
7
7
 
8
8
  def copy_initializer
9
9
  template "beyond_api_initializer.rb", "config/initializers/beyond_api.rb"
@@ -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.16.0.pre
4
+ version: 0.18.2.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-24 00:00:00.000000000 Z
14
+ date: 2021-11-25 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: bundler
@@ -26,6 +27,34 @@ dependencies:
26
27
  - - "~>"
27
28
  - !ruby/object:Gem::Version
28
29
  version: '2.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: dotenv
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.7'
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.7'
44
+ - !ruby/object:Gem::Dependency
45
+ name: faker
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - "~>"
49
+ - !ruby/object:Gem::Version
50
+ version: '2.2'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.2'
29
58
  - !ruby/object:Gem::Dependency
30
59
  name: rake
31
60
  requirement: !ruby/object:Gem::Requirement
@@ -55,7 +84,21 @@ dependencies:
55
84
  - !ruby/object:Gem::Version
56
85
  version: '3.0'
57
86
  - !ruby/object:Gem::Dependency
58
- name: yard
87
+ name: rubocop
88
+ requirement: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - "~>"
91
+ - !ruby/object:Gem::Version
92
+ version: '1.20'
93
+ type: :development
94
+ prerelease: false
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - "~>"
98
+ - !ruby/object:Gem::Version
99
+ version: '1.20'
100
+ - !ruby/object:Gem::Dependency
101
+ name: rubocop-ordered_methods
59
102
  requirement: !ruby/object:Gem::Requirement
60
103
  requirements:
61
104
  - - "~>"
@@ -69,33 +112,33 @@ dependencies:
69
112
  - !ruby/object:Gem::Version
70
113
  version: '0.9'
71
114
  - !ruby/object:Gem::Dependency
72
- name: faker
115
+ name: rubocop-rspec
73
116
  requirement: !ruby/object:Gem::Requirement
74
117
  requirements:
75
118
  - - "~>"
76
119
  - !ruby/object:Gem::Version
77
- version: '2.2'
120
+ version: '2.4'
78
121
  type: :development
79
122
  prerelease: false
80
123
  version_requirements: !ruby/object:Gem::Requirement
81
124
  requirements:
82
125
  - - "~>"
83
126
  - !ruby/object:Gem::Version
84
- version: '2.2'
127
+ version: '2.4'
85
128
  - !ruby/object:Gem::Dependency
86
- name: dotenv
129
+ name: yard
87
130
  requirement: !ruby/object:Gem::Requirement
88
131
  requirements:
89
132
  - - "~>"
90
133
  - !ruby/object:Gem::Version
91
- version: '2.7'
134
+ version: '0.9'
92
135
  type: :development
93
136
  prerelease: false
94
137
  version_requirements: !ruby/object:Gem::Requirement
95
138
  requirements:
96
139
  - - "~>"
97
140
  - !ruby/object:Gem::Version
98
- version: '2.7'
141
+ version: '0.9'
99
142
  - !ruby/object:Gem::Dependency
100
143
  name: faraday
101
144
  requirement: !ruby/object:Gem::Requirement
@@ -110,14 +153,15 @@ dependencies:
110
153
  - - "~>"
111
154
  - !ruby/object:Gem::Version
112
155
  version: '0.15'
113
- description:
114
- email:
156
+ description:
157
+ email:
115
158
  executables: []
116
159
  extensions: []
117
160
  extra_rdoc_files: []
118
161
  files:
119
162
  - ".gitignore"
120
163
  - ".rspec"
164
+ - ".rubocop.yml"
121
165
  - ".travis.yml"
122
166
  - ".yardopts"
123
167
  - CHANGELOG.md
@@ -183,7 +227,7 @@ files:
183
227
  homepage: https://github.com/ePages-de/beyond_api-ruby_client
184
228
  licenses: []
185
229
  metadata: {}
186
- post_install_message:
230
+ post_install_message:
187
231
  rdoc_options: []
188
232
  require_paths:
189
233
  - lib
@@ -198,8 +242,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
198
242
  - !ruby/object:Gem::Version
199
243
  version: 1.3.1
200
244
  requirements: []
201
- rubygems_version: 3.0.3
202
- signing_key:
245
+ rubygems_version: 3.2.26
246
+ signing_key:
203
247
  specification_version: 4
204
248
  summary: Ruby client to access the Beyond API
205
249
  test_files: []