magento 0.4.0 → 0.4.1

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: 10797b41b2292eb765414cf4757cca8e92d6eeaa604ae3c59da76763e11dce9e
4
- data.tar.gz: 683f76e2c1b7215e279459bd5eca921caba0e58fe18d299a29c256a0a5e11b94
3
+ metadata.gz: ca2b525890d23f017395642b3be2f67da40a5bdcddba2f95001f2b467fdf832c
4
+ data.tar.gz: 529d1fa8ee55419914824373462cc7408d3d63f525de916eef3c35f5970bdd36
5
5
  SHA512:
6
- metadata.gz: c8c44416f426c6c57bd402cd2d794027ce811bdd1d2e001502d19ffc785e3cb16b26d01fa983c1a3e1582a2d2a6b18f33a3a6f472230069abb33d75263676060
7
- data.tar.gz: 5175d8d609601f3b207e29f92cfa38fff076c7ec51a225c274cbdfbd5d6a81edc99e3f8069ebeed100b838899add3c875c70054afa2de70601d69148270ad521
6
+ metadata.gz: d76e0f91f76401fc6494819747e137cff7fe38ec527b071ec1c98ccbc5a70b4c7f074019965b4d7075a26649e1515684a08534ef81e932d3e87b1c8c8677b822
7
+ data.tar.gz: 7cf8c1c7aa3f80d963bf7d26ee2188c20caee28ce79a5b48c376aa90a0c10586764cbe572bfa883acdc688f77bc27b5f50e00752d631fed26e19ddbb1678eed0
@@ -2,9 +2,9 @@ name: Ruby Gem
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
5
+ branches: [ release ]
6
6
  pull_request:
7
- branches: [ master ]
7
+ branches: [ release ]
8
8
 
9
9
  jobs:
10
10
  build:
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add in your Gemfile
6
6
 
7
7
  ```rb
8
- gem 'magento', '~> 0.4.0'
8
+ gem 'magento', '~> 0.4.1'
9
9
  ```
10
10
 
11
11
  or run
@@ -134,28 +134,74 @@ The `all` method retorns a `Magento::RecordCollection` instance
134
134
 
135
135
  ```rb
136
136
  products.first
137
- # #<Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
137
+ >> <Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
138
138
 
139
139
  products[0]
140
- # #<Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
140
+ >> <Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
141
141
 
142
142
  products.last
143
- # #<Magento::Product @sku="964", @name="Biscoito Negresco 140 G Original">
143
+ >> <Magento::Product @sku="964", @name="Biscoito Negresco 140 G Original">
144
144
 
145
145
  products.map(&:sku)
146
- # ["2100", "792", "836", "913", "964"]
146
+ >> ["2100", "792", "836", "913", "964"]
147
147
 
148
148
  products.size
149
- # 5
149
+ >> 5
150
150
 
151
- products.current_page
152
- # 1
151
+ products.current_page
152
+ >> 1
153
153
 
154
- products.page_size
155
- # 5
154
+ products.page_size
155
+ >> 5
156
156
 
157
- products.total_count
158
- # 307
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_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?
159
205
  ```
160
206
 
161
207
  ## Create
@@ -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)
@@ -85,7 +85,8 @@ module Magento
85
85
 
86
86
  def all
87
87
  result = request.get("#{endpoint}?#{query_params}").parse
88
- RecordCollection.from_magento_response(result, model: model)
88
+ field = model == Magento::Category ? 'children_data' : 'items'
89
+ RecordCollection.from_magento_response(result, model: model, iterable_field: field)
89
90
  end
90
91
 
91
92
  private
@@ -7,9 +7,10 @@ module Magento
7
7
  attr_accessor :items, :search_criteria, :total_count
8
8
  extend Forwardable
9
9
 
10
- def initialize
11
- @items = []
12
- @search_criteria = Magento::SearchCriterium
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
13
14
  end
14
15
 
15
16
  def_delegators :@search_criteria, :current_page, :filter_groups, :page_size
@@ -17,49 +18,26 @@ module Magento
17
18
  def_delegators :@items, :last, :each_index, :sample, :sort, :count, :[],
18
19
  :find_index, :select, :filter, :reject, :collect, :map,
19
20
  :first, :all?, :any?, :none?, :one?, :reverse_each, :take,
20
- :take_while, :drop, :drop_while, :cycle, :index, :sort_by,
21
- :empty?, :reverse, :length, :size, :each, :find
21
+ :empty?, :reverse, :length, :size, :each, :find,
22
+ :take_while, :index, :sort_by
22
23
 
23
24
  alias_method :per, :page_size
24
25
 
25
26
  class << self
26
- def from_magento_response(response, model:)
27
- if model == Magento::Category
28
- handle_category_response(response, model)
29
- else
30
- handle_response(response, model)
27
+ def from_magento_response(response, model:, iterable_field: 'items')
28
+ items = response[iterable_field]&.map do
29
+ |item| ModelMapper.from_hash(item).to_model(model)
31
30
  end
32
- end
33
-
34
- private
35
-
36
- def handle_category_response(response, model)
37
- collection = Magento::RecordCollection.new
38
-
39
- collection.items = response['children_data']&.map do |item|
40
- ModelMapper.from_hash(item).to_model(model)
41
- end || []
42
-
43
- collection.total_count = response['children_data']&.size || 0
44
- collection
45
- end
46
-
47
- def handle_response(response, model)
48
- collection = Magento::RecordCollection.new
49
-
50
- collection.items = response['items']&.map do |item|
51
- ModelMapper.from_hash(item).to_model(model)
52
- end || []
53
31
 
54
- collection.total_count = response['total_count'] if response['total_count']
55
-
56
- if response['search_criteria']
57
- collection.search_criteria = ModelMapper
58
- .from_hash(response['search_criteria'])
59
- .to_model(Magento::SearchCriterium)
60
- end
32
+ search_criteria = ModelMapper
33
+ .from_hash(response['search_criteria'])
34
+ .to_model(Magento::SearchCriterium)
61
35
 
62
- collection
36
+ Magento::RecordCollection.new(
37
+ items: items,
38
+ total_count: response['total_count'],
39
+ search_criteria: search_criteria
40
+ )
63
41
  end
64
42
  end
65
43
  end
@@ -1,3 +1,3 @@
1
1
  module Magento
2
- VERSION = '0.4.0'
2
+ VERSION = '0.4.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magento
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wallas Faria