Skip to content

Instantly share code, notes, and snippets.

@ongaeshi
Created November 13, 2016 07:51
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 ongaeshi/a169ba85d04350e7dbf7d5b359f884c2 to your computer and use it in GitHub Desktop.
Save ongaeshi/a169ba85d04350e7dbf7d5b359f884c2 to your computer and use it in GitHub Desktop.
# https://developer.github.com/v3/gists/#create-a-gist
TOKEN = "XXXXXX"
def new_gist(filename, content)
json = {
# description: "Created by RubyPico at #{Time.now}",
public: true,
files: {
filename => {
content: content
},
}
}
Browser.post(
"https://api.github.com/gists",
header: { "Authorization" => "token #{TOKEN}" },
json: json
)
end
puts "Specify path"
path = prompt
File.open(path) do |f|
r = new_gist(
File.basename(path),
f.read
)
r = JSON.parse(r)
if r["html_url"]
puts r["html_url"]
else
puts r
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment