beyond_api 0.18.0.pre → 0.21.0.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/.env.template +3 -0
  3. data/.rubocop.yml +35 -0
  4. data/CHANGELOG.md +34 -0
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +68 -8
  7. data/Rakefile +4 -2
  8. data/beyond_api.gemspec +13 -9
  9. data/bin/console +2 -1
  10. data/lib/beyond_api/connection.rb +17 -6
  11. data/lib/beyond_api/error.rb +6 -6
  12. data/lib/beyond_api/ext.rb +16 -16
  13. data/lib/beyond_api/request.rb +25 -6
  14. data/lib/beyond_api/resources/carts.rb +52 -23
  15. data/lib/beyond_api/resources/categories_view.rb +16 -6
  16. data/lib/beyond_api/resources/newsletter_target.rb +10 -4
  17. data/lib/beyond_api/resources/orders.rb +152 -33
  18. data/lib/beyond_api/resources/payment_method_definitions.rb +11 -4
  19. data/lib/beyond_api/resources/product_attribute_definitions.rb +16 -4
  20. data/lib/beyond_api/resources/products/attachments.rb +0 -2
  21. data/lib/beyond_api/resources/products/availability.rb +20 -11
  22. data/lib/beyond_api/resources/products/cross_sells.rb +0 -1
  23. data/lib/beyond_api/resources/products/custom_attributes.rb +0 -1
  24. data/lib/beyond_api/resources/products/images.rb +36 -11
  25. data/lib/beyond_api/resources/products/searches.rb +62 -1
  26. data/lib/beyond_api/resources/products/variation_properties.rb +0 -1
  27. data/lib/beyond_api/resources/products/videos.rb +4 -3
  28. data/lib/beyond_api/resources/products.rb +28 -9
  29. data/lib/beyond_api/resources/products_view.rb +21 -5
  30. data/lib/beyond_api/resources/script_tags.rb +21 -5
  31. data/lib/beyond_api/resources/shipping_zones.rb +53 -12
  32. data/lib/beyond_api/resources/shop.rb +9 -2
  33. data/lib/beyond_api/resources/shops/address.rb +0 -1
  34. data/lib/beyond_api/resources/shops/attributes.rb +0 -1
  35. data/lib/beyond_api/resources/shops/images.rb +12 -9
  36. data/lib/beyond_api/resources/shops/legals.rb +14 -7
  37. data/lib/beyond_api/resources/shops/locations.rb +0 -1
  38. data/lib/beyond_api/resources/signers.rb +12 -3
  39. data/lib/beyond_api/resources/token.rb +6 -5
  40. data/lib/beyond_api/resources/users.rb +73 -15
  41. data/lib/beyond_api/resources/variations/availability.rb +17 -5
  42. data/lib/beyond_api/resources/variations/images.rb +92 -18
  43. data/lib/beyond_api/resources/variations.rb +14 -3
  44. data/lib/beyond_api/resources/webhook_subscriptions.rb +30 -8
  45. data/lib/beyond_api/session.rb +7 -1
  46. data/lib/beyond_api/utils.rb +55 -42
  47. data/lib/beyond_api/version.rb +3 -1
  48. data/lib/beyond_api.rb +3 -1
  49. data/lib/generators/beyond_api/install_generator.rb +1 -1
  50. metadata +61 -17
@@ -4,13 +4,34 @@ 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 file_content_type(file_path)
8
+ case File.extname(file_path)
9
+ when ".png"
10
+ "image/png"
11
+ when ".jpg", ".jpeg"
12
+ "image/jpeg"
13
+ when ".gif"
14
+ "image/gif"
15
+ end
16
+ end
17
+
18
+ def handle_all_request(url, resource, params = {})
19
+ paginated_size = BeyondApi.configuration.all_pagination_size
20
+
21
+ if params[:paginated] == false
22
+ result = all_paginated(url, params.merge(page: 0, size: paginated_size))
23
+
24
+ (1..result[:page][:total_pages] - 1).each do |page|
25
+ result[:embedded][resource].concat(all_paginated(url, params.merge(page: page, size: paginated_size))[:embedded][resource])
26
+ end
27
+
28
+ result[:page][:size] = result[:page][:total_elements]
29
+ result[:page][:total_pages] = 1
30
+ result[:page][:number] = 0
31
+
32
+ result
12
33
  else
13
- handle_error(response, status)
34
+ all_paginated(url, params)
14
35
  end
15
36
  end
16
37
 
@@ -20,64 +41,56 @@ module BeyondApi
20
41
  BeyondApi.configuration.raise_error_requests ? raise(error) : error
21
42
  end
22
43
 
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) }
44
+ def handle_response(response, status, respond_with_true: false)
45
+ if status.between?(200, 299)
46
+ return true if respond_with_true
47
+
48
+ response = sanitize_response(response)
49
+ BeyondApi.configuration.object_struct_responses ? to_object_struct(response) : response
28
50
  else
29
- return data
51
+ handle_error(response, status)
30
52
  end
31
53
  end
32
54
 
55
+ def sanitize_key(key)
56
+ key.chars.first == "_" ? key[1..-1] : key
57
+ end
58
+
33
59
  def sanitize_response(hash)
34
60
  {}.tap do |h|
35
61
  hash.each do |key, value|
36
62
  next if key == "_links" && BeyondApi.configuration.remove_response_links
63
+
37
64
  key = sanitize_key(key) if BeyondApi.configuration.remove_response_key_underscores
38
65
  h[key.underscore.to_sym] = transform(value)
39
66
  end
40
67
  end
41
68
  end
42
69
 
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
- paginated_size = BeyondApi.configuration.all_pagination_size
49
-
50
- if params[:paginated] == false
51
- result = all_paginated(url, params.merge(page: 0, size: paginated_size))
52
-
53
- (1..result[:page][:total_pages] - 1).each do |page|
54
- result[:embedded][resource].concat(all_paginated(url, params.merge(page: page, size: paginated_size))[:embedded][resource])
55
- end
56
-
57
- result[:page][:size] = result[:page][:total_elements]
58
- result[:page][:total_pages] = 1
59
- result[:page][:number] = 0
60
-
61
- result
70
+ def to_object_struct(data)
71
+ if data.is_a? Hash
72
+ OpenStruct.new(data.map { |key, val| [key, to_object_struct(val)] }.to_h)
73
+ elsif data.is_a? Array
74
+ data.map { |o| to_object_struct(o) }
62
75
  else
63
- all_paginated(url, params)
76
+ data
64
77
  end
65
78
  end
66
79
 
67
80
  private
68
81
 
69
- def transform(thing)
70
- case thing
71
- when Hash; sanitize_response(thing)
72
- when Array; thing.map { |v| transform(v) }
73
- else; thing
74
- end
75
- end
82
+ def all_paginated(url, params = {})
83
+ response, status = BeyondApi::Request.get(@session, url, params)
76
84
 
77
- def all_paginated(url, params = {})
78
- response, status = BeyondApi::Request.get(@session, url, params)
85
+ handle_response(response, status)
86
+ end
79
87
 
80
- handle_response(response, status)
88
+ def transform(thing)
89
+ case thing
90
+ when Hash then sanitize_response(thing)
91
+ when Array then thing.map { |v| transform(v) }
92
+ else; thing
81
93
  end
94
+ end
82
95
  end
83
96
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module BeyondApi
2
- VERSION = "0.18.0.pre".freeze
4
+ VERSION = "0.21.0.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,7 +27,7 @@ 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
32
  :log_headers, :log_bodies, :log_level, :all_pagination_size
31
33
 
@@ -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"
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beyond_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0.pre
4
+ version: 0.21.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Unai Abrisketa
8
8
  - Kathia Salazar
9
9
  - German San Emeterio
10
10
  - Kenneth Gallego
11
- autorequire:
11
+ autorequire:
12
12
  bindir: exe
13
13
  cert_chain: []
14
- date: 2021-08-20 00:00:00.000000000 Z
14
+ date: 2022-01-18 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler
@@ -27,6 +27,34 @@ dependencies:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
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'
30
58
  - !ruby/object:Gem::Dependency
31
59
  name: rake
32
60
  requirement: !ruby/object:Gem::Requirement
@@ -56,7 +84,21 @@ dependencies:
56
84
  - !ruby/object:Gem::Version
57
85
  version: '3.0'
58
86
  - !ruby/object:Gem::Dependency
59
- 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
60
102
  requirement: !ruby/object:Gem::Requirement
61
103
  requirements:
62
104
  - - "~>"
@@ -70,55 +112,57 @@ dependencies:
70
112
  - !ruby/object:Gem::Version
71
113
  version: '0.9'
72
114
  - !ruby/object:Gem::Dependency
73
- name: faker
115
+ name: rubocop-rspec
74
116
  requirement: !ruby/object:Gem::Requirement
75
117
  requirements:
76
118
  - - "~>"
77
119
  - !ruby/object:Gem::Version
78
- version: '2.2'
120
+ version: '2.4'
79
121
  type: :development
80
122
  prerelease: false
81
123
  version_requirements: !ruby/object:Gem::Requirement
82
124
  requirements:
83
125
  - - "~>"
84
126
  - !ruby/object:Gem::Version
85
- version: '2.2'
127
+ version: '2.4'
86
128
  - !ruby/object:Gem::Dependency
87
- name: dotenv
129
+ name: yard
88
130
  requirement: !ruby/object:Gem::Requirement
89
131
  requirements:
90
132
  - - "~>"
91
133
  - !ruby/object:Gem::Version
92
- version: '2.7'
134
+ version: '0.9'
93
135
  type: :development
94
136
  prerelease: false
95
137
  version_requirements: !ruby/object:Gem::Requirement
96
138
  requirements:
97
139
  - - "~>"
98
140
  - !ruby/object:Gem::Version
99
- version: '2.7'
141
+ version: '0.9'
100
142
  - !ruby/object:Gem::Dependency
101
143
  name: faraday
102
144
  requirement: !ruby/object:Gem::Requirement
103
145
  requirements:
104
146
  - - "~>"
105
147
  - !ruby/object:Gem::Version
106
- version: '0.15'
148
+ version: 1.8.0
107
149
  type: :runtime
108
150
  prerelease: false
109
151
  version_requirements: !ruby/object:Gem::Requirement
110
152
  requirements:
111
153
  - - "~>"
112
154
  - !ruby/object:Gem::Version
113
- version: '0.15'
114
- description:
115
- email:
155
+ version: 1.8.0
156
+ description:
157
+ email:
116
158
  executables: []
117
159
  extensions: []
118
160
  extra_rdoc_files: []
119
161
  files:
162
+ - ".env.template"
120
163
  - ".gitignore"
121
164
  - ".rspec"
165
+ - ".rubocop.yml"
122
166
  - ".travis.yml"
123
167
  - ".yardopts"
124
168
  - CHANGELOG.md
@@ -184,7 +228,7 @@ files:
184
228
  homepage: https://github.com/ePages-de/beyond_api-ruby_client
185
229
  licenses: []
186
230
  metadata: {}
187
- post_install_message:
231
+ post_install_message:
188
232
  rdoc_options: []
189
233
  require_paths:
190
234
  - lib
@@ -199,8 +243,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
199
243
  - !ruby/object:Gem::Version
200
244
  version: 1.3.1
201
245
  requirements: []
202
- rubygems_version: 3.2.26
203
- signing_key:
246
+ rubygems_version: 3.2.16
247
+ signing_key:
204
248
  specification_version: 4
205
249
  summary: Ruby client to access the Beyond API
206
250
  test_files: []