Created
July 30, 2011 17:11
-
-
Save yaotti/1115757 to your computer and use it in GitHub Desktop.
v3 APIを使ってGistに投稿する適当スクリプト
This file contains hidden or 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
#!/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