Hubot でねこ Vine を拾ってきてチームに癒しをもたらす


## コード

```tabi.coffee
module.exports = (robot) ->
  robot.respond /(tabi|たび|(癒|いや)し)/i, (msg) ->
    robot.http("https://api.vineapp.com/timelines/users/1038468495395958784") # ざわちゃんのuserid
      .get() (err, res, body) ->
        records = JSON.parse(body)['data']['records']
        tabis = []
        for record in records
          # ざわちゃんは複数タグつけないと思うので配列0ハードで
          # https://twitter.com/shelf703/status/616130432418095104
          if record.entities[0]?.id == 1138830969860853760 # tag"#たび"のid
            tabis.push(record.shareUrl)
        msg.send msg.random tabis
```


## 解説・過程

### 癒しコンテンツ

癒しの代名詞である、ねこ:cat2:優良コンテンツ配信元としてチーム内に心当たり
https://vine.co/u/1038468495395958784


### api があるらしいので curl で叩いてみる

```
$ curl -s https://api.vineapp.com/timelines/users/1038468495395958784 -X GET | python -mjson.tool
{
    "code": "",
    "data": {
        "anchor": 1199308322436804608,
        "anchorStr": "1199308322436804608",
        "backAnchor": "1217408396299509760",
        "count": 79,
        "nextPage": 2,
        "previousPage": null,
        "records": [
            {
                "avatarUrl": "http://v.cdn.vine.co/r/avatars/38C93AC8CA1038468503772205056_137eac0d903.4.7_v2Cn1oY3wssbcjsNYX_DhPB1eMqHWaUvVf03oJPqQo4n4nj.SA5VFlyKagUaXSMo.jpg?versionId=b1s9TFAblLwdBQ8oUCd93UQLTyFE28Ep",
                "blocked": 0,
                "comments": {
                    "anchor": null,
                    "anchorStr": null,
                    "backAnchor": "",
                    "count": 0,
                    "nextPage": null,
                    "previousPage": null,
                    "records": [],
                    "size": 10
                },
                "created": "2015-06-02T06:36:34.000000",
                "description": "#\u305f\u3073",
                "entities": [
                    {
                        "id": 1138830969860853760,
                        "link": "vine://tag/%E3%81%9F%E3%81%B3",
                        "range": [
                            0,
                            3
                        ],
                        "title": "\u305f\u3073",
                        "type": "tag"
                    }
                ],
                "explicitContent": 0,
                "followRequested": 0,
                "following": 0,
                "foursquareVenueId": null,
                "liked": 0,
                "likes": {
                    "anchor": null,
                    "anchorStr": null,
                    "backAnchor": "",
                    "count": 0,
                    "nextPage": null,
                    "previousPage": null,
                    "records": [],
                    "size": 10
                },
                "loops": {
                    "count": 76.0,
                    "onFire": 0,
                    "velocity": 0.0
                },
                "myRepostId": 0,
                "permalinkUrl": "https://vine.co/v/ehppuW2Xvpa",
                "postId": 1217408396299509760,
                "private": 0,
                "profileBackground": "0x33ccbf",
                "promoted": 0,
                "reposts": {
                    "anchor": 0,
                    "anchorStr": "0",
                    "backAnchor": "",
                    "count": 0,
                    "nextPage": null,
                    "previousPage": null,
                    "records": [],
                    "size": 10
                },
                "shareUrl": "https://vine.co/v/ehppuW2Xvpa",
                "tags": [],
                "thumbnailUrl": "http://v.cdn.vine.co/r/videos/368B21E1961217408385885585408_3e75c67fd9e.3.3.2180569995895087565.mp4.jpg?versionId=J6EwcuLJSRmMUqyRXEACHtniepQuIY6F",
                "userId": 1038468495395958784,
                "username": "shelf",
                "vanityUrls": [],
                "verified": 0,
                "videoDashUrl": "http://mtc.cdn.vine.co/r/videos_h264dash/368B21E1961217408385885585408_3e75c67fd9e.3.3.2180569995895087565.mp4?versionId=QwED.ccJfew_pzNVFXP_Y6cYqqQ7o5OK",
                "videoLowURL": "http://mtc.cdn.vine.co/r/videos_r2/368B21E1961217408385885585408_3e75c67fd9e.3.3.2180569995895087565.mp4?versionId=tZ4bk3a6uZN2mO_MvrkZ_o4mQ6vVLmCU",
                "videoUrl": "http://mtc.cdn.vine.co/r/videos/368B21E1961217408385885585408_3e75c67fd9e.3.3.2180569995895087565.mp4?versionId=GLPtLJkrq45ThrdxqsgUyzS.CY1C1jJk",
                "videoWebmUrl": null
            },
            // 省略
        ],
        "size": 10
    },
    "error": "",
    "success": true
}

```

日本語がUnicode hiraganaだ。
タグにidが振られているらしく、 `data.records[].entities[].id` に書いてある。
`#たび` は `1138830969860853760`だった。



## 動機・感想

![Slack 2015-07-02 16-03-05.png](https://qiita-image-store.s3.amazonaws.com/0/21888/88787a35-da62-2234-156f-3d64b3e98539.png "Slack 2015-07-02 16-03-05.png")

![Slack 2015-07-01 06-30-20.png](https://qiita-image-store.s3.amazonaws.com/0/21888/796a93e8-bda7-2790-a500-65b840fac059.png "Slack 2015-07-01 06-30-20.png")

bot育てるの楽しすぎて本プロダクトの開発に影響しかねないの、恐ろしすぎる。
きちんとタグをつけているざわ、とても偉い。


## 参考

* [Hubot | 自作Script | Hubot で 「フォト蔵」API の結果を取得する - Qiita](http://qiita.com/tbpgr/items/0a7b989b10e742256033)
* [Vineの非公式APIの使い方まとめ (サンプルコード付き)](http://syncer.jp/vine-api-matome)
* [hubot/scripting.md at master · github/hubot](https://github.com/github/hubot/blob/master/docs/scripting.md#making-http-calls)
* [コマンドラインからjsonを見やすく表示する - Qiita](http://qiita.com/pugiemonn/items/731c33e8cd8ccc6a6c4c)