-
-
Save AgoristRadio/5210947 to your computer and use it in GitHub Desktop.
Create GitHub Gist With Ruby #github #ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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