magentwo 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/adapter.rb +6 -2
- data/lib/dataset.rb +7 -8
- data/lib/magentwo.rb +14 -1
- data/lib/model/base.rb +11 -2
- data/lib/model/order.rb +2 -1
- data/lib/model/sales_rule.rb +5 -0
- data/magentwo.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa0539c40b51df6d70767268e48405720552c3760e5eb50bf0743de635428924
|
4
|
+
data.tar.gz: e95ee4c5eac328f66fcd5653b8b5c4530eaa396df8671b6a2b2c019583043fad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1924091ecf2d564e164f1dc380adaca6321016e6a6eecb9514e5a288c8be1619a6e38b60d27dd831d2e07e70b174586121367fd7c2dfbae4737cbae920d17aca
|
7
|
+
data.tar.gz: edd7edc4deb94fcd308dc004fcda0cb6b6e8dcd1c692afb7b76f2db028ab28db8f4a054e1fd6421ffb93e1a3aa615ec61cd02f09aff466a85b2ecde757032b62
|
data/lib/adapter.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Magentwo
|
2
2
|
class Adapter < Magentwo::Connection
|
3
|
-
|
3
|
+
DateTimeFields = %i(created_at updated_at change_status_at)
|
4
|
+
DateFields = %i(dob)
|
4
5
|
def call method, path, params
|
5
6
|
http_method, params = case method
|
6
7
|
when :put, :post, :delete then [method, params.to_json]
|
@@ -50,7 +51,10 @@ module Magentwo
|
|
50
51
|
|
51
52
|
def date_transform item
|
52
53
|
DateFields.each do |date_field|
|
53
|
-
item[date_field] =
|
54
|
+
item[date_field] = Date.parse item[date_field] if item[date_field]
|
55
|
+
end
|
56
|
+
DateTimeFields.each do |datetime_field|
|
57
|
+
item[datetime_field] = Time.parse item[datetime_field] if item[datetime_field]
|
54
58
|
end
|
55
59
|
item
|
56
60
|
end
|
data/lib/dataset.rb
CHANGED
@@ -109,8 +109,8 @@ module Magentwo
|
|
109
109
|
self.model.first self
|
110
110
|
end
|
111
111
|
|
112
|
-
def all
|
113
|
-
self.model.all self
|
112
|
+
def all meta_data:false
|
113
|
+
self.model.all self, :meta_data => meta_data
|
114
114
|
end
|
115
115
|
|
116
116
|
#################
|
@@ -187,12 +187,11 @@ module Magentwo
|
|
187
187
|
|
188
188
|
received_element_count = page_size
|
189
189
|
current_page = 1
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
received_element_count = page.count
|
190
|
+
total_count = nil
|
191
|
+
until(total_count && current_page*page_size > total_count) do
|
192
|
+
page = self.page(current_page, page_size).all meta_data:true
|
193
|
+
total_count = page[:total_count] unless total_count
|
194
|
+
block.call(page[:items])
|
196
195
|
current_page += 1
|
197
196
|
end
|
198
197
|
end
|
data/lib/magentwo.rb
CHANGED
@@ -35,6 +35,19 @@ module Magentwo
|
|
35
35
|
@@logger ||= Logger.new STDOUT, {:level => Logger::INFO}
|
36
36
|
end
|
37
37
|
|
38
|
+
def self.log_level= level
|
39
|
+
new_log_level = case level
|
40
|
+
when :debug then Logger::DEBUG
|
41
|
+
when :info then Logger::INFO
|
42
|
+
when :warn then Logger::WARN
|
43
|
+
when :error then Logger::ERROR
|
44
|
+
when :fatal then Logger::FATAL
|
45
|
+
else
|
46
|
+
raise ArgumentError, "invalid log_level"
|
47
|
+
end
|
48
|
+
self.logger= Logger.new STDOUT, {:level => new_log_level}
|
49
|
+
end
|
50
|
+
|
38
51
|
def self.default_page_size
|
39
52
|
@@default_page_size ||= 20
|
40
53
|
end
|
@@ -60,5 +73,5 @@ require_relative 'dataset.rb'
|
|
60
73
|
require_relative 'util/validator.rb'
|
61
74
|
|
62
75
|
Magentwo::Models.each do |file_name|
|
63
|
-
|
76
|
+
require_relative("model/#{file_name}.rb")
|
64
77
|
end
|
data/lib/model/base.rb
CHANGED
@@ -18,11 +18,13 @@ module Magentwo
|
|
18
18
|
|
19
19
|
def save
|
20
20
|
self.validate
|
21
|
+
self.check_presence self.class.unique_identifier
|
21
22
|
response = Magentwo::Base.call :put, "#{self.class.base_path}/#{self.send(self.class.unique_identifier)}", self
|
22
23
|
self.class.new response
|
23
24
|
end
|
24
25
|
|
25
26
|
def delete
|
27
|
+
self.check_presence self.class.unique_identifier
|
26
28
|
Magentwo::Base.call :delete, "#{self.class.base_path}/#{self.send(self.class.unique_identifier)}", nil
|
27
29
|
end
|
28
30
|
|
@@ -83,11 +85,18 @@ module Magentwo
|
|
83
85
|
base_path
|
84
86
|
end
|
85
87
|
|
86
|
-
def all ds=self.dataset
|
87
|
-
self.get(ds.to_query)
|
88
|
+
def all ds=self.dataset, meta_data:false
|
89
|
+
response = self.get(ds.to_query, :meta_data => meta_data)
|
90
|
+
items = (meta_data ? response[:items] : response)
|
88
91
|
.map do |item|
|
89
92
|
self.new item
|
90
93
|
end
|
94
|
+
if meta_data
|
95
|
+
response[:items] = items
|
96
|
+
response
|
97
|
+
else
|
98
|
+
items
|
99
|
+
end
|
91
100
|
end
|
92
101
|
|
93
102
|
def first ds=self.dataset
|
data/lib/model/order.rb
CHANGED
@@ -11,6 +11,7 @@ module Magentwo
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def customer
|
14
|
+
self.check_presence :customer_id
|
14
15
|
Magentwo::Customer[self.customer_id]
|
15
16
|
end
|
16
17
|
|
@@ -21,7 +22,7 @@ module Magentwo
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def unique_identifier
|
24
|
-
Magentwo::Logger.error "orders do not
|
25
|
+
Magentwo::Logger.error "orders do not contain id on default requests, therefore they cannot be targeted on the API"
|
25
26
|
nil
|
26
27
|
end
|
27
28
|
end
|
data/lib/model/sales_rule.rb
CHANGED
@@ -4,13 +4,18 @@ module Magentwo
|
|
4
4
|
Attributes.each do |attr| attr_accessor attr end
|
5
5
|
|
6
6
|
def generate quantity:1, length:16, format:(:alpha), delimiter:"-", delimiter_at_every:4
|
7
|
+
self.check_presence :rule_id
|
7
8
|
Magentwo::Coupon.generate self.rule_id, quantity:quantity, length:length, format:format, delimiter:delimiter, delimiter_at_every:delimiter_at_every
|
8
9
|
end
|
9
10
|
|
10
11
|
def coupons
|
12
|
+
self.check_presence :rule_id
|
11
13
|
Magentwo::Coupon.filter(:rule_id => self.rule_id).all
|
12
14
|
end
|
13
15
|
|
16
|
+
def to_json
|
17
|
+
Hash["rule", self.to_h].to_json
|
18
|
+
end
|
14
19
|
|
15
20
|
class << self
|
16
21
|
def get_path
|
data/magentwo.gemspec
CHANGED
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.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- André Mueß
|
@@ -60,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
requirements: []
|
63
|
-
rubygems_version: 3.0.
|
63
|
+
rubygems_version: 3.0.3
|
64
64
|
signing_key:
|
65
65
|
specification_version: 4
|
66
66
|
summary: Magento 2 API Wrapper
|