magento 0.10.0 → 0.11.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: f2d89a076f05f6e5a3f3a828d7658582a76556e57f6f0ff07a2422044ce82ab4
4
- data.tar.gz: fbf4ab1013bf639d81781cc40042aedc5ed62062207f597e127a2ba0bc5b21b3
3
+ metadata.gz: ba575ef3ae90104d8c2fab63e96762478536391becc467892d0feee3ff9a15ad
4
+ data.tar.gz: 655504007fb8ff01db537e8d7fa51641fba248ce0fdee9a0b153418b95dce688
5
5
  SHA512:
6
- metadata.gz: b31854a2ad2fb3ed3ea8711c45e56a426abae13c17b392c69e0186f2594d5bb7654baf8e0dc55cf72265340153bdba56edfdff0a28836d1516d55a7c7537c4ab
7
- data.tar.gz: 364a54b27877e55198d1cbb6f2f749aaa399301ba377ade578e2f9e092bd280002aa7cc1932c367adc8825c6790ab4aae2d39e20c30202f3a53d3cf2ecb9ce24
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.10.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
@@ -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(*_attributes)
13
- raise NotImplementedError
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(*_attributes)
17
- raise NotImplementedError
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)
@@ -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
- build(hash)
59
+
60
+ block_given? ? yield(hash) : build(hash)
52
61
  end
53
62
 
54
63
  def api_resource
@@ -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.singleton_class.instance_eval { attr_accessor key }
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)
@@ -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}
@@ -1,3 +1,3 @@
1
1
  module Magento
2
- VERSION = '0.10.0'
2
+ VERSION = '0.11.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.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wallas Faria