Created
November 19, 2012 22:34
-
-
Save danmartens/4114538 to your computer and use it in GitHub Desktop.
Mechanize - Submit to 99 Designs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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