magento_remote 0.1.6 → 0.2.0

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
- OTJhNDBjMTU0NjEyODY3MTdlOTlkYmVkYmZlZGFmN2EyNTFiMGI4Mw==
4
+ ZWMyMzg2MGJhMzVlZGExZmVkMjljOGJkYjdlMmVlOWI1MzY3NWQ0Yw==
5
5
  data.tar.gz: !binary |-
6
- MzcwMjQzNjdhZmE5YTg4NTg3MDk5ZTU1MDFjMWYyMGQ4NDgxNTlmNA==
6
+ NWRiZTM2MDUxMzJlOTIwNzY5M2FmNmNmMTdhNWJkNWZkNmI4YTQ2OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWY2NjRjMzFiZTFkODdlMzFiZmU3NjE2Y2Q0MGQzZTA1ZGFkOWRlNmM0MTM2
10
- MGU3NDg4ZGIyODc5MGU1NDdhOGJkZWY1YjNiNmNiZWNhZTMyMGI4NGEwZWZj
11
- MDI4NzJmOWY1ZTFkYTJlMzRjNGQ5OTIyNGM0NTlkYjFlZGY1ZWE=
9
+ N2JiM2YyYzZjMjJiNTA3NDk4MGUxMjM1ZjllMTQ4ZmQzYTNlMTI1ZjM2NmMx
10
+ NzM4NzNiNmMwZjgwYWVlZTYzNzJlMzI3MTVmMzVlZTEwZDcxODc4MTE4NmU1
11
+ OGNkYWE0YjY1NjViMDkxMWQxMjVlODEwMmZkYWQ4OTAzMjNjZjM=
12
12
  data.tar.gz: !binary |-
13
- Y2Y2MzdlOGM3MTNiOGE5OTdkMDcwZTNiODMwMGRhNmJkZWQyMzM2MGU3OTgw
14
- NjI3YWFiYTM1NzRjMzIzZjZiZmE3OTU0MDJmM2IxMjE3MWU3ZTZkNmI3M2Q2
15
- MGZmNTIyNzk3ZWY5OGNhZGU3ZTAzNmUwM2RkMDU5ZmQ2MGI0NzA=
13
+ Y2Q0YTUyNmEwYjI5YTNmYjk0NjRhZDI5YmY0MDM1NjgxNWFhZjQ0NzY3Yzk5
14
+ OWE0MTFhOWJjYWZiMmMxMGMyYTk4MjUwYjk0M2U5MTVmZjRmNDU4OWIyOTcy
15
+ ZDRlOTZhMjMzYjYwYmEyMGYxNWE3NDkxZDk0OTFkYTgzNGU1NmQ=
@@ -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: magento_add_to_cart [OPTIONS]"
12
+ opts.banner = "Usage: #{program_name} [OPTIONS]"
11
13
 
12
14
  opts.separator ""
13
15
  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: magento_find_product [OPTIONS]\n Find product(s) in shop."
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: magento_scrape [OPTIONS]\n Find product(s) in shop."
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: magento_list_order [OPTIONS]\n Show last order."
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...]...]
@@ -1,3 +1,3 @@
1
1
  module MagentoRemote
2
- VERSION = "0.1.6".freeze
2
+ VERSION = "0.2.0".freeze
3
3
  end
@@ -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.1.6
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-31 00:00:00.000000000 Z
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
- - magento_list_order
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/magento_list_order
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