| 1 | package WebService::Booklog; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | # ABSTRACT: Access to unofficial API of booklog.jp | ||||||||||||||||||||
| 7 | 3 | our $VERSION = 'v0.0.1'; # VERSION | |||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 3 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 3 | ▶ | use JSON::Any; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | sub new | ||||||||||||||||||||
| 13 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||
| 14 | 3 | my ($self) = @_; | |||||||||||||||||||
| 15 | 3 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||
|
Condition33%1/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table33%1/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||
| 16 | 3 | return bless { | |||||||||||||||||||
| 17 | _UA => LWP::UserAgent->new, | ||||||||||||||||||||
| 18 | }, $class; | ||||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 3 | my %status = ( | |||||||||||||||||||
| 22 | want_read => 1, | ||||||||||||||||||||
| 23 | reading => 2, | ||||||||||||||||||||
| 24 | read => 3, | ||||||||||||||||||||
| 25 | stacked => 4, | ||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | sub get_minishelf | ||||||||||||||||||||
| 29 | 3 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_minishelf: called CC=6 SCAR=20.5
Pod
documented
| |||||||||||||||||||||
| 30 | 3 | my ($self, $account, %arg) = @_; | |||||||||||||||||||
| 31 | 3 | my $data = {}; | |||||||||||||||||||
| 32 | 3 | ▶ | $data->{status} = $status{lc $arg{status}} if exists $arg{status}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 33 | 3 | foreach my $key (qw(category rank count)) { | |||||||||||||||||||
| 34 | 9 | ▶ | $data->{$key} = $arg{$key} if exists $arg{$key}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 35 | } | ||||||||||||||||||||
| 36 | 3 | my $param = join '&', map { $_.'='.$data->{$_} } keys %$data; | |||||||||||||||||||
| 37 | 3 | ▶ | $param = "?$param" if length $param; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 3 | my $ret = JSON::Any->from_json($self->{_UA}->get('http://api.booklog.jp/json/'.$account.$param)->content); | |||||||||||||||||||
| 39 | 0 | ▶ | $ret->{category} = {} if ref $ret->{category} eq 'ARRAY'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 0 | $ret->{books} = [ grep { ref $_ ne 'ARRAY' } @{$ret->{books}} ]; | |||||||||||||||||||
| 41 | 0 | return $ret; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | sub get_review | ||||||||||||||||||||
| 45 | 1 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_review: called CC=2 SCAR=11.6
Pod
documented
| |||||||||||||||||||||
| 46 | 1 | my ($self, $book_id) = @_; | |||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | my $ret = JSON::Any->from_json($self->{_UA}->get('http://booklog.jp/json/review/'.$book_id)->content); | |||||||||||||||||||
| 49 | 0 | ▶ | return $ret->{$book_id} if exists $ret->{$book_id}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | 0 | return; | |||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | sub get_shelf | ||||||||||||||||||||
| 54 | 4 | ▶ | { | ||||||||||||||||||
|
Subroutine
get_shelf: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||
| 55 | 4 | my ($self, $account, %arg) = @_; | |||||||||||||||||||
| 56 | 4 | my $data = {}; | |||||||||||||||||||
| 57 | 4 | ▶ | $data->{status} = $status{lc $arg{status}} if exists $arg{status}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 4 | ▶ | $data->{category_id} = $arg{category} if exists $arg{category}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 4 | foreach my $key (qw(sort rank tag genre page parpage keyword)) { | |||||||||||||||||||
| 60 | 28 | ▶ | $data->{$key} = $arg{$key} if exists $arg{$key}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | 4 | my $param = join '&', map { $_.'='.$data->{$_} } keys %$data; | |||||||||||||||||||
| 63 | 4 | my $ret = JSON::Any->from_json($self->{_UA}->get('http://booklog.jp/users_api/'.$account.'?'.$param)->content); | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | # Followings are not yet tested | ||||||||||||||||||||
| 67 | sub _login | ||||||||||||||||||||
| 68 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_login: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 69 | 0 | my ($self, $account, $password) = @_; | |||||||||||||||||||
| 70 | 0 | my $ret = $self->{_UA}->post('https://booklog.jp/login', { account => $account, password => $password }); | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | sub _logout | ||||||||||||||||||||
| 74 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_logout: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 75 | 0 | my ($self) = @_; | |||||||||||||||||||
| 76 | 0 | my $ret = $self->{_UA}->get('http://booklog.jp/logout'); | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | sub _add_fav | ||||||||||||||||||||
| 80 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_add_fav: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 81 | 0 | my ($self, $book_id) = @_; | |||||||||||||||||||
| 82 | 0 | $self->{_UA}->post('http://booklog.jp/api/review/fav', { book_id => $book_id }); | |||||||||||||||||||
| 83 | } | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | sub _del_fav | ||||||||||||||||||||
| 86 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_del_fav: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 87 | 0 | my ($self, $book_id) = @_; | |||||||||||||||||||
| 88 | 0 | $self->{_UA}->post('http://booklog.jp/api/review/fav', { book_id => $book_id, _method => 'delete' }); | |||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | sub _add_follow | ||||||||||||||||||||
| 92 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_add_follow: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 93 | 0 | my ($self, $account) = @_; | |||||||||||||||||||
| 94 | 0 | $self->{_UA}->post('http://booklog.jp/api/follow/add', { account => $account }); | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | # status | ||||||||||||||||||||
| 98 | # read_at_[ymd] (w/o 0 pad) / read_at_null | ||||||||||||||||||||
| 99 | # rank | ||||||||||||||||||||
| 100 | # category_id | ||||||||||||||||||||
| 101 | # description | ||||||||||||||||||||
| 102 | # public (2: revealer) | ||||||||||||||||||||
| 103 | # tags | ||||||||||||||||||||
| 104 | # create_on_[ymdhis] (w/ 0 pad) | ||||||||||||||||||||
| 105 | # memo | ||||||||||||||||||||
| 106 | sub _edit_review | ||||||||||||||||||||
| 107 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_edit_review: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 108 | 0 | my ($self, $service, $id, $args) = @_; | |||||||||||||||||||
| 109 | 0 | ▶ | $args ||= {}; | ||||||||||||||||||
|
Condition0%0/2
$args ||= {}
MC/DC0%0/1
$args ||= {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||||||||||
| 110 | 0 | $args->{_method} = 'edit'; | |||||||||||||||||||
| 111 | 0 | $self->{_UA}->post("http://booklog.jp/edit/$service/$id", $args); | |||||||||||||||||||
| 112 | } | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | # description | ||||||||||||||||||||
| 115 | # page | ||||||||||||||||||||
| 116 | sub _edit_quote | ||||||||||||||||||||
| 117 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_edit_quote: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 118 | 0 | my ($self, $service, $id, $args) = @_; | |||||||||||||||||||
| 119 | 0 | ▶ | $args ||= {}; | ||||||||||||||||||
|
Condition0%0/2
$args ||= {}
MC/DC0%0/1
$args ||= {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||||||||||
| 120 | 0 | $args->{_method} = 'quote'; | |||||||||||||||||||
| 121 | 0 | $self->{_UA}->post("http://booklog.jp/edit/$service/$id#select_tab2", $args); | |||||||||||||||||||
| 122 | } | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | # read_at_[ymd] (w/o 0 pad) | ||||||||||||||||||||
| 125 | # rank | ||||||||||||||||||||
| 126 | # comment | ||||||||||||||||||||
| 127 | sub _edit_reread | ||||||||||||||||||||
| 128 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_edit_reread: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 129 | 0 | my ($self, $service, $id, $book_id, $args) = @_; | |||||||||||||||||||
| 130 | 0 | ▶ | $args ||= {}; | ||||||||||||||||||
|
Condition0%0/2
$args ||= {}
MC/DC0%0/1
$args ||= {}
$args
Truth table0%0/2
A
A= $args
| |||||||||||||||||||||
| 131 | 0 | $args->{_method} = 'reread'; | |||||||||||||||||||
| 132 | 0 | $args->{book_id} = $book_id; | |||||||||||||||||||
| 133 | 0 | $self->{_UA}->post("http://booklog.jp/edit/$service/$id#select_tab2", $args); | |||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | sub _delete_item | ||||||||||||||||||||
| 137 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_delete_item: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 138 | 0 | my ($self, $service, $id) = @_; | |||||||||||||||||||
| 139 | 0 | my $args = { _method => 'delete' }; | |||||||||||||||||||
| 140 | 0 | $self->{_UA}->post("http://booklog.jp/edit/$service/$id#select_tab2", $args); | |||||||||||||||||||
| 141 | } | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | sub _sort_all | ||||||||||||||||||||
| 144 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_sort_all: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 145 | 0 | my ($self, @book_id) = @_; | |||||||||||||||||||
| 146 | 0 | my $arg = [map { ('booklist[]', $_) } @book_id]; | |||||||||||||||||||
| 147 | 0 | $self->{_UA}->post("http://booklog.jp/sort", $arg); | |||||||||||||||||||
| 148 | } | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | sub _set_sort | ||||||||||||||||||||
| 151 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
_set_sort: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 152 | 0 | my ($self, $book_id, $sort) = @_; | |||||||||||||||||||
| 153 | 0 | $self->{_UA}->post('http://booklog.jp/sort_edit', { book_id => $book_id, 'sort' => $sort }); | |||||||||||||||||||
| 154 | } | ||||||||||||||||||||
| 155 | |||||||||||||||||||||
| 156 | 3 | 1; | |||||||||||||||||||
| 157 | |||||||||||||||||||||
| 158 | __END__ | ||||||||||||||||||||