magento_remote 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/bin/magento_add_to_cart +3 -1
- data/bin/magento_find_product +3 -1
- data/bin/magento_list_orders +65 -0
- data/bin/magento_scrape +3 -1
- data/bin/{magento_list_order → magento_show_last_order} +3 -1
- data/lib/bin_helper.rb +34 -0
- data/lib/magento_remote/magento_mech.rb +14 -3
- data/lib/magento_remote/version.rb +1 -1
- data/magento_remote.gemspec +2 -0
- metadata +21 -4
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZWMyMzg2MGJhMzVlZGExZmVkMjljOGJkYjdlMmVlOWI1MzY3NWQ0Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWRiZTM2MDUxMzJlOTIwNzY5M2FmNmNmMTdhNWJkNWZkNmI4YTQ2OQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2JiM2YyYzZjMjJiNTA3NDk4MGUxMjM1ZjllMTQ4ZmQzYTNlMTI1ZjM2NmMx
|
10
|
+
NzM4NzNiNmMwZjgwYWVlZTYzNzJlMzI3MTVmMzVlZTEwZDcxODc4MTE4NmU1
|
11
|
+
OGNkYWE0YjY1NjViMDkxMWQxMjVlODEwMmZkYWQ4OTAzMjNjZjM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2Q0YTUyNmEwYjI5YTNmYjk0NjRhZDI5YmY0MDM1NjgxNWFhZjQ0NzY3Yzk5
|
14
|
+
OWE0MTFhOWJjYWZiMmMxMGMyYTk4MjUwYjk0M2U5MTVmZjRmNDU4OWIyOTcy
|
15
|
+
ZDRlOTZhMjMzYjYwYmEyMGYxNWE3NDkxZDk0OTFkYTgzNGU1NmQ=
|
data/bin/magento_add_to_cart
CHANGED
@@ -2,12 +2,14 @@
|
|
2
2
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'magento_remote'
|
5
|
+
require 'bin_helper'
|
5
6
|
|
6
7
|
# Sweet, sweet options.
|
7
8
|
options = {}
|
9
|
+
program_name = File.basename __FILE__
|
8
10
|
|
9
11
|
optparse = OptionParser.new do |opts|
|
10
|
-
opts.banner = "Usage:
|
12
|
+
opts.banner = "Usage: #{program_name} [OPTIONS]"
|
11
13
|
|
12
14
|
opts.separator ""
|
13
15
|
opts.separator "Magento shop options"
|
data/bin/magento_find_product
CHANGED
@@ -3,12 +3,14 @@
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'terminal-table'
|
5
5
|
require 'magento_remote'
|
6
|
+
require 'bin_helper'
|
6
7
|
|
7
8
|
# Sweet, sweet options.
|
8
9
|
options = {}
|
10
|
+
program_name = File.basename __FILE__
|
9
11
|
|
10
12
|
optparse = OptionParser.new do |opts|
|
11
|
-
opts.banner = "Usage:
|
13
|
+
opts.banner = "Usage: #{program_name} [OPTIONS]\n Find product(s) in shop."
|
12
14
|
|
13
15
|
opts.separator ""
|
14
16
|
opts.separator "Magento shop options"
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'terminal-table'
|
5
|
+
require 'magento_remote'
|
6
|
+
require 'bin_helper'
|
7
|
+
|
8
|
+
# Sweet, sweet options.
|
9
|
+
options = {}
|
10
|
+
program_name = File.basename __FILE__
|
11
|
+
|
12
|
+
optparse = OptionParser.new do |opts|
|
13
|
+
opts.banner = "Usage: #{program_name} [OPTIONS]\n Show last order."
|
14
|
+
|
15
|
+
opts.separator ""
|
16
|
+
MagentoRemote::CLI::Options::add_shop_options opts, options
|
17
|
+
|
18
|
+
opts.separator ""
|
19
|
+
opts.separator "Output options"
|
20
|
+
|
21
|
+
opts.on('-d', '--debug FILE', 'enable debugging output, STDOUT, or FILE if given') do |d|
|
22
|
+
if d
|
23
|
+
options[:debug] = d
|
24
|
+
else
|
25
|
+
options[:debug] = true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.separator ""
|
30
|
+
opts.separator "General options"
|
31
|
+
|
32
|
+
opts.on_tail('--version', 'Show version.') do
|
33
|
+
puts "magento_list_order #{MagentoRemote::VERSION}"
|
34
|
+
exit 0
|
35
|
+
end
|
36
|
+
opts.on('-h', '--help', 'Show help.') do
|
37
|
+
puts opts
|
38
|
+
exit 0
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
optparse.parse!
|
43
|
+
|
44
|
+
# Exit if not all obligatory params given.
|
45
|
+
MagentoRemote::CLI::Options::exit_obligatory! options
|
46
|
+
|
47
|
+
mech = MagentoMech.from_config options
|
48
|
+
if options[:debug] == true
|
49
|
+
mech.log_to! STDOUT
|
50
|
+
elsif options[:debug]
|
51
|
+
mech.log_to! options[:debug]
|
52
|
+
end
|
53
|
+
|
54
|
+
return_code = 0
|
55
|
+
|
56
|
+
mech.login
|
57
|
+
|
58
|
+
orders = mech.last_orders
|
59
|
+
if orders.empty?
|
60
|
+
puts "Nothing found"
|
61
|
+
else
|
62
|
+
puts Terminal::Table.new :headings => ['Date', 'Volume', 'link'], :rows => orders
|
63
|
+
end
|
64
|
+
|
65
|
+
exit return_code
|
data/bin/magento_scrape
CHANGED
@@ -3,12 +3,14 @@
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'terminal-table'
|
5
5
|
require 'magento_remote'
|
6
|
+
require 'bin_helper'
|
6
7
|
|
7
8
|
# Sweet, sweet options.
|
8
9
|
options = {}
|
10
|
+
program_name = File.basename __FILE__
|
9
11
|
|
10
12
|
optparse = OptionParser.new do |opts|
|
11
|
-
opts.banner = "Usage:
|
13
|
+
opts.banner = "Usage: #{program_name} [OPTIONS]\n Find product(s) in shop."
|
12
14
|
|
13
15
|
opts.separator ""
|
14
16
|
opts.separator "Magento shop options"
|
@@ -3,12 +3,14 @@
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'terminal-table'
|
5
5
|
require 'magento_remote'
|
6
|
+
require 'bin_helper'
|
6
7
|
|
7
8
|
# Sweet, sweet options.
|
8
9
|
options = {}
|
10
|
+
program_name = File.basename __FILE__
|
9
11
|
|
10
12
|
optparse = OptionParser.new do |opts|
|
11
|
-
opts.banner = "Usage:
|
13
|
+
opts.banner = "Usage: #{program_name} [OPTIONS]\n Show last order."
|
12
14
|
|
13
15
|
opts.separator ""
|
14
16
|
opts.separator "Magento shop options"
|
data/lib/bin_helper.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# "Helpers" for the binary/programs
|
2
|
+
module MagentoRemote
|
3
|
+
module CLI
|
4
|
+
module Options
|
5
|
+
# Register customer, password and base-uri options.
|
6
|
+
def self.add_shop_options opts, options
|
7
|
+
opts.separator "Magento shop options"
|
8
|
+
|
9
|
+
opts.on('-u', '--customer USER',
|
10
|
+
'customer/username of shop.') do |u|
|
11
|
+
options[:user] = u
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on('-p', '--password PASSWORD',
|
15
|
+
'password of customer account.') do |p|
|
16
|
+
options[:pass] = p
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on('-b', '--base-uri URI',
|
20
|
+
'base URI of shop.') do |b|
|
21
|
+
options[:base_uri] = b
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# Exit if obligatory options not given.
|
26
|
+
def self.exit_obligatory! options
|
27
|
+
if !options[:user] || !options[:pass] || !options[:base_uri]
|
28
|
+
STDERR.puts "Error: You have to define user, pass and base_uri. (see --help)"
|
29
|
+
exit 1
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -7,14 +7,15 @@ require 'logger'
|
|
7
7
|
class MagentoMech
|
8
8
|
attr_accessor :user
|
9
9
|
attr_accessor :pass
|
10
|
+
attr_accessor :base_uri
|
10
11
|
|
11
12
|
# Create Mech from hash
|
12
13
|
# Argument conf
|
13
14
|
# values :base_uri, :user, :pass.
|
14
15
|
def self.from_config(conf)
|
15
|
-
client = MagentoMech.new(conf[:base_uri])
|
16
|
-
client.user = conf[:user]
|
17
|
-
client.pass = conf[:pass]
|
16
|
+
client = MagentoMech.new(conf[:base_uri] || conf['base_uri'])
|
17
|
+
client.user = conf[:user] || conf['user']
|
18
|
+
client.pass = conf[:pass] || conf['pass']
|
18
19
|
client
|
19
20
|
end
|
20
21
|
|
@@ -175,6 +176,16 @@ class MagentoMech
|
|
175
176
|
return products
|
176
177
|
end
|
177
178
|
|
179
|
+
# Return list [date, volume, link] of last orders
|
180
|
+
def last_orders
|
181
|
+
orders_url = relative_url("/customer/account/")
|
182
|
+
@mech.get orders_url
|
183
|
+
@mech.page.search('#my-orders-table tbody tr').map do |order_row|
|
184
|
+
row_columns = order_row.search("td")
|
185
|
+
[row_columns[1].text, row_columns[3].text, row_columns[5].search("a").first[:href]]
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
178
189
|
# Get products of last order.
|
179
190
|
# Arguments
|
180
191
|
# returns [[product_name1, product_sku1, qty_ordered1],[name2, sku2...]...]
|
data/magento_remote.gemspec
CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "bundler", "~> 1.6"
|
25
25
|
spec.add_development_dependency "rake"
|
26
26
|
spec.add_development_dependency "rspec"
|
27
|
+
# cli tools should be configured by inifiles in 0.2.1
|
28
|
+
spec.add_development_dependency "inifile"
|
27
29
|
end
|
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.
|
4
|
+
version: 0.2.0
|
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-08
|
11
|
+
date: 2014-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mechanize
|
@@ -80,14 +80,29 @@ dependencies:
|
|
80
80
|
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: inifile
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Allows ordering through a (defaultish) magento web page.
|
84
98
|
email:
|
85
99
|
- felix.wolfsteller@gmail.com
|
86
100
|
executables:
|
87
101
|
- magento_add_to_cart
|
88
102
|
- magento_find_product
|
89
|
-
-
|
103
|
+
- magento_list_orders
|
90
104
|
- magento_scrape
|
105
|
+
- magento_show_last_order
|
91
106
|
extensions: []
|
92
107
|
extra_rdoc_files: []
|
93
108
|
files:
|
@@ -101,8 +116,10 @@ files:
|
|
101
116
|
- Rakefile
|
102
117
|
- bin/magento_add_to_cart
|
103
118
|
- bin/magento_find_product
|
104
|
-
- bin/
|
119
|
+
- bin/magento_list_orders
|
105
120
|
- bin/magento_scrape
|
121
|
+
- bin/magento_show_last_order
|
122
|
+
- lib/bin_helper.rb
|
106
123
|
- lib/magento_remote.rb
|
107
124
|
- lib/magento_remote/magento_mech.rb
|
108
125
|
- lib/magento_remote/version.rb
|