magentwo 0.1.0 → 0.1.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/lib/connection.rb +1 -1
- data/lib/dataset.rb +4 -4
- data/lib/model/base.rb +16 -1
- data/magentwo.gemspec +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: aec00d3aa4f9cead374c52e885a4e5caf630faaa072e4bf5502757008ca4e58e
|
4
|
+
data.tar.gz: 1c6688ed66e1f3a7264f33fe11e897a5a464280d1e40e2400439fddd5f7ade91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 49108b46b30b97ca463d4fecfdcbc33ee2f029e66ad3152ea67fde75909e9369eeb470c4af6cb82710c9cefa753991c8bf570007c97a6f4d28d605e5ad8595cd
|
7
|
+
data.tar.gz: 922da63238bbea63fea0a34beee23227a9564568a72352d91e6075a3093d5268236c3ad678a256c6f1198b223375083849d0aa97618b5976a1c2e5961e2eeff6
|
data/lib/connection.rb
CHANGED
@@ -65,7 +65,7 @@ module Magentwo
|
|
65
65
|
private
|
66
66
|
def handle_response response
|
67
67
|
case response.code
|
68
|
-
when "200" then JSON.parse response.body
|
68
|
+
when "200" then JSON.parse response.body, :symbolize_names => true
|
69
69
|
else
|
70
70
|
raise "request failed #{response.code} #{response.body}"
|
71
71
|
end
|
data/lib/dataset.rb
CHANGED
@@ -66,8 +66,8 @@ module Magentwo
|
|
66
66
|
def info
|
67
67
|
result = self.model.call :get, self.page(1, 1).to_query
|
68
68
|
{
|
69
|
-
:fields => result[
|
70
|
-
:total_count => result[
|
69
|
+
:fields => result[:items]&.first&.keys,
|
70
|
+
:total_count => result[:total_count]
|
71
71
|
}
|
72
72
|
end
|
73
73
|
|
@@ -81,13 +81,13 @@ module Magentwo
|
|
81
81
|
|
82
82
|
def first
|
83
83
|
result = self.model.call :get, self.page(1, 1).to_query
|
84
|
-
self.model.new result[
|
84
|
+
self.model.new result[:items].first
|
85
85
|
end
|
86
86
|
|
87
87
|
def all
|
88
88
|
result = self.model.call :get, self.to_query
|
89
89
|
return [] if result.nil?
|
90
|
-
(result[
|
90
|
+
(result[:items] || []).map do |item|
|
91
91
|
self.model.new item
|
92
92
|
end
|
93
93
|
end
|
data/lib/model/base.rb
CHANGED
@@ -9,6 +9,22 @@ module Magentwo
|
|
9
9
|
instance_variable_set key_sym, value
|
10
10
|
end
|
11
11
|
end
|
12
|
+
if self.respond_to? :custom_attributes
|
13
|
+
self.custom_attributes = args[:custom_attributes].map do |attr|
|
14
|
+
Hash[attr[:attribute_code].to_sym, attr[:value]]
|
15
|
+
end.inject(&:merge)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def method_missing m, *args, &block
|
20
|
+
if custom_attr = self.custom_attributes[m]
|
21
|
+
return custom_attr
|
22
|
+
end
|
23
|
+
|
24
|
+
if extension_attr = self.extension_attributes[m]
|
25
|
+
return extension_attr
|
26
|
+
end
|
27
|
+
nil
|
12
28
|
end
|
13
29
|
|
14
30
|
class << self; attr_accessor :connection end
|
@@ -29,7 +45,6 @@ module Magentwo
|
|
29
45
|
return dataset.send(name, *args)
|
30
46
|
end
|
31
47
|
end
|
32
|
-
|
33
48
|
end
|
34
49
|
end
|
35
50
|
end
|
data/magentwo.gemspec
CHANGED