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 +4 -4
- data/.github/workflows/gem-push.yml +2 -2
- data/README.md +58 -12
- data/lib/magento/model_mapper.rb +2 -2
- data/lib/magento/query.rb +2 -1
- data/lib/magento/record_collection.rb +17 -39
- data/lib/magento/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca2b525890d23f017395642b3be2f67da40a5bdcddba2f95001f2b467fdf832c
|
4
|
+
data.tar.gz: 529d1fa8ee55419914824373462cc7408d3d63f525de916eef3c35f5970bdd36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d76e0f91f76401fc6494819747e137cff7fe38ec527b071ec1c98ccbc5a70b4c7f074019965b4d7075a26649e1515684a08534ef81e932d3e87b1c8c8677b822
|
7
|
+
data.tar.gz: 7cf8c1c7aa3f80d963bf7d26ee2188c20caee28ce79a5b48c376aa90a0c10586764cbe572bfa883acdc688f77bc27b5f50e00752d631fed26e19ddbb1678eed0
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
Add in your Gemfile
|
6
6
|
|
7
7
|
```rb
|
8
|
-
gem 'magento', '~> 0.4.
|
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
|
-
|
137
|
+
>> <Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
|
138
138
|
|
139
139
|
products[0]
|
140
|
-
|
140
|
+
>> <Magento::Product @sku="2100", @name="Biscoito Piraque Salgadinho 100G">
|
141
141
|
|
142
142
|
products.last
|
143
|
-
|
143
|
+
>> <Magento::Product @sku="964", @name="Biscoito Negresco 140 G Original">
|
144
144
|
|
145
145
|
products.map(&:sku)
|
146
|
-
|
146
|
+
>> ["2100", "792", "836", "913", "964"]
|
147
147
|
|
148
148
|
products.size
|
149
|
-
|
149
|
+
>> 5
|
150
150
|
|
151
|
-
products.current_page
|
152
|
-
|
151
|
+
products.current_page
|
152
|
+
>> 1
|
153
153
|
|
154
|
-
products.page_size
|
155
|
-
|
154
|
+
products.page_size
|
155
|
+
>> 5
|
156
156
|
|
157
|
-
products.total_count
|
158
|
-
|
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
|
data/lib/magento/model_mapper.rb
CHANGED
data/lib/magento/query.rb
CHANGED
@@ -85,7 +85,8 @@ module Magento
|
|
85
85
|
|
86
86
|
def all
|
87
87
|
result = request.get("#{endpoint}?#{query_params}").parse
|
88
|
-
|
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
|
-
@
|
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
|
-
:
|
21
|
-
:
|
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
|
-
|
28
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
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
|
data/lib/magento/version.rb
CHANGED