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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.env.template +3 -0
  3. data/.rubocop.yml +35 -0
  4. data/CHANGELOG.md +38 -1
  5. data/Gemfile +6 -0
  6. data/Gemfile.lock +68 -8
  7. data/Rakefile +4 -2
  8. data/beyond_api.gemspec +14 -10
  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 +21 -4
  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 +35 -10
  25. data/lib/beyond_api/resources/products/searches.rb +2 -2
  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 +32 -13
  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 +20 -18
  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 +60 -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 -41
  47. data/lib/beyond_api/version.rb +3 -1
  48. data/lib/beyond_api.rb +6 -2
  49. data/lib/generators/beyond_api/install_generator.rb +1 -1
  50. data/lib/generators/templates/beyond_api_initializer.rb +3 -0
  51. metadata +57 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e21d3e55d80fdab110e763b80945554aaa37db10d9cd1d6420e1048992990442
4
- data.tar.gz: abfb64188b9e2b04a223b7cbc839eec16b2f6307ecccf0a8c6b484ab55259231
3
+ metadata.gz: e2d0989b9c2efdb165c8411d97aac823941fc1eae61e2dac30352746191fa146
4
+ data.tar.gz: 449c75efb650ec8b65f9686c5993b2d6ab643002f1732e9fb8c28c24ce574a38
5
5
  SHA512:
6
- metadata.gz: 9a51c07ca44a5f137e8c2cea3e3249e607323ec9a58a661895d4541ccd573d234c72fae261632341e8e44077a8eca1f34e0748cad693961e4195e0c6b881089a
7
- data.tar.gz: 64b13f1fa84d4292c6f414071dd64beed61acddcefff7c8aa952cc089e53bf519d8823e7ad9ebf98cfb779fb60855411c603c435b07a5c74caa07a9a243a3ac3
6
+ metadata.gz: 5e3aabaf8efe9424ecca4a4df173d8ecb370ff73e60144c2bdf1306f889b1dc3bb62ffe0f12307b8c12ce9c52b8f74e86d43362d69f4f405274ede477bf9fd69
7
+ data.tar.gz: beea89efdd34dd846ded24f57f0e64f8ec0202146efcdd239f7b06b2ff99b2cd2a0a30fb7ef250afd3509cf3e538a990fedc9ae7250852c0dc4411bc1b805cc4
data/.env.template ADDED
@@ -0,0 +1,3 @@
1
+ CLIENT_ID=""
2
+ CLIENT_SECRET=""
3
+ SHOP_URL=""
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,40 @@
1
+ ### v0.19.0.pre
2
+
3
+ * features
4
+ * Upload multiple images for products and variations
5
+
6
+ ### v0.18.2.pre
7
+
8
+ * bug-fixes
9
+ * Move `#products.update_reserve_stock` from `POST` to `PUT`.
10
+
11
+ * enhancements
12
+ * Update how `api_url` is set on `BeyondApi::Session`.
13
+
14
+ * features
15
+ * Install, configure and fix most of the Rubocop issues.
16
+
17
+ ### v0.18.1.pre
18
+
19
+ * bug-fixes
20
+ * Prevent logging `code` and `refresh_token` on `/api/token` calls.
21
+
22
+ ### v0.18.0.pre
23
+
24
+ * features
25
+ * Add new token retrieval/refresh methods
26
+ * `Token#authorization_code`
27
+ * `Token#refresh_token`
28
+ * `Token#client_credentials`
29
+ * Add alias methods for avoiding deprecation
30
+ * `refresh` -> `refresh_token`
31
+ * `create` -> `authorization_code`
32
+
33
+ ### v0.17.0.pre
34
+
35
+ * enhancements
36
+ * Add customizable pagination size when sending `paginated: false` parameter to `#all` requests.
37
+
1
38
  ### v0.16.1.pre
2
39
 
3
40
  * bug-fixes
@@ -26,7 +63,7 @@
26
63
 
27
64
  * features
28
65
  * Add `Products#assign_variation_attribute_as_differentiator`
29
-
66
+
30
67
  ### v0.13.0.pre
31
68
 
32
69
  * features
data/Gemfile CHANGED
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in beyond_api.gemspec
4
6
  gemspec
5
7
 
6
8
  gem "pry"
9
+
10
+ group :test do
11
+ gem "factory_bot"
12
+ end
data/Gemfile.lock CHANGED
@@ -1,28 +1,61 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- beyond_api (0.16.1.pre)
5
- faraday (~> 0.15)
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)
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
- faker (2.18.0)
21
+ factory_bot (6.2.0)
22
+ activesupport (>= 5.0.0)
23
+ faker (2.19.0)
15
24
  i18n (>= 1.6, < 2)
16
- faraday (0.17.4)
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
- i18n (1.8.10)
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.2)
39
- yard (0.9.26)
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.1.4
115
+ 2.2.31
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 :default => :spec
9
+ task default: :spec
8
10
 
9
11
  YARD::Rake::YardocTask.new do |t|
10
- t.files = ['lib/**/*.rb']
12
+ t.files = ["lib/**/*.rb"]
11
13
  end
data/beyond_api.gemspec CHANGED
@@ -1,17 +1,18 @@
1
+ # frozen_string_literal: true
1
2
 
2
- lib = File.expand_path("../lib", __FILE__)
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
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = "beyond_api"
8
9
  spec.version = BeyondApi::VERSION
9
- spec.authors = ["Unai Abrisketa", "Kathia Salazar", "German San Emeterio"]
10
+ spec.authors = ["Unai Abrisketa", "Kathia Salazar", "German San Emeterio", "Kenneth Gallego"]
10
11
 
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('..', __FILE__)) do
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", "~> 2.0"
24
- spec.add_development_dependency "rake", "~> 10.0"
25
- spec.add_development_dependency "rspec", "~> 3.0"
26
- spec.add_development_dependency "yard", "~> 0.9"
27
- spec.add_development_dependency "faker", "~> 2.2"
28
- spec.add_development_dependency "dotenv", "~> 2.7"
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.15"
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? and ENV["CLIENT_SECRET"].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 'faraday'
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['Accept'] = 'application/json'
17
- faraday.headers['Content-Type'] = 'application/json'
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(BeyondApi.configuration.client_id,
33
- BeyondApi.configuration.client_secret)
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
@@ -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['errorId']
9
- @details = data['details']
10
- @trace_id = data['traceId']
11
- @error = data['error']
12
- @error_description = data['error_description']
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['message'] || data['error_description'])
16
+ super(data["message"] || data["error_description"])
17
17
  end
18
18
  end
19
19
  end
@@ -5,13 +5,13 @@ class Hash
5
5
  result = {}
6
6
  each do |key, value|
7
7
  result[yield(key)] = case value
8
- when Hash
9
- value.deep_transform_keys(&block)
10
- when Array
11
- value.camelize_keys
12
- else
13
- value
14
- end
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
- self.gsub(/::/, '/').
35
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
36
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
37
- tr("-", "_").
38
- downcase
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]*/) { |match| match.capitalize }
44
+ string = string.sub(/^[a-z\d]*/, &:capitalize)
45
45
  else
46
- string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
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
- when Hash, Array; elem.camelize_keys
57
- else; elem
56
+ when Hash, Array then elem.camelize_keys
57
+ else; elem
58
58
  end
59
59
  end
60
60
  end
@@ -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['Authorization'] = "Bearer #{ session.access_token }" unless session.access_token.nil?
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
 
@@ -21,7 +23,7 @@ module BeyondApi
21
23
  define_method(method) do |session, path, body = {}, params = {}|
22
24
  response = BeyondApi::Connection.default.send(method) do |request|
23
25
  request.url(session.api_url + path)
24
- request.headers['Authorization'] = "Bearer #{ session.access_token }" unless session.access_token.nil?
26
+ request.headers["Authorization"] = "Bearer #{session.access_token}" unless session.access_token.nil?
25
27
  request.params = params.to_h.camelize_keys
26
28
  request.body = body.camelize_keys.to_json
27
29
  end
@@ -34,8 +36,8 @@ module BeyondApi
34
36
  def self.upload(session, path, file_binary, content_type, params)
35
37
  response = BeyondApi::Connection.default.post do |request|
36
38
  request.url(session.api_url + path)
37
- request.headers['Authorization'] = "Bearer #{ session.access_token }" unless session.access_token.nil?
38
- request.headers['Content-Type'] = content_type
39
+ request.headers["Authorization"] = "Bearer #{session.access_token}" unless session.access_token.nil?
40
+ request.headers["Content-Type"] = content_type
39
41
  request.params = params.to_h.camelize_keys
40
42
  request.body = file_binary
41
43
  end
@@ -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