50 lines
19 KiB
Markdown
50 lines
19 KiB
Markdown
---
|
||
title: rfc.jsonを使ってみる
|
||
author: kazu634
|
||
date: 2010-12-23
|
||
url: /2010/12/23/_1644/
|
||
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
|
||
|
||
---
|
||
<div class="section">
|
||
<p>
|
||
Gauche の新機能検証をしているように見えますが、単純に Foursquare API を利用するスクリプトを作っているんです。たまたま最新バージョンで HTTPS 接続や、 json が利用出来るようになっているだけでして。。。
|
||
</p>
|
||
|
||
<p>
|
||
rfc.json、使い方はとても簡単でした:
|
||
</p>
|
||
|
||
<pre class="syntax-highlight">
|
||
gosh> <span class="synSpecial">(</span>use rfc.json<span class="synSpecial">)</span>
|
||
#<undef>
|
||
gosh> <span class="synSpecial">(</span>receive <span class="synSpecial">(</span>status header body<span class="synSpecial">)</span>
|
||
<span class="synSpecial">(</span>http-get <span class="synConstant">"api.foursquare.com"</span>
|
||
<span class="synSpecial">(</span>string-append
|
||
<span class="synConstant">"/v2/users/self/checkins?oauth_token="</span>
|
||
<span class="synConstant">"私の oauth_token"</span>
|
||
<span class="synConstant">"&limit=3"</span><span class="synSpecial">)</span>
|
||
:secure #t<span class="synSpecial">)</span>
|
||
<span class="synSpecial">(</span>parse-json-string body<span class="synSpecial">))</span>
|
||
<span class="synSpecial">((</span><span class="synConstant">"meta"</span> <span class="synSpecial">(</span><span class="synConstant">"code"</span><span class="synStatement"> . </span><span class="synConstant">200</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"response"</span> <span class="synSpecial">(</span><span class="synConstant">"checkins"</span> <span class="synSpecial">(</span><span class="synConstant">"count"</span><span class="synStatement"> . </span><span class="synConstant">1963</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"items"</span><span class="synStatement"> . </span>#<span class="synSpecial">(((</span><span class="synConstant">"id"</span><span class="synStatement"> . </span><span class="synConstant">"4d12f47c37f1236aaafd7d1b"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"createdAt"</span><span class="synStatement"> . </span><span class="synConstant">1293087868</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"type"</span><span class="synStatement"> . </span><span class="synConstant">"checkin"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"shout"</span><span class="synStatement"> . </span><span class="synConstant">"勉強してます。"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"isMayor"</span><span class="synStatement"> . </span>true<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"venue"</span> <span class="synSpecial">(</span><span class="synConstant">"id"</span><span class="synStatement"> . </span><span class="synConstant">"4c131b17b7b9c9280320a937"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"name"</span><span class="synStatement"> . </span><span class="synConstant">"STICK SWEETS FACTORY サクラス戸塚店"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"contact"</span> <span class="synSpecial">(</span><span class="synConstant">"phone"</span><span class="synStatement"> . </span><span class="synConstant">"0458654511"</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"location"</span> <span class="synSpecial">(</span><span class="synConstant">"address"</span><span class="synStatement"> . </span><span class="synConstant">"戸塚町4253-1"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"city"</span><span class="synStatement"> . </span><span class="synConstant">"横浜市戸塚区"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"state"</span><span class="synStatement"> . </span><span class="synConstant">"神奈川県"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"postalCode"</span><span class="synStatement"> . </span><span class="synConstant">"244-0003"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"lat"</span><span class="synStatement"> . </span><span class="synConstant">35.40073452467999</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"lng"</span><span class="synStatement"> . </span><span class="synConstant">139.53113079071045</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"categories"</span><span class="synStatement"> . </span>#<span class="synSpecial">(((</span><span class="synConstant">"id"</span><span class="synStatement"> . </span><span class="synConstant">"4bf58dd8d48988d16d941735"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"name"</span><span class="synStatement"> . </span><span class="synConstant">"Caf&#233;"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"icon"</span><span class="synStatement"> . </span><span class="synConstant">"http://foursquare.com/img/categories/food/cafe.png"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"parents"</span><span class="synStatement"> . </span>#<span class="synSpecial">(</span><span class="synConstant">"Food"</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"primary"</span><span class="synStatement"> . </span>true<span class="synSpecial">))))</span> <span class="synSpecial">(</span><span class="synConstant">"verified"</span><span class="synStatement"> . </span>false<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"stats"</span> <span class="synSpecial">(</span><span class="synConstant">"checkinsCount"</span><span class="synStatement"> . </span><span class="synConstant">32</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"usersCount"</span><span class="synStatement"> . </span><span class="synConstant">4</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"todos"</span> <span class="synSpecial">(</span><span class="synConstant">"count"</span><span class="synStatement"> . </span><span class="synConstant"></span><span class="synSpecial">))))</span> <span class="synSpecial">((</span><span class="synConstant">"id"</span><span class="synStatement"> . </span><span class="synConstant">"4d12d45c2e5837042a87e7d1"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"createdAt"</span><span class="synStatement"> . </span><span class="synConstant">1293079644</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"type"</span><span class="synStatement"> . </span><span class="synConstant">"checkin"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"isMayor"</span><span class="synStatement"> . </span>true<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"venue"</span> <span class="synSpecial">(</span><span class="synConstant">"id"</span><span class="synStatement"> . </span><span class="synConstant">"4b497967f964a520497026e3"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"name"</span><span class="synStatement"> . </span><span class="synConstant">"有隣堂 戸塚モディ店"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"contact"</span> <span class="synSpecial">(</span><span class="synConstant">"phone"</span><span class="synStatement"> . </span><span class="synConstant">"0458812661"</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"location"</span> <span class="synSpecial">(</span><span class="synConstant">"address"</span><span class="synStatement"> . </span><span class="synConstant">"戸塚町10"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"crossStreet"</span><span class="synStatement"> . </span><span class="synConstant">"戸塚モディ 4階"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"city"</span><span class="synStatement"> . <span class="synConstant">"横浜市戸塚区"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"state"</span><span class="synStatement"> . </span><span class="synConstant">"神奈川県"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"postalCode"</span><span class="synStatement"> . </span><span class="synConstant">"244-0003"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"lat"</span><span class="synStatement"> . </span><span class="synConstant">35.40139479158353</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"lng"</span><span class="synStatement"> . </span><span class="synConstant">139.5345962047577</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"categories"</span><span class="synStatement"> . </span>#<span class="synSpecial">(((</span><span class="synConstant">"id"</span><span class="synStatement"> . </span><span class="synConstant">"4bf58dd8d48988d114951735"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"name"</span><span class="synStatement"> . </span><span class="synConstant">"Bookstore"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"icon"</span><span class="synStatement"> . </span><span class="synConstant">"http://foursquare.com/img/categories/shops/bookstore.png"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"parents"</span><span class="synStatement"> . </span>#<span class="synSpecial">(</span><span class="synConstant">"Shops"</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"primary"</span><span class="synStatement"> . </span>true<span class="synSpecial">))))</span> <span class="synSpecial">(</span><span class="synConstant">"verified"</span><span class="synStatement"> . </span>false<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"stats"</span> <span class="synSpecial">(</span><span class="synConstant">"checkinsCount"</span><span class="synStatement"> . </span><span class="synConstant">202</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"usersCount"</span><span class="synStatement"> . </span><span class="synConstant">47</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"todos"</span> <span class="synSpecial">(</span><span class="synConstant">"count"</span><span class="synStatement"> . </span><span class="synConstant"></span><span class="synSpecial">))))</span> <span class="synSpecial">((</span><span class="synConstant">"id"</span><span class="synStatement"> . </span><span class="synConstant">"4d11f486d1848cfa79f1b771"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"createdAt"</span><span class="synStatement"> . </span><span class="synConstant">1293022342</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"type"</span><span class="synStatement"> . </span><span class="synConstant">"checkin"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"venue"</span> <span class="synSpecial">(</span><span class="synConstant">"id"</span><span class="synStatement"> . </span><span class="synConstant">"4b0e60adf964a520305723e3"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"name"</span><span class="synStatement"> . </span><span class="synConstant">"品川駅 (Shinagawa Sta.)"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"contact"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"location"</span> <span class="synSpecial">(</span><span class="synConstant">"address"</span><span class="synStatement"> . </span><span class="synConstant">"高輪3 / 港南2"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"city"</span><span class="synStatement"> . </span><span class="synConstant">"港区"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"state"</span><span class="synStatement"> . </span><span class="synConstant">"東京都"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"lat"</span><span class="synStatement"> . </span><span class="synConstant">35.62866325853653</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"lng"</span><span class="synStatement"> . </span><span class="synConstant">139.73909854888916</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"categories"</span><span class="synStatement"> . </span>#<span class="synSpecial">(((</span><span class="synConstant">"id"</span><span class="synStatement"> . </span><span class="synConstant">"4bf58dd8d48988d129951735"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"name"</span><span class="synStatement"> . </span><span class="synConstant">"Train Station"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"icon"</span><span class="synStatement"> . </span><span class="synConstant">"http://foursquare.com/img/categories/travel/trainstation.png"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"parents"</span><span class="synStatement"> . </span>#<span class="synSpecial">(</span><span class="synConstant">"Travel"</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"primary"</span><span class="synStatement"> . </span>true<span class="synSpecial">))</span> <span class="synSpecial">((</span><span class="synConstant">"id"</span><span class="synStatement"> . </span><span class="synConstant">"4bf58dd8d48988d1fd931735"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"name"</span><span class="synStatement"> . </span><span class="synConstant">"Subway"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"icon"</span><span class="synStatement"> . </span><span class="synConstant">"http://foursquare.com/img/categories/travel/subway.png"</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"parents"</span><span class="synStatement"> . </span>#<span class="synSpecial">(</span><span class="synConstant">"Travel"</span><span class="synSpecial">)))))</span> <span class="synSpecial">(</span><span class="synConstant">"verified"</span><span class="synStatement"> . </span>false<span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"stats"</span> <span class="synSpecial">(</span><span class="synConstant">"checkinsCount"</span><span class="synStatement"> . </span><span class="synConstant">48244</span><span class="synSpecial">)</span> <span class="synSpecial">(</span><span class="synConstant">"usersCount"</span><span class="synStatement"> . </span><span class="synConstant">9210</span><span class="synSpecial">))</span> <span class="synSpecial">(</span><span class="synConstant">"todos"</span>
|
||
<span class="synSpecial">(</span><span class="synConstant">"count"</span><span class="synStatement"> . </span><span class="synConstant"></span><span class="synSpecial">)))))))))</span>
|
||
</span></pre>
|
||
|
||
<p>
|
||
XMLの場合だと、 XPATH を指定することで簡単に任意の場所からのS式を切り出せたけど、この場合は自分で切り出すしか無いのかな?こんな感じかな?
|
||
</p>
|
||
|
||
<pre class="syntax-highlight">
|
||
<span class="synSpecial">(</span><span class="synStatement">assoc</span> <span class="synConstant">"items"</span>
|
||
<span class="synSpecial">(</span><span class="synStatement">assoc</span> <span class="synConstant">"checkins"</span>
|
||
<span class="synSpecial">(</span><span class="synStatement">assoc</span> <span class="synConstant">"response"</span>
|
||
<span class="synType">*json-response*</span><span class="synSpecial">)))</span>
|
||
</pre>
|
||
|
||
<p>
|
||
面倒くさい気がする。
|
||
</p>
|
||
</div> |