magento 0.3.3 → 0.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2ef9e4abebd84117c6020d833b54c06358ad77a09c879152094d46ee1dd8167
4
- data.tar.gz: 905d0add93e45c83bf986bd3d041139ebaf7fa6242f8ee190dbc253d8bd65a31
3
+ metadata.gz: 5e1d4dc0ca7f0297a7bf5e735663772a68a0251a6e042bb39dea0e80149e5b19
4
+ data.tar.gz: 99b623dfff145efed9dc2b1ae32588e5cc67ac34247a95efec5b4fce56efd932
5
5
  SHA512:
6
- metadata.gz: 3b9c0be888fa8efe844d2a3ce4dece5d66e86ffaa2260b02814fd18daf81f9fa32e09c12cca553048519f37b2bc56cba62c2e3806aa5441f8e96686227c8a73e
7
- data.tar.gz: 6888f1ad953b3184f24b3f8c68f7cd40441169fcfc1eed94e31c8889fa386e4101844d7f1a69da0bd5ff0f5878df5b6c0b5eac0903237bfc0d1d723e20a96a84
6
+ metadata.gz: ef981adfa2b1d5f44412ee9f5d6aa70100935b79b91cda3885f13127017f3ce884a0a35d375de81c0abf237c69ef475b7b5731a9c0fc50bc367e04362c90d0a5
7
+ data.tar.gz: a997a2ffe333830a1648b11525508e9007bc75188bc6ebcdedaf09d7c5f832fe292f4401f32b5b35eb370cad61966f2af34c16f664e0cea3c884bc2c720a6d83
@@ -0,0 +1,42 @@
1
+ name: Ruby Gem
2
+
3
+ on:
4
+ push:
5
+ branches: [ release ]
6
+ pull_request:
7
+ branches: [ release ]
8
+
9
+ jobs:
10
+ build:
11
+ name: Build + Publish
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - name: Set up Ruby 2.6
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: 2.6.x
20
+
21
+ - name: Publish to GPR
22
+ run: |
23
+ mkdir -p $HOME/.gem
24
+ touch $HOME/.gem/credentials
25
+ chmod 0600 $HOME/.gem/credentials
26
+ printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
27
+ gem build magento-ruby.gemspec
28
+ gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
29
+ env:
30
+ GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
31
+ OWNER: ${{ github.repository_owner }}
32
+
33
+ - name: Publish to RubyGems
34
+ run: |
35
+ mkdir -p $HOME/.gem
36
+ touch $HOME/.gem/credentials
37
+ chmod 0600 $HOME/.gem/credentials
38
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
39
+ gem build magento.gemspec
40
+ gem push magento-[0-9]*.gem
41
+ env:
42
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add in your Gemfile
6
6
 
7
7
  ```rb
8
- gem 'magento', '~> 0.3.3'
8
+ gem 'magento', '~> 0.4.3'
9
9
  ```
10
10
 
11
11
  or run
@@ -109,20 +109,101 @@ Magento::Product.order(status: :desc, name: :asc).all
109
109
 
110
110
  ```rb
111
111
  # Set page and quantity per page
112
- Magento::Product.page(1).per(25) # Default per is 50
112
+ Magento::Product.page(1) # Current page, Default is 1
113
+ .page_size(25) # Default is 50
114
+ .all
115
+
116
+ # per is an alias to page_size
117
+ Magento::Product.per(25).all
113
118
  ```
114
119
 
115
120
  #### Example of several options together:
116
121
  ```rb
117
- Magento::Product.select(:sku, :name, :price)
118
- .where(name_like: 'Tshort%')
119
- .order(price: :desc)
120
- .per(10)
121
- .all
122
+ products = Magento::Product.select(:sku, :name)
123
+ .where(name_like: 'biscoito%')
124
+ .page(1)
125
+ .page_size(5)
126
+ .all
122
127
  ```
123
128
 
124
129
  \* _same pattern to all models_
125
130
 
