2014-12-13 56 views
1

我正在嘗試使用Github API在回購庫中創建文件。使用Github API與其他客戶端創建文件

這curl命令不正是我想做的事:

curl -X PUT -H 'Authorization: token <TOKEN>' -d '{"path": "test.txt", "message": "Test Commit", "committer": {"name": "Kevin Clark", "email": "[email protected]"}, "content": "bXkgbmV3IGZpbGUgY29udGVudHM="}' https://api.github.com/repos/vernalkick/kevinclark/contents/test.txt

我需要做的紅寶石同樣的請求,但使用rest_client,但這返回404:

require 'rest_client' 

params = { 
    :path => "test.txt", 
    :message => "Test Commit", 
    :committer => { 
    :name => "Kevin Clark", 
    :email => "[email protected]" 
    }, 
    :content => "bXkgbmV3IGZpbGUgY29udGVudHM=", 
    :access_token => <TOKEN> 
} 

RestClient.put "https://api.github.com/repos/vernalkick/kevinclark/contents/test.txt", :params => params 

Github的文檔:https://developer.github.com/v3/repos/contents/

回答

4

所以我終於找到了解決我的問題!

我需要創建一個json字符串,而不是僅傳遞散列。

RestClient.put "https://api.github.com/repos/vernalkick/kevinclark/contents/test.txt", :params => JSON.generate(params) 
相關問題