gpt4 book ai didi

ruby - 从 Ruby 脚本创建 Gist

转载 作者:太空宇宙 更新时间:2023-11-03 16:04:53 25 4
gpt4 key购买 nike

有没有办法使用 net/httpnet/https 创建匿名(公共(public)或私有(private))要点?

最佳答案

这对我有用。

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

结果:My test gist

关于ruby - 从 Ruby 脚本创建 Gist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16365553/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com