Skip to content

Instantly share code, notes, and snippets.

@yosmoc
Created July 27, 2008 08:06
Show Gist options
  • Save yosmoc/2764 to your computer and use it in GitHub Desktop.
Save yosmoc/2764 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'pit'
require 'mechanize'
require 'uri'
pit = Pit.get('github', :require => {
'username' => 'username',
'password' => 'password'})
BASE = URI('http://gist.github.com/')
@agent = WWW::Mechanize.new
login_page = @agent.get(BASE + 'login?return_to=gist')
login_form = login_page.forms.first
login_form['login'] = pit['username']
login_form['password'] = pit['password']
@agent.submit(login_form)
gist_new_page = @agent.get(BASE)
filename = ARGV.shift
language = '.'+ filename.split('.').last
File.open(filename) { |file| @content = file.read }
gist_form = gist_new_page.forms.first
gist_form["file_name[gistfile1]"] = filename
gist_form["file_contents[gistfile1]"] = @content
gist_form["file_ext[gistfile1]"] = language
@agent.submit(gist_form)
p @agent.page.links.href(/^git:/).text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment