beyond_api 0.18.2.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 +2 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +49 -17
- data/beyond_api.gemspec +1 -1
- data/lib/beyond_api/connection.rb +10 -2
- data/lib/beyond_api/request.rb +17 -0
- data/lib/beyond_api/resources/products/images.rb +30 -8
- data/lib/beyond_api/resources/variations/images.rb +35 -10
- data/lib/beyond_api/utils.rb +16 -5
- data/lib/beyond_api/version.rb +1 -1
- metadata +11 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2d0989b9c2efdb165c8411d97aac823941fc1eae61e2dac30352746191fa146
|
4
|
+
data.tar.gz: 449c75efb650ec8b65f9686c5993b2d6ab643002f1732e9fb8c28c24ce574a38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e3aabaf8efe9424ecca4a4df173d8ecb370ff73e60144c2bdf1306f889b1dc3bb62ffe0f12307b8c12ce9c52b8f74e86d43362d69f4f405274ede477bf9fd69
|
7
|
+
data.tar.gz: beea89efdd34dd846ded24f57f0e64f8ec0202146efcdd239f7b06b2ff99b2cd2a0a30fb7ef250afd3509cf3e538a990fedc9ae7250852c0dc4411bc1b805cc4
|
data/.env.template
ADDED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,27 +1,53 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
beyond_api (0.
|
5
|
-
faraday (~> 0
|
4
|
+
beyond_api (0.19.0.pre)
|
5
|
+
faraday (~> 1.8.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
+
activesupport (6.1.4.1)
|
11
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
12
|
+
i18n (>= 1.6, < 2)
|
13
|
+
minitest (>= 5.1)
|
14
|
+
tzinfo (~> 2.0)
|
15
|
+
zeitwerk (~> 2.3)
|
10
16
|
ast (2.4.2)
|
11
17
|
coderay (1.1.3)
|
12
18
|
concurrent-ruby (1.1.9)
|
13
19
|
diff-lcs (1.4.4)
|
14
20
|
dotenv (2.7.6)
|
15
|
-
|
21
|
+
factory_bot (6.2.0)
|
22
|
+
activesupport (>= 5.0.0)
|
23
|
+
faker (2.19.0)
|
16
24
|
i18n (>= 1.6, < 2)
|
17
|
-
faraday (
|
25
|
+
faraday (1.8.0)
|
26
|
+
faraday-em_http (~> 1.0)
|
27
|
+
faraday-em_synchrony (~> 1.0)
|
28
|
+
faraday-excon (~> 1.1)
|
29
|
+
faraday-httpclient (~> 1.0.1)
|
30
|
+
faraday-net_http (~> 1.0)
|
31
|
+
faraday-net_http_persistent (~> 1.1)
|
32
|
+
faraday-patron (~> 1.0)
|
33
|
+
faraday-rack (~> 1.0)
|
18
34
|
multipart-post (>= 1.2, < 3)
|
19
|
-
|
35
|
+
ruby2_keywords (>= 0.0.4)
|
36
|
+
faraday-em_http (1.0.0)
|
37
|
+
faraday-em_synchrony (1.0.0)
|
38
|
+
faraday-excon (1.1.0)
|
39
|
+
faraday-httpclient (1.0.1)
|
40
|
+
faraday-net_http (1.0.1)
|
41
|
+
faraday-net_http_persistent (1.2.0)
|
42
|
+
faraday-patron (1.0.0)
|
43
|
+
faraday-rack (1.0.0)
|
44
|
+
i18n (1.8.11)
|
20
45
|
concurrent-ruby (~> 1.0)
|
21
46
|
method_source (1.0.0)
|
47
|
+
minitest (5.14.4)
|
22
48
|
multipart-post (2.1.1)
|
23
|
-
parallel (1.
|
24
|
-
parser (3.0.
|
49
|
+
parallel (1.21.0)
|
50
|
+
parser (3.0.3.1)
|
25
51
|
ast (~> 2.4.1)
|
26
52
|
pry (0.14.1)
|
27
53
|
coderay (~> 1.1)
|
@@ -42,26 +68,31 @@ GEM
|
|
42
68
|
rspec-mocks (3.10.2)
|
43
69
|
diff-lcs (>= 1.2.0, < 2.0)
|
44
70
|
rspec-support (~> 3.10.0)
|
45
|
-
rspec-support (3.10.
|
46
|
-
rubocop (1.
|
71
|
+
rspec-support (3.10.3)
|
72
|
+
rubocop (1.23.0)
|
47
73
|
parallel (~> 1.10)
|
48
74
|
parser (>= 3.0.0.0)
|
49
75
|
rainbow (>= 2.2.2, < 4.0)
|
50
76
|
regexp_parser (>= 1.8, < 3.0)
|
51
77
|
rexml
|
52
|
-
rubocop-ast (>= 1.
|
78
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
53
79
|
ruby-progressbar (~> 1.7)
|
54
80
|
unicode-display_width (>= 1.4.0, < 3.0)
|
55
|
-
rubocop-ast (1.
|
81
|
+
rubocop-ast (1.13.0)
|
56
82
|
parser (>= 3.0.1.1)
|
57
83
|
rubocop-ordered_methods (0.9)
|
58
84
|
rubocop (>= 1.0)
|
59
|
-
rubocop-rspec (2.
|
60
|
-
rubocop (~> 1.
|
61
|
-
rubocop-ast (>= 1.1.0)
|
85
|
+
rubocop-rspec (2.6.0)
|
86
|
+
rubocop (~> 1.19)
|
62
87
|
ruby-progressbar (1.11.0)
|
63
|
-
|
64
|
-
|
88
|
+
ruby2_keywords (0.0.5)
|
89
|
+
tzinfo (2.0.4)
|
90
|
+
concurrent-ruby (~> 1.0)
|
91
|
+
unicode-display_width (2.1.0)
|
92
|
+
webrick (1.7.0)
|
93
|
+
yard (0.9.27)
|
94
|
+
webrick (~> 1.7.0)
|
95
|
+
zeitwerk (2.5.1)
|
65
96
|
|
66
97
|
PLATFORMS
|
67
98
|
ruby
|
@@ -70,6 +101,7 @@ DEPENDENCIES
|
|
70
101
|
beyond_api!
|
71
102
|
bundler (~> 2.0)
|
72
103
|
dotenv (~> 2.7)
|
104
|
+
factory_bot
|
73
105
|
faker (~> 2.2)
|
74
106
|
pry
|
75
107
|
rake (~> 10.0)
|
@@ -80,4 +112,4 @@ DEPENDENCIES
|
|
80
112
|
yard (~> 0.9)
|
81
113
|
|
82
114
|
BUNDLED WITH
|
83
|
-
2.2.
|
115
|
+
2.2.31
|
data/beyond_api.gemspec
CHANGED
@@ -32,8 +32,16 @@ module BeyondApi
|
|
32
32
|
end
|
33
33
|
faraday.headers['Accept'] = 'application/json'
|
34
34
|
faraday.adapter(:net_http)
|
35
|
-
faraday.basic_auth
|
36
|
-
|
35
|
+
faraday.request :basic_auth, BeyondApi.configuration.client_id, BeyondApi.configuration.client_secret
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.multipart
|
40
|
+
Faraday.new(ssl: { verify: true }) do |faraday|
|
41
|
+
faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
|
42
|
+
faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
|
43
|
+
faraday.request :multipart, { flat_encode: true }
|
44
|
+
faraday.adapter Faraday.default_adapter
|
37
45
|
end
|
38
46
|
end
|
39
47
|
end
|
data/lib/beyond_api/request.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "json"
|
4
|
+
require "faraday"
|
5
|
+
require "beyond_api/utils"
|
4
6
|
|
5
7
|
module BeyondApi
|
6
8
|
class Request
|
@@ -51,5 +53,20 @@ module BeyondApi
|
|
51
53
|
|
52
54
|
[response.body.blank? ? nil : JSON.parse(response.body), response.status]
|
53
55
|
end
|
56
|
+
|
57
|
+
def self.upload_by_form(session, path, files, params)
|
58
|
+
response = BeyondApi::Connection.multipart.post do |request|
|
59
|
+
request.url(session.api_url + path)
|
60
|
+
request.headers["Authorization"] = "Bearer #{session.access_token}" unless session.access_token.nil?
|
61
|
+
request.options[:params_encoder] = Faraday::FlatParamsEncoder
|
62
|
+
request.params = params.to_h.camelize_keys
|
63
|
+
files = files.split unless files.is_a? Array
|
64
|
+
upload_files = files.map{ |file| Faraday::FilePart.new(File.open(file),
|
65
|
+
BeyondApi::Utils.file_content_type(file)) }
|
66
|
+
request.body = { image: upload_files }
|
67
|
+
end
|
68
|
+
|
69
|
+
[response.body.blank? ? nil : JSON.parse(response.body), response.status]
|
70
|
+
end
|
54
71
|
end
|
55
72
|
end
|
@@ -185,14 +185,7 @@ module BeyondApi
|
|
185
185
|
# session.products.upload_image("4125b993-49fc-47c8-b9b3-76d8871e4e06", "/home/epages/file.png", "file.png")
|
186
186
|
#
|
187
187
|
def upload_image(product_id, image_path, image_name)
|
188
|
-
content_type =
|
189
|
-
when ".png"
|
190
|
-
"image/png"
|
191
|
-
when ".jpg", ".jpeg"
|
192
|
-
"image/jpeg"
|
193
|
-
when ".gif"
|
194
|
-
"image/gif"
|
195
|
-
end
|
188
|
+
content_type = file_content_type(image_path)
|
196
189
|
image_binary = File.binread(image_path)
|
197
190
|
|
198
191
|
response, status = BeyondApi::Request.upload(@session,
|
@@ -203,5 +196,34 @@ module BeyondApi
|
|
203
196
|
|
204
197
|
handle_response(response, status, respond_with_true: true)
|
205
198
|
end
|
199
|
+
|
200
|
+
# A +POST+ request is used to upload up to 10 images and add them to a product. The body of the request must contain the content of the images.
|
201
|
+
#
|
202
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/4125b993-49fc-47c8-b9b3-76d8871e4e06/images?fileName=file.png&fileName=file2.png' -i -X POST \
|
203
|
+
# -H 'Content-Type: multipart/form-data' \
|
204
|
+
# -H 'Authorization: Bearer <Access token>' \
|
205
|
+
# -F 'image=@/home/epages/file.png' \
|
206
|
+
# -F 'image=@/home/epages/file2.png'
|
207
|
+
#
|
208
|
+
# @beyond_api.scopes +prod:u+
|
209
|
+
#
|
210
|
+
# @param product_id [String] the product UUID
|
211
|
+
# @param images_path [Array] the images path
|
212
|
+
# @param images_name [Array] the images name
|
213
|
+
#
|
214
|
+
# @return true
|
215
|
+
#
|
216
|
+
# @example
|
217
|
+
# session.products.upload_multiple_images("4125b993-49fc-47c8-b9b3-76d8871e4e06",
|
218
|
+
# ["/home/epages/file.png", "/home/epages/file2.png"], ["file.png", "file2.png"])
|
219
|
+
#
|
220
|
+
def upload_multiple_images(product_id, images_path, images_name)
|
221
|
+
response, status = BeyondApi::Request.upload_by_form(@session,
|
222
|
+
"/products/#{product_id}/images",
|
223
|
+
images_path,
|
224
|
+
file_name: images_name)
|
225
|
+
|
226
|
+
handle_response(response, status)
|
227
|
+
end
|
206
228
|
end
|
207
229
|
end
|
@@ -140,8 +140,8 @@ module BeyondApi
|
|
140
140
|
#
|
141
141
|
# @param product_id [String] the product UUID
|
142
142
|
# @param variation_id [String] the variation UUID
|
143
|
-
# @param
|
144
|
-
# @param
|
143
|
+
# @param images_path [Array] the images path
|
144
|
+
# @param images_name [Array] the images name
|
145
145
|
#
|
146
146
|
# @return [OpenStruct]
|
147
147
|
#
|
@@ -154,15 +154,9 @@ module BeyondApi
|
|
154
154
|
# session.variations.upload_image("4125b993-49fc-47c8-b9b3-76d8871e4e06", "d7fecf94-2e57-4122-8c94-a0acd840c111", "/home/epages/file.png", "file.png")
|
155
155
|
#
|
156
156
|
def upload_image(product_id, variation_id, image_path, image_name)
|
157
|
+
content_type = file_content_type(image_path)
|
157
158
|
path = "/products/#{product_id}/variations/#{variation_id}/images"
|
158
|
-
|
159
|
-
when ".png"
|
160
|
-
"image/png"
|
161
|
-
when ".jpg", ".jpeg"
|
162
|
-
"image/jpeg"
|
163
|
-
when ".gif"
|
164
|
-
"image/gif"
|
165
|
-
end
|
159
|
+
|
166
160
|
image_binary = File.binread(image_path)
|
167
161
|
|
168
162
|
response, status = BeyondApi::Request.upload(@session,
|
@@ -173,5 +167,36 @@ module BeyondApi
|
|
173
167
|
|
174
168
|
handle_response(response, status, respond_with_true: true)
|
175
169
|
end
|
170
|
+
|
171
|
+
#
|
172
|
+
# A +POST+ request is used to upload up to 10 images to the image storage and assign the URL of the images to up to 30 variations. The body of the request must contain the content of the images.
|
173
|
+
#
|
174
|
+
# $ curl 'https://api-shop.beyondshop.cloud/api/products/4125b993-49fc-47c8-b9b3-76d8871e4e06/variations/images?fileName=file.png&fileName=file2.png&variation=ca53ae26-e7c6-44a4-8070-9fca08cc87ed&variation=ab63fa3a-c2ac-4074-aaa3-b547217b042d' -i -X POST \
|
175
|
+
# -H 'Content-Type: multipart/form-data' \
|
176
|
+
# -H 'Authorization: Bearer <Access token>' \
|
177
|
+
# -F 'image=@/home/epages/file.png' \
|
178
|
+
# -F 'image=@/home/epages/file2.png'
|
179
|
+
#
|
180
|
+
# @beyond_api.scopes +prod:u+
|
181
|
+
#
|
182
|
+
# @param product_id [String] the product UUID
|
183
|
+
# @param variation_id [String] the variation UUID
|
184
|
+
# @param images_path [String] the image path
|
185
|
+
# @param images_name [String] the image name
|
186
|
+
#
|
187
|
+
# @return [OpenStruct]
|
188
|
+
#
|
189
|
+
# @example
|
190
|
+
# session.variations.upload_multiple_images("4125b993-49fc-47c8-b9b3-76d8871e4e06", "d7fecf94-2e57-4122-8c94-a0acd840c111",
|
191
|
+
# ["/home/epages/file.png", "/home/epages/file2.png"], ["file.png", "file2.png"])
|
192
|
+
#
|
193
|
+
def upload_multiple_images(product_id, variation_id, images_path, images_name)
|
194
|
+
response, status = BeyondApi::Request.upload_by_form(@session,
|
195
|
+
"/products/#{product_id}/variations/#{variation_id}/images",
|
196
|
+
images_path,
|
197
|
+
file_name: images_name)
|
198
|
+
|
199
|
+
handle_response(response, status)
|
200
|
+
end
|
176
201
|
end
|
177
202
|
end
|
data/lib/beyond_api/utils.rb
CHANGED
@@ -4,6 +4,17 @@ module BeyondApi
|
|
4
4
|
module Utils
|
5
5
|
extend self
|
6
6
|
|
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
|
+
|
7
18
|
def handle_all_request(url, resource, params = {})
|
8
19
|
paginated_size = BeyondApi.configuration.all_pagination_size
|
9
20
|
|
@@ -58,11 +69,11 @@ module BeyondApi
|
|
58
69
|
|
59
70
|
def to_object_struct(data)
|
60
71
|
if data.is_a? Hash
|
61
|
-
|
72
|
+
OpenStruct.new(data.map { |key, val| [key, to_object_struct(val)] }.to_h)
|
62
73
|
elsif data.is_a? Array
|
63
|
-
|
74
|
+
data.map { |o| to_object_struct(o) }
|
64
75
|
else
|
65
|
-
|
76
|
+
data
|
66
77
|
end
|
67
78
|
end
|
68
79
|
|
@@ -76,8 +87,8 @@ module BeyondApi
|
|
76
87
|
|
77
88
|
def transform(thing)
|
78
89
|
case thing
|
79
|
-
when Hash
|
80
|
-
when Array
|
90
|
+
when Hash then sanitize_response(thing)
|
91
|
+
when Array then thing.map { |v| transform(v) }
|
81
92
|
else; thing
|
82
93
|
end
|
83
94
|
end
|
data/lib/beyond_api/version.rb
CHANGED
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.
|
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
10
|
- Kenneth Gallego
|
11
|
-
autorequire:
|
11
|
+
autorequire:
|
12
12
|
bindir: exe
|
13
13
|
cert_chain: []
|
14
|
-
date: 2021-
|
14
|
+
date: 2021-12-01 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: bundler
|
@@ -145,20 +145,21 @@ dependencies:
|
|
145
145
|
requirements:
|
146
146
|
- - "~>"
|
147
147
|
- !ruby/object:Gem::Version
|
148
|
-
version:
|
148
|
+
version: 1.8.0
|
149
149
|
type: :runtime
|
150
150
|
prerelease: false
|
151
151
|
version_requirements: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
153
|
- - "~>"
|
154
154
|
- !ruby/object:Gem::Version
|
155
|
-
version:
|
156
|
-
description:
|
157
|
-
email:
|
155
|
+
version: 1.8.0
|
156
|
+
description:
|
157
|
+
email:
|
158
158
|
executables: []
|
159
159
|
extensions: []
|
160
160
|
extra_rdoc_files: []
|
161
161
|
files:
|
162
|
+
- ".env.template"
|
162
163
|
- ".gitignore"
|
163
164
|
- ".rspec"
|
164
165
|
- ".rubocop.yml"
|
@@ -227,7 +228,7 @@ files:
|
|
227
228
|
homepage: https://github.com/ePages-de/beyond_api-ruby_client
|
228
229
|
licenses: []
|
229
230
|
metadata: {}
|
230
|
-
post_install_message:
|
231
|
+
post_install_message:
|
231
232
|
rdoc_options: []
|
232
233
|
require_paths:
|
233
234
|
- lib
|
@@ -242,8 +243,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
243
|
- !ruby/object:Gem::Version
|
243
244
|
version: 1.3.1
|
244
245
|
requirements: []
|
245
|
-
rubygems_version: 3.2.
|
246
|
-
signing_key:
|
246
|
+
rubygems_version: 3.2.16
|
247
|
+
signing_key:
|
247
248
|
specification_version: 4
|
248
249
|
summary: Ruby client to access the Beyond API
|
249
250
|
test_files: []
|