magento_remote 0.1.1 → 0.1.2

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MTY4MzBjMGViZWVjZTQwMGVhNjBkZDViNjRhYzNlNzVmYzUwZjc3ZQ==
4
+ ZWJlMDMyMjViOWFmMDdjYTMyODVlNTViMTYwYWQ5MjU5MDUwZjg1Zg==
5
5
  data.tar.gz: !binary |-
6
- ZTUwYzU3MzllMmE0MjQ0ZjFlYjhiN2VlYzUwMWNhOGQ2OTg2Y2E4YQ==
6
+ OWVmMjRhMDA0OGU1NzhlMWFmOTk5MTA2ZmM3ZThhZWJkNTc0ZmVkNQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YWRkOTg3MTY5YjVmZGFiNDdjNjA1NjA0ZTcwMmRkNzQxODg3NzU3ZmY0ZDI5
10
- YmE4NzM5YmI0MTM3YmNkNTRjMjgxZmIxMjVhNDhiYTY1NjEwYzJhZTg3MDcz
11
- MmVkYmI1YmQ0YmM1ZmVkMzM5NGIwNGU1NzFkNWY2ZjUxNzU2MzU=
9
+ Y2VhYWQxMjNlZmQ1ZDk5YjQ0ZDc3ZjBkN2RmMzlmN2RjNjM1ZGY1YjdkYTgx
10
+ OGE2OGNmODcxZTAzNDc0ZGNiMzM4ZDEyMDQyOWEzNmEyYjNjOTY2YjIxMmM2
11
+ ODAzNWI4YTZmMmM5N2I4MDcwMWY4NzllZTUyYWEzODY3Mzk2ZmQ=
12
12
  data.tar.gz: !binary |-
13
- MTQ1NGUxMGQ0NDBmNTc5OGVlZWM0ZGQ4ZWNlMTMyODY0OWRhMjg2ZDMxMDhh
14
- MWI5YjVmNDExMjMzMTE5OTU4Y2JhNGM3OTRlYTU0ZWVkNDNhN2JmN2RhNDMy
15
- MjJjYzEyNmE5YTgyZjgxMDM1M2NhMTAwZTg1OTM2MWY5MzhjYjU=
13
+ MzdjMzk0ZjZjZjkzZmFmYjdiZjgxNjUzZDYxOWY2MDEzOGJkMzk0MTYxYzU1
14
+ ZjkyMDk5MjNmNWMzMDA3OTM1YWM5YzMxMDZmNjdmOWVjNmNhNDMxODQ2MDI2
15
+ Zjg3MjVmNTE2YTVkOTRjODgyZmNmNzUwMWM5ZWQ0MTExMWE0NWU=
@@ -64,10 +64,27 @@ class MagentoMech
64
64
  # Puts as many items of given product to cart as possible
65
65
  # Returns number of items put to cart.
66
66
  def add_to_cart! product_id, qty
67
+ # Try to be a bit clever and early find out whether article
68
+ # is out of stock.
69
+ if add_to_cart(product_id, qty)
70
+ return qty
71
+ end
72
+ num_ordered = 0
73
+ # Apparently not enough in stock!
74
+
75
+ if qty.to_i > 4
76
+ if !add_to_cart(product_id, 1)
77
+ # out of stock
78
+ return 0
79
+ else
80
+ num_ordered = 1
81
+ qty = qty.to_i - 1
82
+ end
83
+ end
67
84
  while qty.to_i > 0 && !add_to_cart(product_id, qty)
68
85
  qty = qty.to_i - 1
69
86
  end
70
- qty.to_i
87
+ qty.to_i + num_ordered
71
88
  end
72
89
 
73
90
  # Get the current carts contents
@@ -134,6 +151,7 @@ class MagentoMech
134
151
  # start_pid: With which product id to start scraping
135
152
  # returns [[name1, product_id1, instock?1],[name2, p_id2...]...]
136
153
  # or nil if not found.
154
+ # yielding would be nice
137
155
  def scrape_products start_pid, limit
138
156
  products = []
139
157
  limit.times do |idx|
@@ -145,6 +163,9 @@ class MagentoMech
145
163
  wishlist_link.attributes['href'].value[/product\/(\d+)/]
146
164
  pid = $1
147
165
  products << [product_name, pid]
166
+ if block_given?
167
+ yield [product_name, pid]
168
+ end
148
169
  end
149
170
 
150
171
  return products
@@ -1,3 +1,3 @@
1
1
  module MagentoRemote
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.2".freeze
3
3
  end
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency 'mechanize'
22
- spec.add_dependency 'terminal-table'
21
+ spec.add_dependency 'mechanize', "~> 2.7"
22
+ spec.add_dependency 'terminal-table', "~> 1.4"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.6"
25
25
  spec.add_development_dependency "rake"
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magento_remote
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Wolfsteller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-05 00:00:00.000000000 Z
11
+ date: 2014-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '2.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: terminal-table
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '1.4'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '1.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement