I have another rails app serving up a RESTful JSON API. I'm able to test the response via the curl request below (you can also see an example of the first item it returns).
我有另一个rails应用程序提供RESTful JSON API。我可以通过下面的curl请求来测试响应(您还可以看到它返回的第一个项的示例)。
I can figure out how to extract certain items from the larger response. I'm just not sure how I should serve the response on the rails app that will render this to the client.
我可以找出如何从较大的响应中提取某些项。我只是不确定如何在rails应用程序上提供响应,以便将其呈现给客户端。
I'd assume I need to save this is in a class of some sort. Can i use curl? I'm very green with rails, and would very much apreciate any help.
我假设我需要把它保存在某个类中。我可以用卷发吗?我对rails一窍不通,非常感谢您的帮助。
THANKS!
谢谢!
curl "http://api.foobar.com/stuff/stuff_name/catalog_items.json" -H "X-Api-Key: georgesbush"
Which returns a nice set of JSON Data.
返回一组漂亮的JSON数据。
{
"data": {
"catalog_items": [
{
"current_price": "9999.0",
"close_date": "2013-05-14T16:08:00-04:00",
"open_date": "2013-04-24T11:00:00-04:00",
"stuff_count": 82,
"minimum_price": "590000.0",
"id": 337478,
"estimated_price": "50000.0",
"name": "This is a really cool name",
"current_winner_id": 696969,
"images": [
{
"thumb_url": "http://foobar.com/images/93695/thumb.png?1365714300",
"detail_url": "http://foobar.com/images/93695/detail.png?1365714300",
"position": 1
},
{
"thumb_url": "http://foobar.com/images/95090/thumb.jpg?1366813823",
"detail_url": "http://foobar.com/images/95090/detail.jpg?1366813823",
"position": 2
}
]
}
]
},
"pagination": {
"per_page": 1,
"page": 1,
"total_pages": 131,
"total_objects": 131
}
}
1 个解决方案
#1
0
I went with the ruby curb library, wow, too easy. Added curb to my gem file, and the following code to my controller action:
我去了ruby语言库,哇,太简单了。在我的gem文件中添加了边框,下面的代码添加到我的控制器动作:
http = Curl.get("http://api.foobar.com/stuff/stuff_name/catalog_items.json?per_page=1&page=1") do|http|
http.headers['X-Api-Key'] = 'georgebush'
end
foobar = http.body_str
@foobar = ActiveSupport::JSON.decode(foobar ).symbolize_keys
#1
0
I went with the ruby curb library, wow, too easy. Added curb to my gem file, and the following code to my controller action:
我去了ruby语言库,哇,太简单了。在我的gem文件中添加了边框,下面的代码添加到我的控制器动作:
http = Curl.get("http://api.foobar.com/stuff/stuff_name/catalog_items.json?per_page=1&page=1") do|http|
http.headers['X-Api-Key'] = 'georgebush'
end
foobar = http.body_str
@foobar = ActiveSupport::JSON.decode(foobar ).symbolize_keys