beyond_api 0.16.1.pre → 0.19.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.template +3 -0
- data/.rubocop.yml +35 -0
- data/CHANGELOG.md +38 -1
- data/Gemfile +6 -0
- data/Gemfile.lock +68 -8
- data/Rakefile +4 -2
- data/beyond_api.gemspec +14 -10
- data/bin/console +2 -1
- data/lib/beyond_api/connection.rb +17 -6
- data/lib/beyond_api/error.rb +6 -6
- data/lib/beyond_api/ext.rb +16 -16
- data/lib/beyond_api/request.rb +21 -4
- data/lib/beyond_api/resources/carts.rb +52 -23
- data/lib/beyond_api/resources/categories_view.rb +16 -6
- data/lib/beyond_api/resources/newsletter_target.rb +10 -4
- data/lib/beyond_api/resources/orders.rb +152 -33
- data/lib/beyond_api/resources/payment_method_definitions.rb +11 -4
- data/lib/beyond_api/resources/product_attribute_definitions.rb +16 -4
- data/lib/beyond_api/resources/products/attachments.rb +0 -2
- data/lib/beyond_api/resources/products/availability.rb +20 -11
- data/lib/beyond_api/resources/products/cross_sells.rb +0 -1
- data/lib/beyond_api/resources/products/custom_attributes.rb +0 -1
- data/lib/beyond_api/resources/products/images.rb +35 -10
- data/lib/beyond_api/resources/products/searches.rb +2 -2
- data/lib/beyond_api/resources/products/variation_properties.rb +0 -1
- data/lib/beyond_api/resources/products/videos.rb +4 -3
- data/lib/beyond_api/resources/products.rb +32 -13
- data/lib/beyond_api/resources/products_view.rb +21 -5
- data/lib/beyond_api/resources/script_tags.rb +21 -5
- data/lib/beyond_api/resources/shipping_zones.rb +53 -12
- data/lib/beyond_api/resources/shop.rb +9 -2
- data/lib/beyond_api/resources/shops/address.rb +0 -1
- data/lib/beyond_api/resources/shops/attributes.rb +0 -1
- data/lib/beyond_api/resources/shops/images.rb +12 -9
- data/lib/beyond_api/resources/shops/legals.rb +14 -7
- data/lib/beyond_api/resources/shops/locations.rb +0 -1
- data/lib/beyond_api/resources/signers.rb +12 -3
- data/lib/beyond_api/resources/token.rb +20 -18
- data/lib/beyond_api/resources/users.rb +73 -15
- data/lib/beyond_api/resources/variations/availability.rb +17 -5
- data/lib/beyond_api/resources/variations/images.rb +60 -18
- data/lib/beyond_api/resources/variations.rb +14 -3
- data/lib/beyond_api/resources/webhook_subscriptions.rb +30 -8
- data/lib/beyond_api/session.rb +7 -1
- data/lib/beyond_api/utils.rb +55 -41
- data/lib/beyond_api/version.rb +3 -1
- data/lib/beyond_api.rb +6 -2
- data/lib/generators/beyond_api/install_generator.rb +1 -1
- data/lib/generators/templates/beyond_api_initializer.rb +3 -0
- metadata +57 -12
data/lib/beyond_api/utils.rb
CHANGED
@@ -4,13 +4,34 @@ module BeyondApi
|
|
4
4
|
module Utils
|
5
5
|
extend self
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
34
|
+
all_paginated(url, params)
|
14
35
|
end
|
15
36
|
end
|
16
37
|
|
@@ -20,63 +41,56 @@ module BeyondApi
|
|
20
41
|
BeyondApi.configuration.raise_error_requests ? raise(error) : error
|
21
42
|
end
|
22
43
|
|
23
|
-
def
|
24
|
-
if
|
25
|
-
return
|
26
|
-
|
27
|
-
|
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
|
-
|
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
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
if params[:paginated] == false
|
50
|
-
result = all_paginated(url, params.merge(page: 0, size: 1000))
|
51
|
-
|
52
|
-
(1..result[:page][:total_pages] - 1).each do |page|
|
53
|
-
result[:embedded][resource].concat(all_paginated(url, params.merge(page: page, size: 1000))[:embedded][resource])
|
54
|
-
end
|
55
|
-
|
56
|
-
result[:page][:size] = result[:page][:total_elements]
|
57
|
-
result[:page][:total_pages] = 1
|
58
|
-
result[:page][:number] = 0
|
59
|
-
|
60
|
-
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) }
|
61
75
|
else
|
62
|
-
|
76
|
+
data
|
63
77
|
end
|
64
78
|
end
|
65
79
|
|
66
80
|
private
|
67
81
|
|
68
|
-
|
69
|
-
|
70
|
-
when Hash; sanitize_response(thing)
|
71
|
-
when Array; thing.map { |v| transform(v) }
|
72
|
-
else; thing
|
73
|
-
end
|
74
|
-
end
|
82
|
+
def all_paginated(url, params = {})
|
83
|
+
response, status = BeyondApi::Request.get(@session, url, params)
|
75
84
|
|
76
|
-
|
77
|
-
|
85
|
+
handle_response(response, status)
|
86
|
+
end
|
78
87
|
|
79
|
-
|
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
|
80
93
|
end
|
94
|
+
end
|
81
95
|
end
|
82
96
|
end
|
data/lib/beyond_api/version.rb
CHANGED
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,
|
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("
|
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.
|
4
|
+
version: 0.19.0.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Unai Abrisketa
|
8
8
|
- Kathia Salazar
|
9
9
|
- German San Emeterio
|
10
|
+
- Kenneth Gallego
|
10
11
|
autorequire:
|
11
12
|
bindir: exe
|
12
13
|
cert_chain: []
|
13
|
-
date: 2021-
|
14
|
+
date: 2021-12-01 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:
|
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,55 +112,57 @@ dependencies:
|
|
69
112
|
- !ruby/object:Gem::Version
|
70
113
|
version: '0.9'
|
71
114
|
- !ruby/object:Gem::Dependency
|
72
|
-
name:
|
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.
|
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.
|
127
|
+
version: '2.4'
|
85
128
|
- !ruby/object:Gem::Dependency
|
86
|
-
name:
|
129
|
+
name: yard
|
87
130
|
requirement: !ruby/object:Gem::Requirement
|
88
131
|
requirements:
|
89
132
|
- - "~>"
|
90
133
|
- !ruby/object:Gem::Version
|
91
|
-
version: '
|
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: '
|
141
|
+
version: '0.9'
|
99
142
|
- !ruby/object:Gem::Dependency
|
100
143
|
name: faraday
|
101
144
|
requirement: !ruby/object:Gem::Requirement
|
102
145
|
requirements:
|
103
146
|
- - "~>"
|
104
147
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
148
|
+
version: 1.8.0
|
106
149
|
type: :runtime
|
107
150
|
prerelease: false
|
108
151
|
version_requirements: !ruby/object:Gem::Requirement
|
109
152
|
requirements:
|
110
153
|
- - "~>"
|
111
154
|
- !ruby/object:Gem::Version
|
112
|
-
version:
|
155
|
+
version: 1.8.0
|
113
156
|
description:
|
114
157
|
email:
|
115
158
|
executables: []
|
116
159
|
extensions: []
|
117
160
|
extra_rdoc_files: []
|
118
161
|
files:
|
162
|
+
- ".env.template"
|
119
163
|
- ".gitignore"
|
120
164
|
- ".rspec"
|
165
|
+
- ".rubocop.yml"
|
121
166
|
- ".travis.yml"
|
122
167
|
- ".yardopts"
|
123
168
|
- CHANGELOG.md
|
@@ -198,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
198
243
|
- !ruby/object:Gem::Version
|
199
244
|
version: 1.3.1
|
200
245
|
requirements: []
|
201
|
-
rubygems_version: 3.
|
246
|
+
rubygems_version: 3.2.16
|
202
247
|
signing_key:
|
203
248
|
specification_version: 4
|
204
249
|
summary: Ruby client to access the Beyond API
|