magento 0.5.0 → 0.6.0
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/README.md +13 -1
- data/lib/magento.rb +16 -0
- data/lib/magento/model.rb +2 -2
- data/lib/magento/order.rb +21 -1
- data/lib/magento/record_collection.rb +11 -0
- 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: f899948f7690202bfadf8b2d0afbb066a864fd85f3e7d0c591df07b4f631d7bb
|
4
|
+
data.tar.gz: 63585fc1f5b5ba321a065e2796c253b52f544b3b057b941b933c027a04d63d07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0142acdd5ef93981d5170c39fecd73852458d8ea4a01d8b3c2ee28fd01c82ae26f2f16c533219908d8110648f50a99188b89a0f8537750b187fe62f003ff04c3
|
7
|
+
data.tar.gz: 39092a61524a5f09cc61ead86e66917f5833f2b30ca6a7155479c41af471a88394ccdbd233341a03ef6a8fadbd3e3dbd6b222d554b9eee590f0fec1b3b1f7006
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
Add in your Gemfile
|
6
6
|
|
7
7
|
```rb
|
8
|
-
gem 'magento', '~> 0.
|
8
|
+
gem 'magento', '~> 0.6.0'
|
9
9
|
```
|
10
10
|
|
11
11
|
or run
|
@@ -20,6 +20,10 @@ gem install magento
|
|
20
20
|
Magento.url = 'https://yourstore.com'
|
21
21
|
Magento.token = 'MAGENTO_API_KEY'
|
22
22
|
Magento.store = :default # optional, Default is :all
|
23
|
+
|
24
|
+
Magento.with_config(store: :other_store) do # accepts store, url and token parameters
|
25
|
+
Magento::Product.find('sku')
|
26
|
+
end
|
23
27
|
```
|
24
28
|
|
25
29
|
## Models
|
@@ -151,6 +155,12 @@ products.size
|
|
151
155
|
products.current_page
|
152
156
|
>> 1
|
153
157
|
|
158
|
+
products.next_page
|
159
|
+
>> 2
|
160
|
+
|
161
|
+
products.last_page?
|
162
|
+
>> false
|
163
|
+
|
154
164
|
products.page_size
|
155
165
|
>> 5
|
156
166
|
|
@@ -166,6 +176,8 @@ All Methods:
|
|
166
176
|
```rb
|
167
177
|
# Information about search criteria
|
168
178
|
:current_page
|
179
|
+
:next_page
|
180
|
+
:last_page?
|
169
181
|
:page_size
|
170
182
|
:total_count
|
171
183
|
:filter_groups
|
data/lib/magento.rb
CHANGED
@@ -35,6 +35,22 @@ module Magento
|
|
35
35
|
self.token = ENV['MAGENTO_TOKEN']
|
36
36
|
self.store = ENV['MAGENTO_STORE'] || :all
|
37
37
|
|
38
|
+
def self.with_config(utl: Magento.url, token: Magento.token, store: Magento.store)
|
39
|
+
@old_url = self.url
|
40
|
+
@old_token = self.token
|
41
|
+
@old_store = self.store
|
42
|
+
|
43
|
+
self.url = utl
|
44
|
+
self.token = token
|
45
|
+
self.store = store
|
46
|
+
|
47
|
+
yield
|
48
|
+
ensure
|
49
|
+
self.url = @old_url
|
50
|
+
self.token = @old_token
|
51
|
+
self.store = @old_store
|
52
|
+
end
|
53
|
+
|
38
54
|
def self.production?
|
39
55
|
ENV['RACK_ENV'] == 'production' ||
|
40
56
|
ENV['RAILS_ENV'] == 'production' ||
|
data/lib/magento/model.rb
CHANGED
@@ -36,7 +36,7 @@ module Magento
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def create(attributes)
|
39
|
-
body = {
|
39
|
+
body = { entity_key => attributes }
|
40
40
|
hash = request.post(api_resource, body).parse
|
41
41
|
build(hash)
|
42
42
|
end
|
@@ -77,7 +77,7 @@ module Magento
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def request
|
80
|
-
|
80
|
+
Request.new
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
data/lib/magento/order.rb
CHANGED
@@ -1,6 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Magento
|
2
4
|
class Order < Model
|
3
5
|
self.primary_key = :entity_id
|
4
6
|
self.entity_key = :entity
|
7
|
+
|
8
|
+
def save
|
9
|
+
raise NotImplementedError
|
10
|
+
end
|
11
|
+
|
12
|
+
def update(attrs)
|
13
|
+
raise "'entity_id' not found" if @entity_id.nil?
|
14
|
+
|
15
|
+
attrs[:entity_id] = @entity_id
|
16
|
+
self.class.update(attrs)
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def update(attributes)
|
21
|
+
hash = request.put('orders/create', { entity_key => attributes }).parse
|
22
|
+
build(hash)
|
23
|
+
end
|
24
|
+
end
|
5
25
|
end
|
6
|
-
end
|
26
|
+
end
|
@@ -23,6 +23,17 @@ module Magento
|
|
23
23
|
|
24
24
|
alias per page_size
|
25
25
|
|
26
|
+
def last_page?
|
27
|
+
current_page * page_size >= total_count
|
28
|
+
end
|
29
|
+
|
30
|
+
#
|
31
|
+
# Returns the {number} of the next page or {nil}
|
32
|
+
# when the current_page is the last page
|
33
|
+
def next_page
|
34
|
+
current_page + 1 unless last_page?
|
35
|
+
end
|
36
|
+
|
26
37
|
class << self
|
27
38
|
def from_magento_response(response, model:, iterable_field: 'items')
|
28
39
|
Magento::RecordCollection.new(
|
data/lib/magento/version.rb
CHANGED