Skip to content

Instantly share code, notes, and snippets.

@AgoristRadio
Forked from ninetwentyfour/gist_helper.rb
Last active December 15, 2015 05:39
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 AgoristRadio/5210947 to your computer and use it in GitHub Desktop.
Save AgoristRadio/5210947 to your computer and use it in GitHub Desktop.
Create GitHub Gist With Ruby #github #ruby
# http://www.travisberry.com/2011/05/create-github-gist-with-ruby/
require 'net/http'
require 'uri'
require 'json'
def get_gist(fileName,content)
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/json/new'),
{ 'files[#{fileName}]' => content,
'login' => 'USER NAME HERE',
'token' => 'API TOKEN HERE',
'description' => 'This is a test description'
})
parsed_json = JSON(res.body)
parsed_json['gists'].each do |key, val|
key.each do |k, v|
if "#{k}" == 'repo'
repo = "#{v}"
end
end
end
return "<script src=\"https://gist.github.com/#{repo}.js\"></script>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment