blog/content/post/2010/12/23/2010-12-23-00001440.md

50 lines
18 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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