gpt4 book ai didi

ruby-on-rails - 在 ruby​​ 中执行 curl 命令

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

谁能告诉我如何用ruby写这个命令

curl -i -u USERNAME https://api.github.com/repos/USERNAME/REPOSITORY/forks

最佳答案

你可以用 Hurley 做到这一点.

首先安装gem:

$ gem install hurley

然后运行这个:

require "hurley"
require "json"

client = Hurley::Client.new "https://api.github.com"

repository = {
username: "repo_username",
name: "repo_name",
}

authentication = {
username: "XXX",
password: "YYY",
}

response = client.get("/repos/#{repository[:username]}/#{repository[:name]}/forks") do |req|
req.header[:accept] = "application/vnd.github.preview+json"
req.url.user = authentication[:username]
req.url.password = authentication[:password]
end

puts JSON.parse(response.body)

关于ruby-on-rails - 在 ruby​​ 中执行 curl 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33232053/

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