Skip to content

Instantly share code, notes, and snippets.

@angeliski
Created August 5, 2020 12:09
Show Gist options
  • Save angeliski/122d265a5640a0b0930f480b720ae253 to your computer and use it in GitHub Desktop.
Save angeliski/122d265a5640a0b0930f480b720ae253 to your computer and use it in GitHub Desktop.
export code to gist
require 'net/http'
require 'json'
uri = URI("https://api.github.com/gists")
payload = {
'description' => "export code to gist",
'public' => false,
'files' => {
'ended_subusers.json' => {
'content' => File.read('some_file.json')
}
}
}
req = Net::HTTP::Post.new(uri.path)
req.body = payload.to_json
req['Authorization'] = "token TOKEN"
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment