2016-12-24 31 views
0

我試圖使用gist API作爲臨時差異工具。要做到這一點,我想上傳一些文本到要點,然後更新它並查看差異。由於某種原因,我得到了 "{\"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 

回答

0

second_req = Net::HTTP::Patch.new(second_uri.path)的伎倆