131
+ ### Response
132
+
133
+ The `all` method retorns a `Magento::RecordCollection` instance
134
+
135
+ ```rb
136
+ products.first
137
+ >> <Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
138
+
139
+ products[0]
140
+ >> <Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
141
+
142
+ products.last
143
+ >> <Magento::Product @sku="964", @name="Biscoito Negresco 140 G Original">
144
+
145
+ products.map(&:sku)
146
+ >> ["2100", "792", "836", "913", "964"]
147
+
148
+ products.size
149
+ >> 5
150
+
151
+ products.current_page
152
+ >> 1
153
+
154
+ products.page_size
155
+ >> 5
156
+
157
+ products.total_count
158
+ >> 307
159
+
160
+ products.filter_groups
161
+ >> [<Magento::FilterGroup @filters=[<Magento::Filter @field="name", @value="biscoito%", @condition_type="like">]>]
162
+ ```
163
+
164
+ All Methods:
165
+
166
+ ```rb
167
+ # Information about search criteria
168
+ :current_page
169
+ :page_size
170
+ :total_count
171
+ :filter_groups
172
+
173
+ # Iterating with the list of items
174
+ :count
175
+ :length
176
+ :size
177
+
178
+ :first
179
+ :last
180
+ :[]
181
+ :find
182
+
183
+ :each
184
+ :each_with_index
185
+ :sample
186
+
187
+ :map
188
+ :select
189
+ :filter
190
+ :reject
191
+ :collect
192
+ :take
193
+ :take_while
194
+
195
+ :sort
196
+ :sort_by
197
+ :reverse_each
198
+ :reverse
199
+
200
+ :all?
201
+ :any?
202
+ :none?
203
+ :one?
204
+ :empty?
205
+ ```
206
+
126
207
  ## Create
127
208
 
