Created
May 30, 2011 02:42
-
-
Save ninetwentyfour/998389 to your computer and use it in GitHub Desktop.
Will create a gist and return the embed code with 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
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