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.
- checksums.yaml +4 -4
- data/.env.template +3 -0
- data/.rubocop.yml +35 -0
- data/CHANGELOG.md +34 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +68 -8
- data/Rakefile +4 -2
- data/beyond_api.gemspec +13 -9
- 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 +25 -6
- 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 +36 -11
- data/lib/beyond_api/resources/products/searches.rb +62 -1
- 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 +28 -9
- 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 +6 -5
- 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 +92 -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 -42
- data/lib/beyond_api/version.rb +3 -1
- data/lib/beyond_api.rb +3 -1
- data/lib/generators/beyond_api/install_generator.rb +1 -1
- metadata +61 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40f831d05843ba3350e2aa8a390715004c1bc99f82836a9f40b60e7f0888ef25
|
4
|
+
data.tar.gz: 4ae22902b0eb2b17941d3e1c59c039eba3d374cb6c0836091ed96906e2f2eae3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 555e694512db5677f89330f54586fc377461e7d5ea17d8a4d8fb4c65851c01ab2f443ee182b1ebe50f725e57eceada098d4eb11e7e2d538f2a5b8bffd69fafd1
|
7
|
+
data.tar.gz: 41752eb106202b23d7c1a449e30d6e4defe811d00bddb1280403829fe71d59683a08ae0b7797c615ff88a583ddcbcd05aa60c72dcc1b6b47ce0b610732c8ac6f
|
data/.env.template
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-ordered_methods
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- spec/**/*.rb
|
8
|
+
NewCops: enable
|
9
|
+
|
10
|
+
Style/StringLiterals:
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Metrics/AbcSize:
|
14
|
+
Enabled: false
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Enabled: false
|
17
|
+
Metrics/BlockLength:
|
18
|
+
Enabled: false
|
19
|
+
Metrics/ClassLength:
|
20
|
+
Enabled: false
|
21
|
+
Style/Documentation:
|
22
|
+
Enabled: false
|
23
|
+
Metrics/CyclomaticComplexity:
|
24
|
+
Enabled: false
|
25
|
+
Metrics/PerceivedComplexity:
|
26
|
+
Enabled: false
|
27
|
+
|
28
|
+
Layout/LineLength:
|
29
|
+
IgnoredPatterns: ['(\A|\s)#']
|
30
|
+
|
31
|
+
Style/AsciiComments:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Style/SymbolArray:
|
35
|
+
EnforcedStyle: brackets
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,37 @@
|
|
1
|
+
### v0.21.0.pre
|
2
|
+
|
3
|
+
* bug-fixes
|
4
|
+
* Fix `Products#sort_images` method
|
5
|
+
|
6
|
+
* features
|
7
|
+
* Add `Variations#sort_images` method
|
8
|
+
### v0.20.0.pre
|
9
|
+
|
10
|
+
* features
|
11
|
+
* Add product search method
|
12
|
+
* `Products#search`
|
13
|
+
|
14
|
+
### v0.19.0.pre
|
15
|
+
|
16
|
+
* features
|
17
|
+
* Upload multiple images for products and variations
|
18
|
+
|
19
|
+
### v0.18.2.pre
|
20
|
+
|
21
|
+
* bug-fixes
|
22
|
+
* Move `#products.update_reserve_stock` from `POST` to `PUT`.
|
23
|
+
|
24
|
+
* enhancements
|
25
|
+
* Update how `api_url` is set on `BeyondApi::Session`.
|
26
|
+
|
27
|
+
* features
|
28
|
+
* Install, configure and fix most of the Rubocop issues.
|
29
|
+
|
30
|
+
### v0.18.1.pre
|
31
|
+
|
32
|
+
* bug-fixes
|
33
|
+
* Prevent logging `code` and `refresh_token` on `/api/token` calls.
|
34
|
+
|
1
35
|
### v0.18.0.pre
|
2
36
|
|
3
37
|
* features
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,28 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
beyond_api (0.
|
5
|
-
faraday (~> 0
|
4
|
+
beyond_api (0.21.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)
|
16
|
+
ast (2.4.2)
|
10
17
|
coderay (1.1.3)
|
11
18
|
concurrent-ruby (1.1.9)
|
12
19
|
diff-lcs (1.4.4)
|
13
20
|
dotenv (2.7.6)
|
14
|
-
|
21
|
+
factory_bot (6.2.0)
|
22
|
+
activesupport (>= 5.0.0)
|
23
|
+
faker (2.19.0)
|
15
24
|
i18n (>= 1.6, < 2)
|
16
|
-
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)
|
17
34
|
multipart-post (>= 1.2, < 3)
|
18
|
-
|
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)
|
19
45
|
concurrent-ruby (~> 1.0)
|
20
46
|
method_source (1.0.0)
|
47
|
+
minitest (5.14.4)
|
21
48
|
multipart-post (2.1.1)
|
49
|
+
parallel (1.21.0)
|
50
|
+
parser (3.0.3.1)
|
51
|
+
ast (~> 2.4.1)
|
22
52
|
pry (0.14.1)
|
23
53
|
coderay (~> 1.1)
|
24
54
|
method_source (~> 1.0)
|
55
|
+
rainbow (3.0.0)
|
25
56
|
rake (10.5.0)
|
57
|
+
regexp_parser (2.1.1)
|
58
|
+
rexml (3.2.5)
|
26
59
|
rspec (3.10.0)
|
27
60
|
rspec-core (~> 3.10.0)
|
28
61
|
rspec-expectations (~> 3.10.0)
|
@@ -35,8 +68,31 @@ GEM
|
|
35
68
|
rspec-mocks (3.10.2)
|
36
69
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
70
|
rspec-support (~> 3.10.0)
|
38
|
-
rspec-support (3.10.
|
39
|
-
|
71
|
+
rspec-support (3.10.3)
|
72
|
+
rubocop (1.23.0)
|
73
|
+
parallel (~> 1.10)
|
74
|
+
parser (>= 3.0.0.0)
|
75
|
+
rainbow (>= 2.2.2, < 4.0)
|
76
|
+
regexp_parser (>= 1.8, < 3.0)
|
77
|
+
rexml
|
78
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
79
|
+
ruby-progressbar (~> 1.7)
|
80
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
81
|
+
rubocop-ast (1.13.0)
|
82
|
+
parser (>= 3.0.1.1)
|
83
|
+
rubocop-ordered_methods (0.9)
|
84
|
+
rubocop (>= 1.0)
|
85
|
+
rubocop-rspec (2.6.0)
|
86
|
+
rubocop (~> 1.19)
|
87
|
+
ruby-progressbar (1.11.0)
|
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)
|
40
96
|
|
41
97
|
PLATFORMS
|
42
98
|
ruby
|
@@ -45,11 +101,15 @@ DEPENDENCIES
|
|
45
101
|
beyond_api!
|
46
102
|
bundler (~> 2.0)
|
47
103
|
dotenv (~> 2.7)
|
104
|
+
factory_bot
|
48
105
|
faker (~> 2.2)
|
49
106
|
pry
|
50
107
|
rake (~> 10.0)
|
51
108
|
rspec (~> 3.0)
|
109
|
+
rubocop (~> 1.20)
|
110
|
+
rubocop-ordered_methods (~> 0.9)
|
111
|
+
rubocop-rspec (~> 2.4)
|
52
112
|
yard (~> 0.9)
|
53
113
|
|
54
114
|
BUNDLED WITH
|
55
|
-
2.
|
115
|
+
2.3.0
|
data/Rakefile
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
4
|
require "rspec/core/rake_task"
|
3
5
|
require "yard"
|
4
6
|
|
5
7
|
RSpec::Core::RakeTask.new(:spec)
|
6
8
|
|
7
|
-
task :
|
9
|
+
task default: :spec
|
8
10
|
|
9
11
|
YARD::Rake::YardocTask.new do |t|
|
10
|
-
|
12
|
+
t.files = ["lib/**/*.rb"]
|
11
13
|
end
|
data/beyond_api.gemspec
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
|
2
|
-
lib = File.expand_path("
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require "beyond_api/version"
|
5
6
|
|
@@ -11,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
11
12
|
spec.summary = "Ruby client to access the Beyond API"
|
12
13
|
spec.homepage = "https://github.com/ePages-de/beyond_api-ruby_client"
|
13
14
|
|
14
|
-
spec.files = Dir.chdir(File.expand_path(
|
15
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
15
16
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
17
|
end
|
17
18
|
spec.bindir = "exe"
|
@@ -20,12 +21,15 @@ Gem::Specification.new do |spec|
|
|
20
21
|
|
21
22
|
spec.required_ruby_version = ">= 2.5.1"
|
22
23
|
|
23
|
-
spec.add_development_dependency "bundler",
|
24
|
-
spec.add_development_dependency "
|
25
|
-
spec.add_development_dependency "
|
26
|
-
spec.add_development_dependency "
|
27
|
-
spec.add_development_dependency "
|
28
|
-
spec.add_development_dependency "
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
25
|
+
spec.add_development_dependency "dotenv", "~> 2.7"
|
26
|
+
spec.add_development_dependency "faker", "~> 2.2"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "rubocop", "~> 1.20"
|
30
|
+
spec.add_development_dependency "rubocop-ordered_methods", "~> 0.9"
|
31
|
+
spec.add_development_dependency "rubocop-rspec", "~> 2.4"
|
32
|
+
spec.add_development_dependency "yard", "~> 0.9"
|
29
33
|
|
30
|
-
spec.add_dependency "faraday", "~> 0
|
34
|
+
spec.add_dependency "faraday", "~> 1.8.0"
|
31
35
|
end
|
data/bin/console
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
require "bundler/setup"
|
4
5
|
require "dotenv/load"
|
5
6
|
require "beyond_api"
|
6
7
|
|
7
|
-
unless ENV["CLIENT_ID"].nil?
|
8
|
+
unless ENV["CLIENT_ID"].nil? && ENV["CLIENT_SECRET"].nil?
|
8
9
|
BeyondApi.setup do |config|
|
9
10
|
config.client_id = ENV["CLIENT_ID"]
|
10
11
|
config.client_secret = ENV["CLIENT_SECRET"]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
3
|
+
require "faraday"
|
4
4
|
|
5
5
|
module BeyondApi
|
6
6
|
class Connection
|
@@ -13,8 +13,8 @@ module BeyondApi
|
|
13
13
|
faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
|
14
14
|
faraday.response :logger, LOGGER, { headers: BeyondApi.configuration.log_headers,
|
15
15
|
bodies: BeyondApi.configuration.log_bodies }
|
16
|
-
faraday.headers[
|
17
|
-
faraday.headers[
|
16
|
+
faraday.headers["Accept"] = "application/json"
|
17
|
+
faraday.headers["Content-Type"] = "application/json"
|
18
18
|
faraday.request(:multipart)
|
19
19
|
faraday.request(:url_encoded)
|
20
20
|
faraday.adapter(:net_http)
|
@@ -26,11 +26,22 @@ module BeyondApi
|
|
26
26
|
faraday.options[:open_timeout] = BeyondApi.configuration.open_timeout.to_i
|
27
27
|
faraday.options[:timeout] = BeyondApi.configuration.timeout.to_i
|
28
28
|
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
|
30
33
|
faraday.headers['Accept'] = 'application/json'
|
31
34
|
faraday.adapter(:net_http)
|
32
|
-
faraday.basic_auth
|
33
|
-
|
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
|
34
45
|
end
|
35
46
|
end
|
36
47
|
end
|
data/lib/beyond_api/error.rb
CHANGED
@@ -5,15 +5,15 @@ module BeyondApi
|
|
5
5
|
attr_reader :error_id, :details, :trace_id, :full_message, :status_code, :error, :error_description
|
6
6
|
|
7
7
|
def initialize(data, status_code = nil)
|
8
|
-
@error_id = data[
|
9
|
-
@details = data[
|
10
|
-
@trace_id = data[
|
11
|
-
@error = data[
|
12
|
-
@error_description = data[
|
8
|
+
@error_id = data["errorId"]
|
9
|
+
@details = data["details"]
|
10
|
+
@trace_id = data["traceId"]
|
11
|
+
@error = data["error"]
|
12
|
+
@error_description = data["error_description"]
|
13
13
|
@full_message = data
|
14
14
|
@status_code = status_code
|
15
15
|
|
16
|
-
super(data[
|
16
|
+
super(data["message"] || data["error_description"])
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
data/lib/beyond_api/ext.rb
CHANGED
@@ -5,13 +5,13 @@ class Hash
|
|
5
5
|
result = {}
|
6
6
|
each do |key, value|
|
7
7
|
result[yield(key)] = case value
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
8
|
+
when Hash
|
9
|
+
value.deep_transform_keys(&block)
|
10
|
+
when Array
|
11
|
+
value.camelize_keys
|
12
|
+
else
|
13
|
+
value
|
14
|
+
end
|
15
15
|
end
|
16
16
|
result
|
17
17
|
end
|
@@ -31,19 +31,19 @@ class String
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def underscore
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
gsub(/::/, "/")
|
35
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
36
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
37
|
+
.tr("-", "_")
|
38
|
+
.downcase
|
39
39
|
end
|
40
40
|
|
41
41
|
def camelize(uppercase_first_letter = true)
|
42
42
|
string = self
|
43
43
|
if uppercase_first_letter
|
44
|
-
string = string.sub(/^[a-z\d]
|
44
|
+
string = string.sub(/^[a-z\d]*/, &:capitalize)
|
45
45
|
else
|
46
|
-
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)
|
46
|
+
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/, &:downcase)
|
47
47
|
end
|
48
48
|
string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub("/", "::")
|
49
49
|
end
|
@@ -53,8 +53,8 @@ class Array
|
|
53
53
|
def camelize_keys
|
54
54
|
map do |elem|
|
55
55
|
case elem
|
56
|
-
|
57
|
-
|
56
|
+
when Hash, Array then elem.camelize_keys
|
57
|
+
else; elem
|
58
58
|
end
|
59
59
|
end
|
60
60
|
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
|
@@ -9,7 +11,7 @@ module BeyondApi
|
|
9
11
|
define_method(method) do |session, path, params = {}|
|
10
12
|
response = BeyondApi::Connection.default.send(method) do |request|
|
11
13
|
request.url(session.api_url + path)
|
12
|
-
request.headers[
|
14
|
+
request.headers["Authorization"] = "Bearer #{session.access_token}" unless session.access_token.nil?
|
13
15
|
request.params = params.to_h.camelize_keys
|
14
16
|
end
|
15
17
|
|
@@ -18,12 +20,14 @@ module BeyondApi
|
|
18
20
|
end
|
19
21
|
|
20
22
|
[:post, :put, :patch].each do |method|
|
21
|
-
define_method(method) do |session, path, body = {}, params = {}|
|
23
|
+
define_method(method) do |session, path, body = {}, params = {}, content_type = 'application/json'|
|
22
24
|
response = BeyondApi::Connection.default.send(method) do |request|
|
23
25
|
request.url(session.api_url + path)
|
24
|
-
request.headers[
|
26
|
+
request.headers["Authorization"] = "Bearer #{session.access_token}" unless session.access_token.nil?
|
27
|
+
request.headers["Content-Type"] = content_type
|
25
28
|
request.params = params.to_h.camelize_keys
|
26
|
-
|
29
|
+
|
30
|
+
request.body = body.respond_to?(:camelize_keys) ? body.camelize_keys.to_json : body
|
27
31
|
end
|
28
32
|
|
29
33
|
[response.body.blank? ? nil : JSON.parse(response.body), response.status]
|
@@ -34,8 +38,8 @@ module BeyondApi
|
|
34
38
|
def self.upload(session, path, file_binary, content_type, params)
|
35
39
|
response = BeyondApi::Connection.default.post do |request|
|
36
40
|
request.url(session.api_url + path)
|
37
|
-
request.headers[
|
38
|
-
request.headers[
|
41
|
+
request.headers["Authorization"] = "Bearer #{session.access_token}" unless session.access_token.nil?
|
42
|
+
request.headers["Content-Type"] = content_type
|
39
43
|
request.params = params.to_h.camelize_keys
|
40
44
|
request.body = file_binary
|
41
45
|
end
|
@@ -51,5 +55,20 @@ module BeyondApi
|
|
51
55
|
|
52
56
|
[response.body.blank? ? nil : JSON.parse(response.body), response.status]
|
53
57
|
end
|
58
|
+
|
59
|
+
def self.upload_by_form(session, path, files, params)
|
60
|
+
response = BeyondApi::Connection.multipart.post do |request|
|
61
|
+
request.url(session.api_url + path)
|
62
|
+
request.headers["Authorization"] = "Bearer #{session.access_token}" unless session.access_token.nil?
|
63
|
+
request.options[:params_encoder] = Faraday::FlatParamsEncoder
|
64
|
+
request.params = params.to_h.camelize_keys
|
65
|
+
files = files.split unless files.is_a? Array
|
66
|
+
upload_files = files.map{ |file| Faraday::FilePart.new(File.open(file),
|
67
|
+
BeyondApi::Utils.file_content_type(file)) }
|
68
|
+
request.body = { image: upload_files }
|
69
|
+
end
|
70
|
+
|
71
|
+
[response.body.blank? ? nil : JSON.parse(response.body), response.status]
|
72
|
+
end
|
54
73
|
end
|
55
74
|
end
|