Skip to content

Commit

Permalink
Attempt to modernize examples, but I'm not sure if they all still wor…
Browse files Browse the repository at this point in the history
…k with my changes. Issue #108
  • Loading branch information
drbrain committed Jun 24, 2011
1 parent 5e03824 commit 442ceae
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 18 deletions.
13 changes: 6 additions & 7 deletions examples/flickr_upload.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'rubygems'
require 'mechanize'

agent = Mechanize.new

# Get the flickr sign in page
page = agent.get('http://flickr.com/signin/flickr/')
page = agent.get 'http://flickr.com/signin/flickr/'

# Fill out the login form
form = page.form_with(:name => 'flickrloginform')
form = page.form_with :name => 'flickrloginform'
form.email = ARGV[0]
form.password = ARGV[1]
page = agent.submit(form)
form.submit

# Go to the upload page
page = agent.click page.link_with(:text => 'Upload')
page = page.link_with(:text => 'Upload').click

# Fill out the form
form = page.forms.action('/photos_upload_process.gne').first
form.file_uploads.name('file1').first.file_name = ARGV[2]
agent.submit(form)
form.submit

2 changes: 0 additions & 2 deletions examples/mech-dump.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'rubygems'
require 'mechanize'

Expand Down
2 changes: 0 additions & 2 deletions examples/proxy_req.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'rubygems'
require 'mechanize'

Expand Down
4 changes: 1 addition & 3 deletions examples/rubyforge.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

# This example logs a user in to rubyforge and prints out the body of the
# page after logging the user in.
require 'rubygems'
Expand All @@ -17,6 +15,6 @@
form.form_pw = ARGV[1]

# Submit the form
page = agent.submit(form, form.buttons.first)
page = form.submit form.buttons.first

puts page.body # Print out the body
5 changes: 2 additions & 3 deletions examples/spider.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
$:.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'rubygems'
require 'mechanize'

agent = Mechanize.new
stack = agent.get(ARGV[0]).links

while l = stack.pop
next unless l.uri
host = l.uri.host
next unless host.nil? or host == agent.history.first.uri.host
next if agent.visited? l.href

puts "crawling #{l.uri}"
begin
page = agent.click(l)
page = l.click
next unless Mechanize::Page === page
stack.push(*page.links)
rescue Mechanize::ResponseCodeError
Expand Down
2 changes: 1 addition & 1 deletion lib/mechanize/form/field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def <=> other
return -1 if Hash === other.node
node <=> other.node
end

# This method is a shortcut to get field's DOM id.
# Common usage: form.field_with(:dom_id => "foo")
def dom_id
Expand Down

0 comments on commit 442ceae

Please sign in to comment.