stMind

about Tech, Computer vision and Machine learning

RILで既読数の取得にstats APIを使う

前回、stateがreadのitemを全部取得して既読数を計算したが、未読数や既読数などの統計情報を取得するためのAPIがあったので、それを使うように変更した。

stats API

  • Method URL
  • Parameters (GET or POST)
    • apikey
      • 必須
    • username
      • 必須
    • password
      • 必須
    • format
https://readitlaterlist.com/v2/stats?username=name&password=123&apikey=yourapikey

こうなりました

commit cf11ea436b55c97372c809005bd198338ce2fc5b
Author: satojkovic <satojkovic@gmail.com>
Date:   Fri Mar 23 01:26:22 2012 +0900

    use stats API

diff --git a/read_get.pl b/read_get.pl
index 8cf35ce..bfefb20 100644
--- a/read_get.pl
+++ b/read_get.pl
@@ -13,7 +13,7 @@ my $conf = pit_get("readitlater.com", require => {
 });
 
 my $service = WebService::Simple->new(
-    base_url => 'https://readitlaterlist.com/v2/get',
+    base_url => 'https://readitlaterlist.com/v2/',
     param => { apikey => "$conf->{APIKey}",
                username => "$conf->{username}",
                password => "$conf->{password}"
@@ -21,8 +21,10 @@ my $service = WebService::Simple->new(
     response_parser => 'JSON'
 );
 
-my $res = $service->get( { state => 'read' } );
+my $res = $service->get( "stats" );
 my $json = $res->parse_response;
-my $read_num = keys $json->{list};
-print "Read $read_num items.\n";
+
+print "count_list : $json->{count_list}\n";
+print "count_unread : $json->{count_unread}\n";
+print "count_read : $json->{count_read}\n";