magento 0.10.0 → 0.11.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 +2 -1
- data/lib/magento/customer.rb +19 -4
- data/lib/magento/model.rb +12 -3
- data/lib/magento/model_mapper.rb +5 -2
- data/lib/magento/order.rb +4 -2
- 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: ba575ef3ae90104d8c2fab63e96762478536391becc467892d0feee3ff9a15ad
|
4
|
+
data.tar.gz: 655504007fb8ff01db537e8d7fa51641fba248ce0fdee9a0b153418b95dce688
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 720efc55bf0754e8a13dae1230208536743bc6939f53ba7ccf4d116e325e257486e4522188fee86bc1383a11c92c49692e4f193cd6d402ce23f687086549a5d2
|
7
|
+
data.tar.gz: 7984a5870e45ebcd220d0426918bd5b616ae545112fd68bc0ca6ac4cb2e60b1e1891ae2e46ed233a06be9f9ae399b5de9a02e8608400ed668336903f34c71472
|
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.11.0'
|
9
9
|
```
|
10
10
|
|
11
11
|
or run
|
@@ -32,6 +32,7 @@ Magento::Product
|
|
32
32
|
Magento::Order
|
33
33
|
Magento::Country
|
34
34
|
Magento::Category
|
35
|
+
Magento::Customer
|
35
36
|
```
|
36
37
|
|
37
38
|
## Get details
|
data/lib/magento/customer.rb
CHANGED
@@ -6,15 +6,30 @@ module Magento
|
|
6
6
|
"#{@firstname} #{@lastname}"
|
7
7
|
end
|
8
8
|
|
9
|
+
def update(attributes)
|
10
|
+
raise "id not present" if @id.nil?
|
11
|
+
|
12
|
+
attributes.each { |key, value| send("#{key}=", value) }
|
13
|
+
save
|
14
|
+
end
|
15
|
+
|
9
16
|
class << self
|
10
17
|
alias_method :find_by_id, :find
|
11
18
|
|
12
|
-
def update(
|
13
|
-
|
19
|
+
def update(id, attributes)
|
20
|
+
hash = request.put("customers/#{id}", { customer: attributes }).parse
|
21
|
+
|
22
|
+
block_given? ? yield(hash) : build(hash)
|
14
23
|
end
|
15
24
|
|
16
|
-
def create(
|
17
|
-
|
25
|
+
def create(attributes)
|
26
|
+
attributes.transform_keys!(&:to_sym)
|
27
|
+
password = attributes.delete :password
|
28
|
+
hash = request.post("customers", {
|
29
|
+
customer: attributes,
|
30
|
+
password: password
|
31
|
+
}).parse
|
32
|
+
build(hash)
|
18
33
|
end
|
19
34
|
|
20
35
|
def find_by_token(token)
|
data/lib/magento/model.rb
CHANGED
@@ -7,13 +7,17 @@ module Magento
|
|
7
7
|
include Magento::ModelParser
|
8
8
|
|
9
9
|
def save
|
10
|
-
self.class.update(send(self.class.primary_key), to_h)
|
10
|
+
self.class.update(send(self.class.primary_key), to_h) do |hash|
|
11
|
+
update_attributes(hash)
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
15
|
def update(attrs)
|
14
16
|
raise "#{self.class.name} not saved" if send(self.class.primary_key).nil?
|
15
17
|
|
16
|
-
self.class.update(send(self.class.primary_key), attrs)
|
18
|
+
self.class.update(send(self.class.primary_key), attrs) do |hash|
|
19
|
+
update_attributes(hash)
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
def delete
|
@@ -24,6 +28,10 @@ module Magento
|
|
24
28
|
@id || send(self.class.primary_key)
|
25
29
|
end
|
26
30
|
|
31
|
+
protected def update_attributes(hash)
|
32
|
+
ModelMapper.map_hash(self, hash)
|
33
|
+
end
|
34
|
+
|
27
35
|
class << self
|
28
36
|
extend Forwardable
|
29
37
|
|
@@ -48,7 +56,8 @@ module Magento
|
|
48
56
|
def update(id, attributes)
|
49
57
|
body = { entity_key => attributes }
|
50
58
|
hash = request.put("#{api_resource}/#{id}", body).parse
|
51
|
-
|
59
|
+
|
60
|
+
block_given? ? yield(hash) : build(hash)
|
52
61
|
end
|
53
62
|
|
54
63
|
def api_resource
|
data/lib/magento/model_mapper.rb
CHANGED
@@ -17,9 +17,12 @@ module Magento
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.map_hash(model, values)
|
20
|
-
object = model.new
|
20
|
+
object = model.is_a?(Class) ? model.new : model
|
21
21
|
values.each do |key, value|
|
22
|
-
object.
|
22
|
+
unless object.respond_to?(key) && object.respond_to?("#{key}=")
|
23
|
+
object.singleton_class.instance_eval { attr_accessor key }
|
24
|
+
end
|
25
|
+
|
23
26
|
if value.is_a?(Hash)
|
24
27
|
class_name = Magento.inflector.camelize(Magento.inflector.singularize(key))
|
25
28
|
value = map_hash(Object.const_get("Magento::#{class_name}"), value)
|
data/lib/magento/order.rb
CHANGED
@@ -12,7 +12,9 @@ module Magento
|
|
12
12
|
def update(attrs)
|
13
13
|
raise "'entity_id' not found" if @entity_id.nil?
|
14
14
|
|
15
|
-
self.class.update(@entity_id, attrs)
|
15
|
+
self.class.update(@entity_id, attrs) do |hash|
|
16
|
+
update_attributes(hash)
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
20
|
def cancel
|
@@ -63,7 +65,7 @@ module Magento
|
|
63
65
|
def update(entity_id, attributes)
|
64
66
|
attributes[:entity_id] = entity_id
|
65
67
|
hash = request.put('orders/create', { entity_key => attributes }).parse
|
66
|
-
build(hash)
|
68
|
+
block_given? ? yield(hash) : build(hash)
|
67
69
|
end
|
68
70
|
|
69
71
|
# @return {Boolean}
|
data/lib/magento/version.rb
CHANGED