magento 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,103 +1,108 @@
1
- # frozen_string_literal: true
2
-
3
- require 'uri'
4
- require 'http'
5
-
6
- module Magento
7
- class Request
8
- attr_reader :token, :store
9
-
10
- def initialize(token: Magento.token, store: Magento.store)
11
- @token = token
12
- @store = store
13
- end
14
-
15
- def get(resource, token: nil)
16
- save_request(:get, url(resource))
17
- handle_error http_auth.get(url(resource))
18
- end
19
-
20
- def put(resource, body)
21
- save_request(:put, url(resource), body)
22
- handle_error http_auth.put(url(resource), json: body)
23
- end
24
-
25
- def post(resource, body = nil, url_completa = false)
26
- url = url_completa ? resource : url(resource)
27
- save_request(:post, url, body)
28
- handle_error http_auth.post(url, json: body)
29
- end
30
-
31
- private
32
-
33
- def http_auth
34
- HTTP.auth("Bearer #{token}")
35
- end
36
-
37
- def base_url
38
- url = Magento.url.to_s.sub(%r{/$}, '')
39
- "#{url}/rest/#{store}/V1"
40
- end
41
-
42
- def url(resource)
43
- "#{base_url}/#{resource}"
44
- end
45
-
46
- def search_params(field:, value:, conditionType: :eq)
47
- create_params(
48
- filter_groups: {
49
- '0': {
50
- filters: {
51
- '0': {
52
- field: field,
53
- conditionType: conditionType,
54
- value: value
55
- }
56
- }
57
- }
58
- }
59
- )
60
- end
61
-
62
- def field_params(fields:)
63
- create_params(fields: fields)
64
- end
65
-
66
- def create_params(filter_groups: nil, fields: nil, current_page: 1)
67
- CGI.unescape(
68
- {
69
- searchCriteria: {
70
- currentPage: current_page,
71
- filterGroups: filter_groups
72
- }.compact,
73
- fields: fields
74
- }.compact.to_query
75
- )
76
- end
77
-
78
- def handle_error(resp)
79
- return resp if resp.status.success?
80
-
81
- begin
82
- msg = resp.parse['message']
83
- errors = resp.parse['errors']
84
- rescue StandardError
85
- msg = 'Failed access to the magento server'
86
- errors = []
87
- end
88
-
89
- raise Magento::NotFound.new(msg, resp.status.code, errors, @request) if resp.status.not_found?
90
-
91
- raise Magento::MagentoError.new(msg, resp.status.code, errors, @request)
92
- end
93
-
94
- def save_request(method, url, body = nil)
95
- begin
96
- body = body[:product].reject { |e| e == :media_gallery_entries }
97
- rescue StandardError
98
- end
99
-
100
- @request = { method: method, url: url, body: body }
101
- end
102
- end
103
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'uri'
4
+ require 'http'
5
+
6
+ module Magento
7
+ class Request
8
+ attr_reader :token, :store
9
+
10
+ def initialize(token: Magento.token, store: Magento.store)
11
+ @token = token
12
+ @store = store
13
+ end
14
+
15
+ def get(resource)
16
+ save_request(:get, url(resource))
17
+ handle_error http_auth.get(url(resource))
18
+ end
19
+
20
+ def put(resource, body)
21
+ save_request(:put, url(resource), body)
22
+ handle_error http_auth.put(url(resource), json: body)
23
+ end
24
+
25
+ def post(resource, body = nil, url_completa = false)
26
+ url = url_completa ? resource : url(resource)
27
+ save_request(:post, url, body)
28
+ handle_error http_auth.post(url, json: body)
29
+ end
30
+
31
+ def delete(resource)
32
+ save_request(:delete, url(resource))
33
+ handle_error http_auth.delete(url(resource))
34
+ end
35
+
36
+ private
37
+
38
+ def http_auth
39
+ HTTP.auth("Bearer #{token}")
40
+ end
41
+
42
+ def base_url
43
+ url = Magento.url.to_s.sub(%r{/$}, '')
44
+ "#{url}/rest/#{store}/V1"
45
+ end
46
+
47
+ def url(resource)
48
+ "#{base_url}/#{resource}"
49
+ end
50
+
51
+ def search_params(field:, value:, conditionType: :eq)
52
+ create_params(
53
+ filter_groups: {
54
+ '0': {
55
+ filters: {
56
+ '0': {
57
+ field: field,
58
+ conditionType: conditionType,
59
+ value: value
60
+ }
61
+ }
62
+ }
63
+ }
64
+ )
65
+ end
66
+
67
+ def field_params(fields:)
68
+ create_params(fields: fields)
69
+ end
70
+
71
+ def create_params(filter_groups: nil, fields: nil, current_page: 1)
72
+ CGI.unescape(
73
+ {
74
+ searchCriteria: {
75
+ currentPage: current_page,
76
+ filterGroups: filter_groups
77
+ }.compact,
78
+ fields: fields
79
+ }.compact.to_query
80
+ )
81
+ end
82
+
83
+ def handle_error(resp)
84
+ return resp if resp.status.success?
85
+
86
+ begin
87
+ msg = resp.parse['message']
88
+ errors = resp.parse['errors']
89
+ rescue StandardError
90
+ msg = 'Failed access to the magento server'
91
+ errors = []
92
+ end
93
+
94
+ raise Magento::NotFound.new(msg, resp.status.code, errors, @request) if resp.status.not_found?
95
+
96
+ raise Magento::MagentoError.new(msg, resp.status.code, errors, @request)
97
+ end
98
+
99
+ def save_request(method, url, body = nil)
100
+ begin
101
+ body = body[:product].reject { |e| e == :media_gallery_entries }
102
+ rescue StandardError
103
+ end
104
+
105
+ @request = { method: method, url: url, body: body }
106
+ end
107
+ end
108
+ end
@@ -1,4 +1,4 @@
1
- module Magento
2
- class Address
3
- end
4
- end
1
+ module Magento
2
+ class Address
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module Magento
2
- class AvailableRegion
3
- end
4
- end
1
+ module Magento
2
+ class AvailableRegion
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Magento
2
+ class BundleProductOption
3
+ end
4
+ end
@@ -1,6 +1,6 @@
1
- # frozen_string_literal: true
2
-
3
- module Magento
4
- class CategoryLink
5
- end
6
- end
1
+ # frozen_string_literal: true
2
+
3
+ module Magento
4
+ class CategoryLink
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module Magento
2
+ class ConfigurableProductOption
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module Magento
2
- class CustomAttribute
3
- end
4
- end
1
+ module Magento
2
+ class CustomAttribute
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module Magento
2
- class ExtensionAttribute
3
- end
1
+ module Magento
2
+ class ExtensionAttribute
3
+ end
4
4
  end
@@ -0,0 +1,4 @@
1
+ module Magento
2
+ class Filter
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Magento
2
+ class FilterGroup
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module Magento
2
- class MediaGalleryEntry
3
- end
4
- end
1
+ module Magento
2
+ class MediaGalleryEntry
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module Magento
2
- class Option
3
- end
4
- end
1
+ module Magento
2
+ class Option
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module Magento
2
- class ProductLink
3
- end
4
- end
1
+ module Magento
2
+ class ProductLink
3
+ end
4
+ end
@@ -1,4 +1,4 @@
1
- module Magento
2
- class Region
3
- end
4
- end
1
+ module Magento
2
+ class Region
3
+ end
4
+ end
@@ -0,0 +1,5 @@
1
+ module Magento
2
+ class SearchCriterium
3
+ attr_accessor :current_page, :filter_groups, :page_size
4
+ end
5
+ end
@@ -1,4 +1,4 @@
1
- module Magento
2
- class StockItem
3
- end
1
+ module Magento
2
+ class StockItem
3
+ end
4
4
  end
@@ -1,4 +1,4 @@
1
- module Magento
2
- class TierPrice
3
- end
4
- end
1
+ module Magento
2
+ class TierPrice
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Magento
2
+ VERSION = '0.4.1'
3
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'magento/version'
7
+
8
+ Gem::Specification.new do |s|
9
+ s.name = 'magento-ruby'
10
+ s.version = Magento::VERSION
11
+ s.date = '2020-07-31'
12
+ s.summary = 'Magento Ruby library'
13
+ s.description = 'Magento Ruby library'
14
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
15
+ s.authors = ['Wallas Faria']
16
+ s.email = 'wallasfaria@hotmail.com'
17
+ s.homepage = 'https://github.com/WallasFaria/magento-ruby'
18
+ s.require_paths = ['lib']
19
+
20
+ s.add_dependency 'dry-inflector', '~> 0.2.0'
21
+ s.add_dependency 'http', '~> 4.4'
22
+ end
@@ -1,8 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'magento/version'
7
+
3
8
  Gem::Specification.new do |s|
