magento 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2db72674e6f177281d192ec853591b747c91e3ce7f3bd61ccb5beb1a01ddf9d
4
- data.tar.gz: 50afe2399868005885926446ac9cb6563625e99f4752ca6c339728f53adb0b0f
3
+ metadata.gz: f2d89a076f05f6e5a3f3a828d7658582a76556e57f6f0ff07a2422044ce82ab4
4
+ data.tar.gz: fbf4ab1013bf639d81781cc40042aedc5ed62062207f597e127a2ba0bc5b21b3
5
5
  SHA512:
6
- metadata.gz: d7734ec0ecf1fcfc46d3675f3cfcee3dd47fbab3606bb8839079b9c5b1f487ba125a6529ee6f7addef0f3e5f81bdb8bd6c97d5c9d73e45a4554ec0e5ab162ec9
7
- data.tar.gz: 1ece8d5edc5efc8d0e336b77c0a0259caf930c51dc7a4fb40ad05954e17a4d960226356d8610c1004e91dc155d6afbeaf094b677130b8a1995ee02e702fb4abb
6
+ metadata.gz: b31854a2ad2fb3ed3ea8711c45e56a426abae13c17b392c69e0186f2594d5bb7654baf8e0dc55cf72265340153bdba56edfdff0a28836d1516d55a7c7537c4ab
7
+ data.tar.gz: 364a54b27877e55198d1cbb6f2f749aaa399301ba377ade578e2f9e092bd280002aa7cc1932c367adc8825c6790ab4aae2d39e20c30202f3a53d3cf2ecb9ce24
data/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  Add in your Gemfile
6
6
 
7
7
  ```rb
8
- gem 'magento', '~> 0.9.2'
8
+ gem 'magento', '~> 0.10.0'
9
9
  ```
10
10
 
11
11
  or run
@@ -68,6 +68,7 @@ Magento::Product.select(:id, :sku, :name, extension_attributes: [:website_ids, {
68
68
  #### Filters:
69
69
 
70
70
  ```rb
71
+ Magento::Product.where(visibility: 4).all
71
72
  Magento::Product.where(name_like: 'IPhone%').all
72
73
  Magento::Product.where(price_gt: 100).all
73
74
 
@@ -130,6 +131,20 @@ products = Magento::Product.select(:sku, :name)
130
131
  .all
131
132
  ```
132
133
 
134
+ ## Get one
135
+
136
+ ```rb
137
+ Magento::Order.where(increment_id: '000013457').first
138
+ # or
139
+ Magento::Order.find_by(increment_id: '000013457')
140
+ ```
141
+
142
+ ## Count
143
+ ```rb
144
+ Magento::Order.count
145
+ Magento::Order.where(status: :pending).count
146
+ ```
147
+
133
148
  \* _same pattern to all models_
134
149
 
135
150
  ### Response
@@ -27,7 +27,8 @@ module Magento
27
27
  class << self
28
28
  extend Forwardable
29
29
 
30
- def_delegators :query, :all, :page, :per, :page_size, :order, :select, :where
30
+ def_delegators :query, :all, :page, :per, :page_size, :order, :select,
31
+ :where, :first, :find_by, :count
31
32
 
32
33
  def find(id)
33
34
  hash = request.get("#{api_resource}/#{id}").parse
@@ -89,6 +89,18 @@ module Magento
89
89
  RecordCollection.from_magento_response(result, model: model, iterable_field: field)
90
90
  end
91
91
 
92
+ def first
93
+ page_size(1).page(1).all.first
94
+ end
95
+
96
+ def find_by(attributes)
97
+ where(attributes).first
98
+ end
99
+
100
+ def count
101
+ select(:id).page_size(1).page(1).all.total_count
102
+ end
103
+
92
104
  private
93
105
 
94
106
  attr_accessor :current_page, :filter_groups, :request, :sort_orders, :model, :fields
@@ -119,10 +131,11 @@ module Magento
119
131
 
120
132
  def parse_filter(key)
121
133
  patter = /(.*)_([a-z]+)$/
122
- raise 'Invalid format' unless key.match(patter)
123
- raise 'Condition not accepted' unless ACCEPTED_CONDITIONS.include?(key.match(patter)[2])
134
+ match = key.match(patter)
135
+
136
+ return match.to_a[1..2] if match && ACCEPTED_CONDITIONS.include?(match[2])
124
137
 
125
- key.match(patter).to_a[1..2]
138
+ [key, 'eq']
126
139
  end
127
140
 
128
141
  def parse_value_filter(condition, value)
@@ -1,3 +1,3 @@
1
1
  module Magento
2
- VERSION = '0.9.2'
2
+ VERSION = '0.10.0'
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.9.2
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wallas Faria