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

50 lines
18 KiB
Markdown
Raw Normal View History

2019-03-31 11:00:21 +00:00
---
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="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>