Is there a way to create an Anonymous (public or private) gist using net/http
or net/https
?
Asked
Active
Viewed 822 times
2 Answers
4
This worked for me.
require 'net/http'
require 'json'
uri = URI("https://api.github.com/gists")
payload = {
'description' => "My test gist",
'public' => true,
'files' => {
'test.txt' => {
'content' => "This is a test!\n\nI am making a public gist."
}
}
}
req = Net::HTTP::Post.new(uri.path)
req.body = payload.to_json
puts req.inspect
puts req.body.inspect
# GitHub API is strictly via HTTPS, so SSL is mandatory
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
http.request(req)
end
puts res.inspect
puts res.body.inspect
Result: My test gist

Wally Altman
- 3,535
- 3
- 25
- 33
-
Is there any way to do this call using Net::HTTP.post_form(...) ? – A B Feb 14 '14 at 05:40
0
This gem will do the trick for you https://github.com/defunkt/gist!
For the record, it does require net/https.

MrSynAckSter
- 1,681
- 1
- 18
- 34
-
My issue is that I want just to add a little functionality in a gem of mine without adding a whole dependency. – Aggelos Avgerinos May 03 '13 at 18:46
-
http://www.travisberry.com/2011/05/create-github-gist-with-ruby/ - this should do the trick then. – MrSynAckSter May 03 '13 at 18:50
-