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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76391fb49be2eacf141856ba17a36dda1edd5b08e0e7069be28ae7bedef35736
4
- data.tar.gz: f6faa7a572b2a0c71007852272ad227032224786c8a42691cde861213a2591c5
3
+ metadata.gz: aa0539c40b51df6d70767268e48405720552c3760e5eb50bf0743de635428924
4
+ data.tar.gz: e95ee4c5eac328f66fcd5653b8b5c4530eaa396df8671b6a2b2c019583043fad
5
5
  SHA512:
6
- metadata.gz: 8ca9a91c6c9e7cbd6df412e71fb418bf79adc68f40c10bb165ba8af3953f1717859f6562c01f5758c4669884cfd66fb14e657a6b00a6df43599624ee092e99f8
7
- data.tar.gz: 985a28699825066decefabdbe438afcad4d4db0105ac12df34971c68c17a70c7cf7a427352a2101daa57d8d9f517f67ac5c133b06a0cfd693cff504d5dfc20ca
6
+ metadata.gz: 1924091ecf2d564e164f1dc380adaca6321016e6a6eecb9514e5a288c8be1619a6e38b60d27dd831d2e07e70b174586121367fd7c2dfbae4737cbae920d17aca
7
+ data.tar.gz: edd7edc4deb94fcd308dc004fcda0cb6b6e8dcd1c692afb7b76f2db028ab28db8f4a054e1fd6421ffb93e1a3aa615ec61cd02f09aff466a85b2ecde757032b62
@@ -1,6 +1,7 @@
1
1
  module Magentwo
2
2
  class Adapter < Magentwo::Connection
3
- DateFields = %i(created_at dob updated_at)
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] = Time.parse item[date_field] if 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
@@ -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
- while(received_element_count == page_size) do
191
- page = self.page(current_page, page_size).all
192
-
193
- block.call(page)
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
@@ -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
- require_relative("model/#{file_name}.rb")
76
+ require_relative("model/#{file_name}.rb")
64
77
  end
@@ -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
@@ -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 container id on default requests, therefore they cannot be targeted on the API"
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
@@ -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
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'magentwo'
3
- s.version = '0.1.7'
3
+ s.version = '0.1.8'
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.7
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.2
63
+ rubygems_version: 3.0.3
64
64
  signing_key:
65
65
  specification_version: 4
66
66
  summary: Magento 2 API Wrapper