public
Created

  • Download Gist
file1.ab
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.