API仕様
とりあえず、一覧表示APIの仕様だけ掲載します。callbackを指定すると、JSONPとしても使えます。その他のAPIの仕様については、Open Beer Databaseのページで調べてください。
http://api.openbeerdatabase.com/v1/beers.json?callback=コールバック名
レスポンス例
うぉーまじでデータが返ってきたよー。しかも大量に...。レスポンスに含まれるbreweryとは、醸造所のことらしい、メーカーね。日本のビールもあるのかなぁ。ちなみに私はAsahiのMasterやレーベンシュタインというビールが好き。
{
"page":1,
"pages":2,
"total":73,
"beers":[
{
"id":1,"name":"(512) ALT",
"description":"A German-style amber ale that is fermented cooler than typical ales and cold conditioned like a lager. ALT means \"old\" in German and refers to a beer style made using ale yeast after many German brewers had switched to newly discovered lager yeast. This ale has a very smooth, yet pronounced, hop bitterness with a malty backbone and a characteristic German yeast character. Made with 98% organic two-row and Munich malts and US noble hops.",
"abv":6.0,
"created_at":"2010-12-07T02:53:38Z",
"updated_at":"2010-12-07T02:53:38Z",
"brewery":{
"id":1,
"name":"(512) Brewing Company"
}
},
{
"id":2,
"name":"(512) Bruin",
...
]
}
JavaScriptのサンプル
JSONPで表示するサンプルを作ってみました。<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$('#btn').click(function() {
var $this = $(this);
$.getJSON('http://api.openbeerdatabase.com/v1/beers.json?callback=?', {}, function(json) {
for (var i = 0; i < json.beers.length; i++) {
$('<li><b>'+json.beers[i].name+'</b> - ' + json.beers[i].description +'</li>').appendTo('#beers');
}
})
});
});
</script>
</head>
<body>
<div>
<button id="btn">Click</button>
<ul id="beers">
</ul>
</div>
</body>
</html>
こんな感じでたくさん表示されます。このビールのデータベースですが、更新・削除などもAPI経由で実現できるみたいです。要は、共有データベースみたいなものなんでしょうが、削除とか怖くないんだろうかー。
まとめ
ビールはともかく、ワインのAPIとかも探せばあるかもしれませんね。ワインの方が需要がありそうー。また、時間があればワインのAPIも探してみます。お約束ですが、アルコールは二十歳を過ぎてから。
0 件のコメント:
コメントを投稿