0

我有另一个提供 RESTful JSON API 的 rails 应用程序。我可以通过下面的 curl 请求测试响应(您还可以看到它返回的第一个项目的示例)。

我可以弄清楚如何从较大的响应中提取某些项目。我只是不确定我应该如何在将其呈现给客户端的 rails 应用程序上提供响应。

我假设我需要将其保存在某种类别中。我可以使用卷曲吗?我对rails非常熟悉,非常感谢任何帮助。

谢谢!

curl "http://api.foobar.com/stuff/stuff_name/catalog_items.json" -H "X-Api-Key: georgesbush"

它返回一组不错的 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
    }
}
4

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:

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
于 2013-04-28T04:05:36.463 回答