Skip to content

Instantly share code, notes, and snippets.

@ninetwentyfour
Created May 30, 2011 02:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ninetwentyfour/998389 to your computer and use it in GitHub Desktop.
Save ninetwentyfour/998389 to your computer and use it in GitHub Desktop.
Will create a gist and return the embed code 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