Skip to content

Instantly share code, notes, and snippets.

@mattn
Created December 20, 2012 04:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/4342903 to your computer and use it in GitHub Desktop.
Save mattn/4342903 to your computer and use it in GitHub Desktop.
We love mruby!
mruby is awesome!
@mattn
Copy link
Author

mattn commented Dec 20, 2012

mruby-curl mruby-http mruby-json 使ってこんな感じでポストしました。

#!mruby

if ARGV.size != 1
  raise "gist.rb [GIST_TOKEN]"
end

req = HTTP::Request.new
req.method = "POST"
req.body = JSON::stringify({
  "description"=> "We love mruby!",
  "public"=> true,
  "files"=> {
    "file1.txt"=> {
      "content"=> "mruby is awesome!"
    }
  }
})
req.headers['Authorization'] = "token #{ARGV[0]}"
req.headers['Content-Type'] = "application/json"
Curl::SSL_VERIFYPEER = 0
res = Curl::send("https://api.github.com/gists", req)
puts JSON::parse(res.body)['html_url']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment