LoginSignup
13
15

More than 5 years have passed since last update.

annict.jsドキュメント

Last updated at Posted at 2016-06-13

annict.js npm version Bower version

アニメ視聴記録サービスAnnictのAPIクライアントライブラリ、annict.jsのドキュメントです。
» リファレンスドキュメントはこちら

はじめに

annict.jsはアニメ視聴記録サービスAnnictのAPIをNode.jsから利用するためのクライアントライブラリです。
APIの仕様については公式ドキュメントを参照してください。

インストール

Node, webpack, browserify

npm install annict --save
var Annict = require('annict').default;
var annict = new Annict();

ブラウザ

bower install annict --save
<body>
    <script type='text/javascript'>
        var access_token = '[アクセストークン]'; //サーバ側で埋め込む
    </script>

    ...

    <script type='text/javascript' src='/js/annict.min.js'></script>
    <script type='text/javascript'>
        var annict = new Annict();
        ...
    </script>
</body>

API

各APIにアクセスする方法です。
一部APIは書き込み権限を必要としますので/oauth/token/infoを利用してトークンがwriteスコープを持っているか確認してください。

認証

アプリケーションに対して認可を行い、アクセストークンを取得します。
Annict APIはOAuth 2.0に基づいて認可を行います。

認証ページへのリダイレクト

※ このメソッドはNode.jsではサポートしていません

annict.OAuth.authorize(
    client_id    : CLIENT_ID,
    response_type: 'code',
    redirect_uri : 'urn:ietf:wg:oauth:2.0:oob',
    scope        : ['read', 'write'] 
);

アクセストークンの取得

※ このメソッドはブラウザではサポートしていません

annict.OAuth.token(
    process.env.CLIENT_ID,       // client_id
    process.env.CLIENT_SECRET,   // client_secret
    'authorization_code',        // grant_type
    'urn:ietf:wg:oauth:2.0:oob', // redirect_uri
    CODE // https://api.annict.com/oauth/authorizeで取得したコード
)
.then(token => {
    annict.client.setHeader('Authorization', `Bearer ${token.access_token}`);
});

トークン情報の取得

annict.OAuth.info()
.then(info => {
    console.log(info.scopes); //=> ['read', 'write']
});

トークンを失効させる

annict.OAuth.revoke(token)
.then(console.log); //=> {}

作品検索

Annictデータベースに登録されているアニメ作品の検索ができます。

annict.Work.get({
    fileter_title: 'shirobako'
})
.then(res => {
    console.log(res.works);
});

エピソード検索

作品のエピソード情報を取得することもできます。

annict.Episode.get({
    filter_ids: [1,2,3]
})
.then(res => {
    console.log(res.episodes);
});

ユーザ

ユーザAPIでは認証ユーザに関連づく情報を取得します。
他のAnnictユーザの検索などはおそらくできません。

ステータス更新

このAPIを利用するにはwriteスコープを持っているトークンが必要です。

/**
 * kind := 'wanna_watch' 
 * | 'watching'
 * | 'watched'
 * | 'on_hold'
 * | 'stop_watching'
 * | 'no_select'
 */

annict.Me.Status.create({ work_id: 4636, kind: 'watching' })
.then(res => console.log(res.status)); //=> 204

記録

me/records APIでは以下の操作が可能です。
自分の記録の取得は通常の /records APIにfilterをかけることで可能です。

  • 新規記録の作成
  • 記録の更新
  • 記録の削除
// 記録の作成
annict.Me.Record.create({
    episode_id     : 5013,
    comment        :'あぁ^~心がぴょんぴょんするんじゃぁ^~',
    share_twitter  :'true',
    share_facebook :'false'
})
.then(res => console.log(res.id)); //=> 1016


// 記録の更新
annict.Me.Record.update({
    id             : 1016,
    rating         : 5.0,
})
.then(res => console.log(res.rating)); //=> 5.0


// 記録の削除
annict.Me.Record.delete( 1016 )
.then(res => console.log(res.status)); //=> 204

作品取得

ユーザに関連する作品を取得することができます。例えば今視聴中の作品一覧を取得する場合は次のようになります。

annict.Me.Work.get({
    filter_status: 'watching'
})
.then(res => {
    console.log(res.works);
});

放送予定取得

放送予定を取得することができます。

annict.Me.Program.get({
    sort_started_at: 'desc',
    filter_started_at_gt: '2016/05/05 02:00'
})
.then(res => {
    console.log(res.programs);
});
13
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
15