magentwo 0.1.0 → 0.1.1

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: 57c5ce2bff9ba6b24431270fec36de370ae8a1637c0b336cf8f5bd7a741d4cdb
4
- data.tar.gz: 2dfe12316718b6e2882db03b7b057ba128c7f6e41df1a23717a21bbb2e59aa11
3
+ metadata.gz: aec00d3aa4f9cead374c52e885a4e5caf630faaa072e4bf5502757008ca4e58e
4
+ data.tar.gz: 1c6688ed66e1f3a7264f33fe11e897a5a464280d1e40e2400439fddd5f7ade91
5
5
  SHA512:
6
- metadata.gz: 57390590bb9ccb28a3fefce2ea23417768a1e01c7dacb1ab388bcd7e6d5ecb3abf6103a9059ec9d21e95137137ce1a4025c30993a5ea3f58638722d0435ed0ec
7
- data.tar.gz: d57e227ce4ec86df09fbdf12ac14f915180e9fe53bcdc08c7c15a02834425491d3547dfc84884abc202e5a639aaebe5331741e9e05fefe1a3adfce26fc8d2f86
6
+ metadata.gz: 49108b46b30b97ca463d4fecfdcbc33ee2f029e66ad3152ea67fde75909e9369eeb470c4af6cb82710c9cefa753991c8bf570007c97a6f4d28d605e5ad8595cd
7
+ data.tar.gz: 922da63238bbea63fea0a34beee23227a9564568a72352d91e6075a3093d5268236c3ad678a256c6f1198b223375083849d0aa97618b5976a1c2e5961e2eeff6
@@ -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
@@ -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["items"]&.first&.keys,
70
- :total_count => result["total_count"]
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["items"].first
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["items"] || []).map do |item|
90
+ (result[:items] || []).map do |item|
91
91
  self.model.new item
92
92
  end
93
93
  end
@@ -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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'magentwo'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
4
  s.date = '2019-01-17'
5
5
  s.summary = "Magento 2 API Wrapper"
6
6
  s.description = "Provides a simple Ruby Interface to interact with the Magento 2 API"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magentwo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Mueß