magento_remote 0.1.2 → 0.1.3
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 +8 -8
- data/bin/magento_list_order +75 -0
- data/lib/magento_remote/magento_mech.rb +20 -0
- data/lib/magento_remote/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
---
|
|
2
2
|
!binary "U0hBMQ==":
|
|
3
3
|
metadata.gz: !binary |-
|
|
4
|
-
|
|
4
|
+
YWQ0NWJkN2IyZDM2NmQ0YzBkY2Q5NDM4ZWJhNDI3NGU4NjZkMzdjMQ==
|
|
5
5
|
data.tar.gz: !binary |-
|
|
6
|
-
|
|
6
|
+
ZWQwMjE5NjIwMTY5ZjA4NDU1MzEzMzA4NTQ1NTc0Nzg2N2UxOTg2OA==
|
|
7
7
|
SHA512:
|
|
8
8
|
metadata.gz: !binary |-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
M2RmYmE3YWM5NzEyODcxMTFkYWRiYmQ3MjAzMjg1M2VhNDg5NjcyYjI0YTIw
|
|
10
|
+
ZmExNjg5MmI2MTA1Y2VhZDc2MmFlNTJkOGY5ODk2NGIyMzhhYmZjNDA5ZTZm
|
|
11
|
+
MGVlYWJiMjk5NzYzOGRiZmJlMzY4ZGU1NTUyNDMzOGMyZWZlYzI=
|
|
12
12
|
data.tar.gz: !binary |-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
MmFmY2RlNDQ3NTY2ZDc5Y2M3YTllMDU5MmM5ZDI0YjI1N2I2N2Y2NmI4NTEz
|
|
14
|
+
NDE0NDM3ODg2YzJhMjJiMGY1MTBkNDcxMmE2ZGQxOWJlMDkxZmJjYjI4NGM5
|
|
15
|
+
ZTA3OWRlNzlhMDg3ZWE3ODVhNzk5Y2RjNzgxZjRkZDBhYTczOWM=
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require 'terminal-table'
|
|
5
|
+
require 'magento_remote'
|
|
6
|
+
|
|
7
|
+
# Sweet, sweet options.
|
|
8
|
+
options = {}
|
|
9
|
+
|
|
10
|
+
optparse = OptionParser.new do |opts|
|
|
11
|
+
opts.banner = "Usage: magento_list_order [OPTIONS]\n Show last order."
|
|
12
|
+
|
|
13
|
+
opts.separator ""
|
|
14
|
+
opts.separator "Magento shop options"
|
|
15
|
+
|
|
16
|
+
opts.on('-u', '--customer USER', 'customer/username of shop.') do |u|
|
|
17
|
+
options[:user] = u
|
|
18
|
+
end
|
|
19
|
+
opts.on('-p', '--password PASSWORD', 'password of customer account.') do |p|
|
|
20
|
+
options[:pass] = p
|
|
21
|
+
end
|
|
22
|
+
opts.on('-b', '--base-uri URI', 'base URI of shop.') do |b|
|
|
23
|
+
options[:base_uri] = b
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
opts.separator ""
|
|
27
|
+
opts.separator "Output options"
|
|
28
|
+
|
|
29
|
+
opts.on('-d', '--debug FILE', 'enable debugging output, STDOUT, or FILE if given') do |d|
|
|
30
|
+
if d
|
|
31
|
+
options[:debug] = d
|
|
32
|
+
else
|
|
33
|
+
options[:debug] = true
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
opts.separator ""
|
|
38
|
+
opts.separator "General options"
|
|
39
|
+
|
|
40
|
+
opts.on_tail('--version', 'Show version.') do
|
|
41
|
+
puts "magento_list_order #{MagentoRemote::VERSION}"
|
|
42
|
+
exit 0
|
|
43
|
+
end
|
|
44
|
+
opts.on('-h', '--help', 'Show help.') do
|
|
45
|
+
puts opts
|
|
46
|
+
exit 0
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
optparse.parse!
|
|
51
|
+
|
|
52
|
+
if !options[:user] || !options[:pass] || !options[:base_uri]
|
|
53
|
+
STDERR.puts "Error: You have to define user, pass and base_uri"
|
|
54
|
+
exit 1
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
mech = MagentoMech.from_config options
|
|
58
|
+
if options[:debug] == true
|
|
59
|
+
mech.log_to! STDOUT
|
|
60
|
+
elsif options[:debug]
|
|
61
|
+
mech.log_to! options[:debug]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
return_code = 0
|
|
65
|
+
|
|
66
|
+
mech.login
|
|
67
|
+
|
|
68
|
+
products = mech.last_order_products
|
|
69
|
+
if products.empty?
|
|
70
|
+
puts "Nothing found"
|
|
71
|
+
else
|
|
72
|
+
puts Terminal::Table.new :headings => ['Name', 'Product SKU', 'Quantity ordered'], :rows => products
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
exit return_code
|
|
@@ -171,6 +171,26 @@ class MagentoMech
|
|
|
171
171
|
return products
|
|
172
172
|
end
|
|
173
173
|
|
|
174
|
+
# Get products of last order.
|
|
175
|
+
# Arguments
|
|
176
|
+
# returns [[product_name1, product_sku1, qty_ordered1],[name2, sku2...]...]
|
|
177
|
+
# or empty list if not found.
|
|
178
|
+
def last_order_products
|
|
179
|
+
orders_url = relative_url("/customer/account/")
|
|
180
|
+
@mech.get orders_url
|
|
181
|
+
#@mech.page.save_as "orders_page.html"
|
|
182
|
+
order_url = @mech.page.search('.a-center a').first.attributes['href']
|
|
183
|
+
puts "order_url #{order_url}"
|
|
184
|
+
@mech.get order_url
|
|
185
|
+
@mech.page.save_as "order_page.html"
|
|
186
|
+
@mech.page.search('tr.border').map do |tr|
|
|
187
|
+
product_name = tr.children[1].children[0].content
|
|
188
|
+
product_sku = tr.children[3].children[0].content
|
|
189
|
+
product_qty = tr.children[7].children[1].content[/\d/]
|
|
190
|
+
[product_name, product_sku, product_qty]
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
174
194
|
private
|
|
175
195
|
|
|
176
196
|
# Construct path relative to base uri.
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: magento_remote
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
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-07-
|
|
11
|
+
date: 2014-07-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mechanize
|
|
@@ -86,6 +86,7 @@ email:
|
|
|
86
86
|
executables:
|
|
87
87
|
- magento_add_to_cart
|
|
88
88
|
- magento_find_product
|
|
89
|
+
- magento_list_order
|
|
89
90
|
- magento_scrape
|
|
90
91
|
extensions: []
|
|
91
92
|
extra_rdoc_files: []
|
|
@@ -100,6 +101,7 @@ files:
|
|
|
100
101
|
- Rakefile
|
|
101
102
|
- bin/magento_add_to_cart
|
|
102
103
|
- bin/magento_find_product
|
|
104
|
+
- bin/magento_list_order
|
|
103
105
|
- bin/magento_scrape
|
|
104
106
|
- lib/magento_remote.rb
|
|
105
107
|
- lib/magento_remote/magento_mech.rb
|