Skip to content

Instantly share code, notes, and snippets.

@joet3ch
Created December 8, 2010 06:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joet3ch/732968 to your computer and use it in GitHub Desktop.
Save joet3ch/732968 to your computer and use it in GitHub Desktop.
require 'rexml/document'
require 'net/http'
require 'uri'
url = URI.parse('http://gist.github.com/api/v1/xml/new')
name = ENV['SNIPPET_NAME']
puts "Uploading: #{name}"
snippet = ENV['SNIPPET_SOURCE_CODE']
response = Net::HTTP.post_form(url, 'files[file1.ab]' => snippet, 'login' => 'your_username', 'token' => 'your_api_token')
doc = REXML::Document.new(response.body)
gist = REXML::XPath.first(doc, "/gists/gist/repo/text()")
snippet_url = "http://gist.github.com/#{gist}"
puts "Snippet is successfully uploaded at #{snippet_url}"
ENV['GIST_SNIPPET_URL'] = snippet_url
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment