Skip to content

Instantly share code, notes, and snippets.

@mkhl
Forked from schacon/example_gist_create.rb
Created December 4, 2008 23:40
Show Gist options
  • Save mkhl/32153 to your computer and use it in GitHub Desktop.
Save mkhl/32153 to your computer and use it in GitHub Desktop.
Gist API
require 'net/http'
require 'uri'
# /api/v1/:format/new
# /api/v1/:format/gists/:user
# /api/v1/:format/:gist_id
res = Net::HTTP.post_form(URI.parse('http://gist.github.com/api/v1/xml/new'),
{ 'files[file1.ab]' => 'CONTNETS',
'files[file2.ab]' => 'contents' })
puts res.body
#!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'yaml'
url = 'http://gist.github.com/api/v1/yaml/gists/mkhl'
gists = YAML::load(Net::HTTP.get(URI.parse(url)))
gists["gists"].each do |item|
puts "#{item[:repo]}: #{item[:description]}"
end
<?xml version="1.0" encoding="UTF-8"?>
<gists type="array">
<gist>
<public type="boolean">true</public>
<description nil="true"></description>
<repo>4278</repo>
<created-at type="datetime">2008-08-06T13:30:32-07:00</created-at>
</gist>
</gists>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment