【问题标题】:Can't update a gist immediately after creating it创建要点后无法立即更新它
【发布时间】:2017-05-09 19:27:46
【问题描述】:

我正在尝试将 gist API 用作临时差异工具。为此,我想将一些文本上传到 gist,然后对其进行更新并查看差异。出于某种原因,我得到 "{\"message\":\"Not Found\",\"documentation_url\":\"https://developer.github.com/v3\"}" 结果。它有点令人困惑,因为当我查看网址时,我可以看到 GIST 很好。

我的代码如下

uri = URI("https://api.github.com/gists")

first_payload = {
    'description' => "My test gist",
    'public' => true,
    'files' => {
        'change.yml' => {
            'content' => "before"
        }
    }
}

req = Net::HTTP::Post.new(uri.path)
req.body = first_payload.to_json
req.basic_auth("username", "password")
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => true) do |http|
  http.request(req)
end

second_uri = URI(JSON.parse(res.body)["url"])
second_payload = {
    'description' => "My test gist",
    'public' => true,
    'files' => {
        'change.yml' => {
            'content' => ':after'
        }
    }
}

second_req = Net::HTTP::Put.new(second_uri.path)
second_req.body = second_payload.to_json
second_req.basic_auth("username", "password")
second_res = Net::HTTP.start(second_uri.hostname, second_uri.port, :use_ssl => true) do |http|
  http.request(second_req)
end

【问题讨论】:

    标签: ruby-on-rails ruby github gist


    【解决方案1】:

    second_req = Net::HTTP::Patch.new(second_uri.path) 成功了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-03
      • 1970-01-01
      • 2013-05-29
      • 1970-01-01
      • 2019-08-16
      • 1970-01-01
      相关资源
      最近更新 更多