Skip to content

Instantly share code, notes, and snippets.

@mattn mattn/file1.txt
Created Dec 20, 2012

Embed
What would you like to do?
We love mruby!
mruby is awesome!
@mattn

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.