Created
August 5, 2020 12:09
-
-
Save angeliski/122d265a5640a0b0930f480b720ae253 to your computer and use it in GitHub Desktop.
export code to gist
This file contains 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
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