4
9
  s.name = 'magento'
5
- s.version = '0.3.1'
10
+ s.version = Magento::VERSION
6
11
  s.date = '2020-07-31'
7
12
  s.summary = 'Magento Ruby library'
8
13
  s.description = 'Magento Ruby library'
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magento
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wallas Faria
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-07-31 00:00:00.000000000 Z
@@ -44,6 +44,7 @@ executables: []
44
44
  extensions: []
45
45
  extra_rdoc_files: []
46
46
  files:
47
+ - ".github/workflows/gem-push.yml"
47
48
  - ".gitignore"
48
49
  - Gemfile
49
50
  - README.md
@@ -57,12 +58,17 @@ files:
57
58
  - lib/magento/order.rb
58
59
  - lib/magento/product.rb
59
60
  - lib/magento/query.rb
61
+ - lib/magento/record_collection.rb
60
62
  - lib/magento/request.rb
61
63
  - lib/magento/shared/address.rb
62
64
  - lib/magento/shared/available_regions.rb
65
+ - lib/magento/shared/bundle_product_option.rb
63
66
  - lib/magento/shared/category_link.rb
67
+ - lib/magento/shared/configurable_product_option.rb
64
68
  - lib/magento/shared/custom_attribute.rb
65
69
  - lib/magento/shared/extension_attribute.rb
70
+ - lib/magento/shared/filter.rb
71
+ - lib/magento/shared/filter_group.rb
66
72
  - lib/magento/shared/item.rb
67
73
  - lib/magento/shared/media_gallery_entry.rb
68
74
  - lib/magento/shared/option.rb
@@ -70,17 +76,20 @@ files:
70
76
  - lib/magento/shared/payment_additional_info.rb
71
77
  - lib/magento/shared/product_link.rb
72
78
  - lib/magento/shared/region.rb
79
+ - lib/magento/shared/search_criterium.rb
73
80
  - lib/magento/shared/shipping.rb
74
81
  - lib/magento/shared/shipping_assignment.rb
75
82
  - lib/magento/shared/stock_item.rb
76
83
  - lib/magento/shared/tier_price.rb
77
84
  - lib/magento/shared/total.rb
78
85
  - lib/magento/shared/value.rb
86
+ - lib/magento/version.rb
87
+ - magento-ruby.gemspec
79
88
  - magento.gemspec
80
89
  homepage: https://github.com/WallasFaria/magento-ruby
81
90
  licenses: []
82
91
  metadata: {}
83
- post_install_message:
92
+ post_install_message:
84
93
  rdoc_options: []
85
94
  require_paths:
86
95
  - lib
@@ -95,8 +104,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
104
  - !ruby/object:Gem::Version
96
105
  version: '0'
97
106
  requirements: []
98
- rubygems_version: 3.0.6
99
- signing_key:
107
+ rubygems_version: 3.0.3
108
+ signing_key:
100
109
  specification_version: 4
101
110
  summary: Magento Ruby library
102
111
  test_files: []