128
209
  ```rb
@@ -1,35 +1,43 @@
1
- # frozen_string_literal: true
2
-
3
- require 'time'
4
- require 'dry/inflector'
5
-
6
- require_relative 'magento/errors'
7
- require_relative 'magento/request'
8
- require_relative 'magento/model'
9
- require_relative 'magento/model_mapper'
10
- require_relative 'magento/query'
11
- require_relative 'magento/product'
12
- require_relative 'magento/country'
13
- require_relative 'magento/customer'
14
- require_relative 'magento/order'
15
-
16
- Dir[File.expand_path('magento/shared/*.rb', __dir__)].map { |f| require f }
17
-
18
- module Magento
19
- class << self
20
- attr_accessor :url, :open_timeout, :timeout, :token, :store
21
- end
22
-
23
- self.url = ENV['MAGENTO_URL']
24
- self.open_timeout = 30
25
- self.timeout = 90
26
- self.token = ENV['MAGENTO_TOKEN']
27
- self.store = ENV['MAGENTO_STORE'] || :all
28
-
29
- def self.production?
30
- ENV['RACK_ENV'] == 'production' ||
31
- ENV['RAILS_ENV'] == 'production' ||
32
- ENV['PRODUCTION'] ||
33
- ENV['production']
34
- end
35
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+ require 'dry/inflector'
5
+
6
+ require_relative 'magento/errors'
7
+ require_relative 'magento/request'
8
+ require_relative 'magento/model'
9
+ require_relative 'magento/model_mapper'
10
+ require_relative 'magento/record_collection'
11
+ require_relative 'magento/query'
12
+ require_relative 'magento/category'
13
+ require_relative 'magento/product'
14
+ require_relative 'magento/country'
15
+ require_relative 'magento/customer'
16
+ require_relative 'magento/order'
17
+
18
+ Dir[File.expand_path('magento/shared/*.rb', __dir__)].map { |f| require f }
19
+
20
+ module Magento
21
+ class << self
22
+ attr_accessor :url, :open_timeout, :timeout, :token, :store
23
+
24
+ def inflector
25
+ @inflector ||= Dry::Inflector.new do |inflections|
26
+ inflections.singular 'children_data', 'category'
27
+ end
28
+ end
29
+ end
30
+
31
+ self.url = ENV['MAGENTO_URL']
32
+ self.open_timeout = 30
33
+ self.timeout = 90
34
+ self.token = ENV['MAGENTO_TOKEN']
35
+ self.store = ENV['MAGENTO_STORE'] || :all
36
+
37
+ def self.production?
38
+ ENV['RACK_ENV'] == 'production' ||
39
+ ENV['RAILS_ENV'] == 'production' ||
40
+ ENV['PRODUCTION'] ||
41
+ ENV['production']
42
+ end
43
+ end
@@ -1,5 +1,5 @@
1
- module Magento
2
- class Country < Model
3
- self.endpoint = 'directory/countries'
4
- end
5
- end
1
+ module Magento
2
+ class Country < Model
3
+ self.endpoint = 'directory/countries'
4
+ end
5
+ end
@@ -1,13 +1,13 @@
1
- module Magento
2
- class Customer < Model
3
- class << self
4
- alias_method :find_by_id, :find
5
-
6
- def find_by_token(token)
7
- user_request = Request.new(token: token)
8
- customer_hash = user_request.get('customers/me').parse
9
- ModelMapper.from_hash(customer_hash).to_model(Customer)
10
- end
11
- end
12
- end
13
- end
1
+ module Magento
2
+ class Customer < Model
3
+ class << self
4
+ alias_method :find_by_id, :find
5
+
6
+ def find_by_token(token)
7
+ user_request = Request.new(token: token)
8
+ customer_hash = user_request.get('customers/me').parse
9
+ ModelMapper.from_hash(customer_hash).to_model(Customer)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,79 +1,79 @@
1
- # frozen_string_literal: true
2
-
3
- require 'forwardable'
4
-
5
- module Magento
6
- class Model
7
- def save
8
- body = ModelMapper.from_object(self).to_hash
9
- self.class.update(send(self.class.primary_key), body)
10
- end
11
-
12
- def update(attrs)
13
- raise "#{self.class.name} not saved" if send(self.class.primary_key).nil?
14
-
15
- attrs.each { |key, value| send("#{key}=", value) }
16
- save
17
- end
18
-
19
- def delete
20
- self.class.delete(send(self.class.primary_key))
21
- end
22
-
23
- class << self
24
- extend Forwardable
25
-
26
- def_delegators :query, :all, :page, :per, :order, :select, :where
27
-
28
- def find(id)
29
- hash = request.get("#{api_resource}/#{id}").parse
30
- ModelMapper.from_hash(hash).to_model(self)
31
- end
32
-
33
- def create(attributes)
34
- body = { entity_name => attributes }
35
- hash = request.post(api_resource, body).parse
36
- ModelMapper.from_hash(hash).to_model(self)
37
- end
38
-
39
- def delete(id)
40
- request.delete("#{api_resource}/#{id}").status.success?
41
- end
42
-
43
- def update(id, attributes)
44
- body = { entity_name => attributes }
45
- hash = request.put("#{api_resource}/#{id}", body).parse
46
- ModelMapper.from_hash(hash).to_model(self)
47
- end
48
-
49
- def api_resource
50
- endpoint || inflector.pluralize(entity_name)
51
- end
52
-
53
- def entity_name
54
- inflector.underscore(name).sub('magento/', '')
55
- end
56
-
57
- def primary_key
58
- @primary_key || :id
59
- end
60
-
61
- protected
62
-
63
- attr_writer :primary_key
64
- attr_accessor :endpoint
65
-
66
- def query
67
- Query.new(self)
68
- end
69
-
70
- def request
71
- @request ||= Request.new
72
- end
73
-
74
- def inflector
75
- @inflector ||= Dry::Inflector.new
76
- end
77
- end
78
- end
79
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Magento
6
+ class Model
7
+ def save
8
+ body = ModelMapper.from_object(self).to_hash
9
+ self.class.update(send(self.class.primary_key), body)
10
+ end
11
+
12
+ def update(attrs)
13
+ raise "#{self.class.name} not saved" if send(self.class.primary_key).nil?
14
+
15
+ attrs.each { |key, value| send("#{key}=", value) }
16
+ save
17
+ end
18
+
19
+ def delete
20
+ self.class.delete(send(self.class.primary_key))
21
+ end
22
+
23
+ def id
24
+ @id || send(self.class.primary_key)
25
+ end
26
+
27
+ class << self
28
+ extend Forwardable
29
+
30
+ def_delegators :query, :all, :page, :per, :page_size, :order, :select, :where
31
+
32
+ def find(id)
33
+ hash = request.get("#{api_resource}/#{id}").parse
34
+ ModelMapper.from_hash(hash).to_model(self)
35
+ end
36
+
37
+ def create(attributes)
38
+ body = { entity_name => attributes }
39
+ hash = request.post(api_resource, body).parse
40
+ ModelMapper.from_hash(hash).to_model(self)
41
+ end
42
+
43
+ def delete(id)
44
+ request.delete("#{api_resource}/#{id}").status.success?
45
+ end
46
+
47
+ def update(id, attributes)
48
+ body = { entity_name => attributes }
49
+ hash = request.put("#{api_resource}/#{id}", body).parse
50
+ ModelMapper.from_hash(hash).to_model(self)
51
+ end
52
+
53
+ def api_resource
54
+ endpoint || Magento.inflector.pluralize(entity_name)
55
+ end
56
+
57
+ def entity_name
58
+ Magento.inflector.underscore(name).sub('magento/', '')
59
+ end
60
+
61
+ def primary_key
62
+ @primary_key || :id
63
+ end
64
+
65
+ protected
66
+
67
+ attr_writer :primary_key
68
+ attr_accessor :endpoint
69
+
70
+ def query
71
+ Query.new(self)
72
+ end
73
+
74
+ def request
75
+ @request ||= Request.new
76
+ end
77
+ end
78
+ end
79
+ end
@@ -4,11 +4,11 @@ class ModelMapper
4
4
  end
5
5
 
6
6
  def to_model(model)
7
- map_hash(model, @from)
7
+ map_hash(model, @from) if @from
8
8
  end
9
9
 
10
10
  def to_hash
11
- self.class.to_hash(@from)
11
+ self.class.to_hash(@from) if @from
12
12
  end
13
13
 
14
14
  def self.from_object(object)
@@ -42,7 +42,7 @@ class ModelMapper
42
42
  values.each do |key, value|
43
43
  object.singleton_class.instance_eval { attr_accessor key }
44
44
  if value.is_a?(Hash)
45
- class_name = inflector.camelize(inflector.singularize(key))
45
+ class_name = Magento.inflector.camelize(Magento.inflector.singularize(key))
46
46
  value = map_hash(Object.const_get("Magento::#{class_name}"), value)
47
47
  elsif value.is_a?(Array)
48
48
  value = map_array(key, value)
@@ -56,7 +56,7 @@ class ModelMapper
56
56
  result = []
57
57
  values.each do |value|
58
58
  if value.is_a?(Hash)
59
- class_name = inflector.camelize(inflector.singularize(key))
59
+ class_name = Magento.inflector.camelize(Magento.inflector.singularize(key))
60
60
  result << map_hash(Object.const_get("Magento::#{class_name}"), value)
61
61
  else
62
62
  result << value
@@ -64,8 +64,4 @@ class ModelMapper
64
64
  end
65
65
  result
66
66
  end
67
-
68
- def inflector
69
- @inflector ||= Dry::Inflector.new
70
- end
71
67
  end
@@ -1,9 +1,9 @@
1
- module Magento
2
- class Product < Model
3
- self.primary_key = :sku
4
-
5
- class << self
6
- alias_method :find_by_sku, :find
7
- end
8
- end
9
- end
1
+ module Magento
2
+ class Product < Model
3
+ self.primary_key = :sku
4
+
5
+ class << self
6
+ alias_method :find_by_sku, :find
7
+ end
8
+ end
9
+ end
@@ -50,14 +50,22 @@ module Magento
50
50
  self
51
51
  end
52
52
 
53
- def per(page_size)
54
- self.page_size = page_size
53
+ def page_size(page_size)
54
+ @page_size = page_size
55
55
  self
56
56
  end
57
57
 
58
+ alias_method :per, :page_size
59
+
58
60
  def select(*fields)
59
61
  fields = fields.map { |field| parse_field(field) }
60
- self.fields = "items[#{fields.join(',')}]"
62
+
63
+ if model == Magento::Category
64
+ self.fields = "children_data[#{fields.join(',')}]"
65
+ else
66
+ self.fields = "items[#{fields.join(',')}],search_criteria,total_count"
67
+ end
68
+
61
69
  self
62
70
  end
63
71
 
@@ -76,13 +84,14 @@ module Magento
76
84
  end
77
85
 
78
86
  def all
79
- items = request.get("#{endpoint}?#{query_params}").parse['items']
80
- items ? items.map { |i| ModelMapper.from_hash(i).to_model(model) } : []
87
+ result = request.get("#{endpoint}?#{query_params}").parse
88
+ field = model == Magento::Category ? 'children_data' : 'items'
89
+ RecordCollection.from_magento_response(result, model: model, iterable_field: field)
81
90
  end
82
91
 
83
92
  private
84
93
 
85
- attr_accessor :current_page, :filter_groups, :page_size, :request, :sort_orders, :model, :fields
94
+ attr_accessor :current_page, :filter_groups, :request, :sort_orders, :model, :fields
86
95
 
87
96
  def endpoint
88
97
  model.api_resource
@@ -100,7 +109,7 @@ module Magento
100
109
  filterGroups: filter_groups,
101
110
  currentPage: current_page,
102
111
  sortOrders: sort_orders,
103
- pageSize: page_size
112
+ pageSize: @page_size
104
113
  }.compact,
105
114
  fields: fields
106
115
  }.compact
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ module Magento
6
+ class RecordCollection
7
+ attr_reader :items, :search_criteria, :total_count
8
+ extend Forwardable
9
+
10
+ def initialize(items:, total_count: nil, search_criteria: nil)
11
+ @items = items || []
12
+ @total_count = total_count || @items.size
13
+ @search_criteria = search_criteria || Magento::SearchCriterium.new
14
+ end
15
+
16
+ def_delegators :@search_criteria, :current_page, :filter_groups, :page_size
17
+
18
+ def_delegators :@items, :count, :length, :size, :first, :last, :[],
19
+ :find, :each, :each_with_index, :sample, :map, :select,
20
+ :filter, :reject, :collect, :take, :take_while, :sort,
21
+ :sort_by, :reverse_each, :reverse, :all?, :any?, :none?,
22
+ :one?, :empty?
23
+
24
+ alias per page_size
25
+
26
+ class << self
27
+ def from_magento_response(response, model:, iterable_field: 'items')
28
+ items = response[iterable_field]&.map do |item|
29
+ ModelMapper.from_hash(item).to_model(model)
30
+ end
31
+
32
+ search_criteria = ModelMapper
33
+ .from_hash(response['search_criteria'])
34
+ .to_model(Magento::SearchCriterium)
35
+
36
+ Magento::RecordCollection.new(
37
+ items: items,
38
+ total_count: response['total_count'],
39
+ search_criteria: search_criteria
40
+ )
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,108 +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)
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
+ # 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 BillingAddress
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
@@ -0,0 +1,4 @@
1
+ module Magento
2
+ class StatusHistory
3
+ end
4
+ 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.3'
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.3'
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.3
4
+ version: 0.4.3
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,18 @@ 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/billing_address.rb
66
+ - lib/magento/shared/bundle_product_option.rb
63
67
  - lib/magento/shared/category_link.rb
68
+ - lib/magento/shared/configurable_product_option.rb
64
69
  - lib/magento/shared/custom_attribute.rb
65
70
  - lib/magento/shared/extension_attribute.rb
71
+ - lib/magento/shared/filter.rb
72
+ - lib/magento/shared/filter_group.rb
66
73
  - lib/magento/shared/item.rb
67
74
  - lib/magento/shared/media_gallery_entry.rb
68
75
  - lib/magento/shared/option.rb
@@ -70,17 +77,21 @@ files:
70
77
  - lib/magento/shared/payment_additional_info.rb
71
78
  - lib/magento/shared/product_link.rb
72
79
  - lib/magento/shared/region.rb
80
+ - lib/magento/shared/search_criterium.rb
73
81
  - lib/magento/shared/shipping.rb
74
82
  - lib/magento/shared/shipping_assignment.rb
83
+ - lib/magento/shared/status_history.rb
75
84
  - lib/magento/shared/stock_item.rb
76
85
  - lib/magento/shared/tier_price.rb
77
86
  - lib/magento/shared/total.rb
78
87
  - lib/magento/shared/value.rb
88
+ - lib/magento/version.rb
89
+ - magento-ruby.gemspec
79
90
  - magento.gemspec
80
91
  homepage: https://github.com/WallasFaria/magento-ruby
81
92
  licenses: []
82
93
  metadata: {}
83
- post_install_message:
94
+ post_install_message:
84
95
  rdoc_options: []
85
96
  require_paths:
86
97
  - lib
@@ -95,8 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
106
  - !ruby/object:Gem::Version
96
107
  version: '0'
97
108
  requirements: []
98
- rubygems_version: 3.0.6
99
- signing_key:
109
+ rubygems_version: 3.0.3
110
+ signing_key:
100
111
  specification_version: 4
101
112
  summary: Magento Ruby library
102
113
  test_files: []