Skip to content

Instantly share code, notes, and snippets.

@danmartens
Created November 19, 2012 22:34
Show Gist options
  • Save danmartens/4114538 to your computer and use it in GitHub Desktop.
Save danmartens/4114538 to your computer and use it in GitHub Desktop.
Mechanize - Submit to 99 Designs
require 'mechanize'
@agent = Mechanize.new
@agent.user_agent_alias = 'Mac Safari'
def sign_in(email, password)
page = @agent.get "https://99designs.com/login"
form = page.forms.first
form.field_with(name: 'email').value = email
form.field_with(name: 'password').value = password
@agent.submit(form)
end
def submit_design(contest_uri, comment, file_name)
page = @agent.get "https://99designs.com/web-design/contests/#{contest_uri}/enter"
form = page.forms.first
form.field_with(name: 'description').value = comment
form.file_uploads.first.file_name = file_name
form.radiobutton_with(name: 'licensedelements', value: 'no').check
puts @agent.submit(form).inspect
end
sign_in(email, password)
submit_design(uri, 'This is my first attempt.', 'upload.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment