Skip to content

Instantly share code, notes, and snippets.

@emad-elsaid
Created March 5, 2014 12:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save emad-elsaid/9366614 to your computer and use it in GitHub Desktop.
Save emad-elsaid/9366614 to your computer and use it in GitHub Desktop.
post to gist
#!/usr/bin/env ruby
# Credits to :
# http://stackoverflow.com/questions/16365553/creating-gist-from-a-ruby-script
# i modified the script alittle bit to read files from params
require 'net/http'
require 'json'
uri = URI("https://api.github.com/gists")
files = {}
ARGV.each do |f|
files[f] = {
content: File.read(f)
}
end
payload = {
'public' => true,
'files' => files
}
req = Net::HTTP::Post.new(uri.path)
req.body = payload.to_json
puts req.inspect
puts req.body.inspect
# GitHub API is strictly via HTTPS, so SSL is mandatory
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
http.request(req)
end
response = JSON.parse res.body
puts response['html_url']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment