Skip to content

Instantly share code, notes, and snippets.

@yaotti
Created July 30, 2011 17:11
Show Gist options
  • Save yaotti/1115757 to your computer and use it in GitHub Desktop.
Save yaotti/1115757 to your computer and use it in GitHub Desktop.
v3 APIを使ってGistに投稿する適当スクリプト
#!/usr/bin/env ruby
# a test script to post gist
# usage: GITHUB_TOKEN=xxxxxxx $0
require 'net/https'
require 'uri'
require 'json'
require 'pp'
uri = URI.parse("https://api.github.com/gists?access_token=#{ENV['GITHUB_TOKEN']}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
postdata = {
"description" => "the description for this gist",
"public" => true,
"files" => {
"file1.txt" => {
"content" => "String file contents"
}
}
}
request = Net::HTTP::Post.new(uri.request_uri)
request.body = postdata.to_json
response, data = http.request(request)
pp JSON.parse(response.body)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment