2014-04-03 67 views
0

我必須從提供的外部API中使用方法,而一種方法是使用json主體的GET方法。我通過使用rest-client gem來完成這項工作的軌道進行連接。使用json主體的GET方法

我知道RestClient.post接受JSON:

RestClient.post "http://example.com/resource", { 'x' => 1 }.to_json, :content_type => :json, :accept => :json 

,也爲我的情況下完美的作品。但是,如果我改變對.post的不用彷徨,我得到這個錯誤:

ArgumentError: wrong number of arguments (3 for 2) 
from /Users/toptierlabs/.rvm/gems/[email protected]/gems/rest-client-1.6.7/lib/restclient.rb:67:in `get' 
from /Users/toptierlabs/Desktop/Proyectos/AppraisalLane/app/models/autoniq.rb:8:in `getCircleInventory' 
from (irb):3 
from /Users/toptierlabs/.rvm/gems/[email protected]/gems/railties-4.0.2/lib/rails/commands/console.rb:90:in `start' 
from /Users/toptierlabs/.rvm/gems/[email protected]/gems/railties-4.0.2/lib/rails/commands/console.rb:9:in `start' 
from /Users/toptierlabs/.rvm/gems/[email protected]/gems/railties-4.0.2/lib/rails/commands.rb:62:in `<top (required)>' 
from bin/rails:4:in `require' 
from bin/rails:4:in `<main>' 

是否有Rails的任何方式做一個JSON身體得到什麼?或者任何可能的解決方案將「用json身體獲取」轉換爲其他東西?沒有必要使用剩餘客戶端的寶石,如果任何人有其他解決方案也是受歡迎的。

謝謝!

回答