--- title: rfc.jsonを使ってみる author: kazu634 date: 2010-12-23 wordtwit_post_info: - 'O:8:"stdClass":13:{s:6:"manual";b:0;s:11:"tweet_times";i:1;s:5:"delay";i:0;s:7:"enabled";i:1;s:10:"separation";s:2:"60";s:7:"version";s:3:"3.7";s:14:"tweet_template";b:0;s:6:"status";i:2;s:6:"result";a:0:{}s:13:"tweet_counter";i:2;s:13:"tweet_log_ids";a:1:{i:0;i:5401;}s:9:"hash_tags";a:0:{}s:8:"accounts";a:1:{i:0;s:7:"kazu634";}}' categories: - gauche ---

Gauche の新機能検証をしているように見えますが、単純に Foursquare API を利用するスクリプトを作っているんです。たまたま最新バージョンで HTTPS 接続や、 json が利用出来るようになっているだけでして。。。

rfc.json、使い方はとても簡単でした:

gosh> (use rfc.json)
#<undef>
gosh> (receive (status header body)
(http-get "api.foursquare.com"
(string-append
"/v2/users/self/checkins?oauth_token="
"私の oauth_token"
"&limit=3")
:secure #t)
(parse-json-string body))
(("meta" ("code" . 200)) ("response" ("checkins" ("count" . 1963) ("items" . #((("id" . "4d12f47c37f1236aaafd7d1b") ("createdAt" . 1293087868) ("type" . "checkin") ("shout" . "勉強してます。") ("isMayor" . true) ("venue" ("id" . "4c131b17b7b9c9280320a937") ("name" . "STICK SWEETS FACTORY サクラス戸塚店") ("contact" ("phone" . "0458654511")) ("location" ("address" . "戸塚町4253-1") ("city" . "横浜市戸塚区") ("state" . "神奈川県") ("postalCode" . "244-0003") ("lat" . 35.40073452467999) ("lng" . 139.53113079071045)) ("categories" . #((("id" . "4bf58dd8d48988d16d941735") ("name" . "Caf&#233;") ("icon" . "http://foursquare.com/img/categories/food/cafe.png") ("parents" . #("Food")) ("primary" . true)))) ("verified" . false) ("stats" ("checkinsCount" . 32) ("usersCount" . 4)) ("todos" ("count" . )))) (("id" . "4d12d45c2e5837042a87e7d1") ("createdAt" . 1293079644) ("type" . "checkin") ("isMayor" . true) ("venue" ("id" . "4b497967f964a520497026e3") ("name" . "有隣堂 戸塚モディ店") ("contact" ("phone" . "0458812661")) ("location" ("address" . "戸塚町10") ("crossStreet" . "戸塚モディ 4階") ("city" . "横浜市戸塚区") ("state" . "神奈川県") ("postalCode" . "244-0003") ("lat" . 35.40139479158353) ("lng" . 139.5345962047577)) ("categories" . #((("id" . "4bf58dd8d48988d114951735") ("name" . "Bookstore") ("icon" . "http://foursquare.com/img/categories/shops/bookstore.png") ("parents" . #("Shops")) ("primary" . true)))) ("verified" . false) ("stats" ("checkinsCount" . 202) ("usersCount" . 47)) ("todos" ("count" . )))) (("id" . "4d11f486d1848cfa79f1b771") ("createdAt" . 1293022342) ("type" . "checkin") ("venue" ("id" . "4b0e60adf964a520305723e3") ("name" . "品川駅 (Shinagawa Sta.)") ("contact") ("location" ("address" . "高輪3 / 港南2") ("city" . "港区") ("state" . "東京都") ("lat" . 35.62866325853653) ("lng" . 139.73909854888916)) ("categories" . #((("id" . "4bf58dd8d48988d129951735") ("name" . "Train Station") ("icon" . "http://foursquare.com/img/categories/travel/trainstation.png") ("parents" . #("Travel")) ("primary" . true)) (("id" . "4bf58dd8d48988d1fd931735") ("name" . "Subway") ("icon" . "http://foursquare.com/img/categories/travel/subway.png") ("parents" . #("Travel"))))) ("verified" . false) ("stats" ("checkinsCount" . 48244) ("usersCount" . 9210)) ("todos"
("count" . )))))))))

XMLの場合だと、 XPATH を指定することで簡単に任意の場所からのS式を切り出せたけど、この場合は自分で切り出すしか無いのかな?こんな感じかな?

(assoc "items"
(assoc "checkins"
(assoc "response"
*json-response*)))

面倒くさい気がする。