NicoVideo/Request.pm

filter: Statementstmt 100% 113 / 113 Branchbran 93.7% 30 / 32 Conditioncond 67.7% 21 / 31 MC/DCmcdc 41.1% 7 / 17 Subroutinesub 100% 29 / 29 Podpod 0.0% 0 / 22 totaltotal 81.9% 200 / 244 CC 32 SCAR 10.6
CC
32
Cov
93%
tag_rss
6.1
thread
6.0
make_id_list
4.0
CRAP 2.9
« NicoVideo/Content/Watch.pm ↑ Summary NicoVideo/Decorator.pm »
1 package Net::NicoVideo::Request;
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 3 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 $VERSION = '0.27';
7  
8 3 ▶use base qw(HTTP::Request);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶sub get {
Subroutine get: called CC=1 SCAR=0.0
Pod undocumented
14 2 my $class = shift;
15 2 return GET @_;
16 }
17  
18 4 ▶sub login {
Subroutine login: called CC=3 SCAR=11.0
Pod undocumented
19 4 my ($class, $email, $password) = @_;
20 4 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $email and defined $password 2 2 4
Condition100%3/3
defined $email and defined $password
!ll&&!rl&&r
112
MC/DC100%2/2
defined $email and defined $password
defined $email defined $password
Truth table100%3/3
A and B
A= defined $emailB= defined $password
ABresult
0X0
100
111
21 if( ! defined $email or ! defined $password );
22 2 my $url = 'https://secure.nicovideo.jp/secure/login?site=niconico';
23 2 return POST $url, [
24 next_url => '',
25 mail => $email,
26 password => $password,
27 ];
28 }
29  
30 3 ▶sub thumbinfo {
Subroutine thumbinfo: called CC=2 SCAR=6.9
Pod undocumented
31 3 my ($class, $video_id) = @_;
32 3 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $video_id 1 2 3
33 if( ! defined $video_id );
34 2 my $url = 'http://ext.nicovideo.jp/api/getthumbinfo/'.$video_id;
35 2 return GET $url;
36 }
37  
38 5 ▶sub flv {
Subroutine flv: called CC=3 SCAR=11.0
Pod undocumented
39 5 my ($class, $video_id) = @_;
40 5 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $video_id 1 4 5
41 if( ! defined $video_id);
42 4 my $url = 'http://flapi.nicovideo.jp/api/getflv/'.$video_id;
43 4 ▶ my $params = $video_id =~ /^nm/ ? ['as3' => 1] : [];
Branch: 1 branch
BranchTrueFalseTotal
$video_id =~ /^nm/ ? : 2 2 4
44 4 return POST $url, $params;
45 }
46  
47 3 ▶sub watch {
Subroutine watch: called CC=2 SCAR=6.9
Pod undocumented
48 3 my ($class, $video_id) = @_;
49 3 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $video_id 1 2 3
50 if( ! defined $video_id);
51 2 my $url = 'http://www.nicovideo.jp/watch/'.$video_id;
52 2 return GET $url;
53 }
54  
55 6 ▶sub thread {
Subroutine thread: called CC=6 SCAR=17.9
Pod undocumented
56 6 my ($class, $ms, $thread_id, $opts) = @_;
57 6 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ms and defined $thread_id 2 4 6
Condition100%3/3
defined $ms and defined $thread_id
!ll&&!rl&&r
114
MC/DC100%2/2
defined $ms and defined $thread_id
defined $ms defined $thread_id
Truth table100%3/3
A and B
A= defined $msB= defined $thread_id
ABresult
0X0
100
111
58 if( ! defined $ms or ! defined $thread_id );
59 4 ▶ $opts ||= {};
Condition50%1/2
$opts ||= {}
l!l
40
MC/DC0%0/1
$opts ||= {}
$opts
Truth table50%1/2
A
A= $opts
Aresult
11
00
60 return POST $ms,
61 Content => sprintf '<thread thread="%s" version="20061206" res_from="-%d"%s></thread>',
62 4 ▶ $thread_id, ($opts->{'chats'} || 250), ($opts->{'fork'} ? ' fork="1"' : '');
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'fork'} ? : 2 2 4
Condition100%2/2
$opts->{'chats'} || 250
l!l
22
MC/DC100%1/1
$opts->{'chats'} || 250
$opts->{'chats'}
Truth table100%2/2
A
A= $opts->{'chats'}
Aresult
11
00
63 }
64  
65 3 ▶sub tag_rss {
Subroutine tag_rss: called CC=6 SCAR=18.1
Pod undocumented
66 3 my ($class, $keyword, $params) = @_;
67 3 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $keyword 1 2 3
68 if( ! defined $keyword );
69 2 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
20
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
70 2 $params->{rss} = '2.0';
71 2 my @q = ();
72 2 for my $k ( sort keys %{$params} ){
73 4 my $v = $params->{$k};
74 4 ▶ $v = '' unless( defined $v );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 4 4
75 4 push @q, sprintf('%s=%s', uri_escape_utf8($k), uri_escape_utf8($v));
76 }
77 2 my $url = sprintf 'http://www.nicovideo.jp/tag/%s', uri_escape_utf8($keyword);
78 2 ▶ $url = sprintf('%s?%s', $url, join('&', @q)) if( @q );
Branch: 1 branch
BranchTrueFalseTotal
if @q 2 0 2
79 2 return GET $url;
80 }
81  
82 3 ▶sub mylist_rss {
Subroutine mylist_rss: called CC=2 SCAR=6.9
Pod undocumented
83 3 my ($class, $mylist_id) = @_;
84 3 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mylist_id 1 2 3
85 if( ! defined $mylist_id );
86 2 my $url = 'http://www.nicovideo.jp/mylist/'.$mylist_id.'?rss=2.0';
87 2 return GET $url;
88 }
89  
90 2 ▶sub mylist_page {
Subroutine mylist_page: called CC=1 SCAR=0.0
Pod undocumented
91 2 my ($class) = @_;
92 2 return GET 'http://www.nicovideo.jp/my/mylist';
93 }
94  
95 3 ▶sub mylist_item {
Subroutine mylist_item: called CC=2 SCAR=6.9
Pod undocumented
96 3 my ($class, $video_id) = @_;
97 3 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $video_id 1 2 3
98 if( ! defined $video_id );
99 2 my $url = 'http://www.nicovideo.jp/mylist_add/video/'.$video_id;
100 2 return GET $url;
101 }
102  
103 2 ▶sub mylistgroup_list {
Subroutine mylistgroup_list: called CC=1 SCAR=0.0
Pod undocumented
104 2 my ($class) = @_;
105 2 return POST 'http://www.nicovideo.jp/api/mylistgroup/list';
106 }
107  
108 3 ▶sub mylistgroup_get {
Subroutine mylistgroup_get: called CC=2 SCAR=6.9
Pod undocumented
109 3 my ($class, $mylist_id) = @_;
110 3 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mylist_id 1 2 3
111 if( ! defined $mylist_id );
112 2 my $params = [ group_id => $mylist_id ];
113 2 return POST 'http://www.nicovideo.jp/api/mylistgroup/get', $params;
114 }
115  
116 2 ▶sub mylistgroup_add {
Subroutine mylistgroup_add: called CC=2 SCAR=7.1
Pod undocumented
117 2 my ($class, $params, $token) = @_;
118 2 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
20
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
119 return POST 'http://www.nicovideo.jp/api/mylistgroup/add', [
120 token => $token,
121 name => $params->{name},
122 description => $params->{description},
123 public => $params->{public},
124 default_sort=> $params->{default_sort},
125 icon_id => $params->{icon_id},
126 2 ];
127 }
128  
129 2 ▶sub mylistgroup_update {
Subroutine mylistgroup_update: called CC=2 SCAR=7.1
Pod undocumented
130 2 my ($class, $params, $token) = @_;
131 2 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
20
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
132 return POST 'http://www.nicovideo.jp/api/mylistgroup/update', [
133 token => $token,
134 group_id => $params->{group_id},
135 name => $params->{name},
136 description => $params->{description},
137 public => $params->{public},
138 default_sort=> $params->{default_sort},
139 icon_id => $params->{icon_id},
140 2 ];
141 }
142  
143 2 ▶sub mylistgroup_delete {
Subroutine mylistgroup_delete: called CC=2 SCAR=7.1
Pod undocumented
144 2 my ($class, $params, $token) = @_;
145 2 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
20
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
146 return POST 'http://www.nicovideo.jp/api/mylistgroup/delete', [
147 token => $token,
148 group_id => $params->{group_id},
149 2 ];
150 }
151  
152 3 ▶sub mylist_list {
Subroutine mylist_list: called CC=2 SCAR=6.9
Pod undocumented
153 3 my ($class, $group_id) = @_;
154 3 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $group_id 1 2 3
155 if( ! defined $group_id );
156 2 my $params = [ group_id => $group_id ];
157 2 return POST 'http://www.nicovideo.jp/api/mylist/list', $params;
158 }
159  
160 2 ▶sub mylist_add {
Subroutine mylist_add: called CC=2 SCAR=7.1
Pod undocumented
161 2 my ($class, $params, $token) = @_;
162 2 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
20
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
163 return POST 'http://www.nicovideo.jp/api/mylist/add', [
164 token => $token,
165 group_id => $params->{group_id},
166 item_type => $params->{item_type},
167 item_id => $params->{item_id},
168 description => $params->{description},
169 2 ];
170 }
171  
172 2 ▶sub mylist_update {
Subroutine mylist_update: called CC=2 SCAR=7.1
Pod undocumented
173 2 my ($class, $params, $token) = @_;
174 2 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
20
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
175 return POST 'http://www.nicovideo.jp/api/mylist/update', [
176 token => $token,
177 group_id => $params->{group_id},
178 item_type => $params->{item_type},
179 item_id => $params->{item_id},
180 description => $params->{description},
181 2 ];
182 }
183  
184 2 ▶sub mylist_delete {
Subroutine mylist_delete: called CC=2 SCAR=7.0
Pod undocumented
185 2 my ($class, $params, $token) = @_;
186 2 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
20
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
187 2 my @args = $class->make_id_list($params->{item_type}, $params->{item_id});
188 push @args, (
189 token => $token,
190 group_id => $params->{group_id},
191 2 );
192 2 return POST 'http://www.nicovideo.jp/api/mylist/delete', \@args;
193 }
194  
195 2 ▶sub mylist_move {
Subroutine mylist_move: called CC=2 SCAR=7.0
Pod undocumented
196 2 my ($class, $params, $token) = @_;
197 2 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
20
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
198 2 my @args = $class->make_id_list($params->{item_type}, $params->{item_id});
199 push @args, (
200 token => $token,
201 group_id => $params->{group_id},
202 target_group_id => $params->{target_group_id},
203 2 );
204 2 return POST 'http://www.nicovideo.jp/api/mylist/move', \@args;
205 }
206  
207 2 ▶sub mylist_copy {
Subroutine mylist_copy: called CC=2 SCAR=7.0
Pod undocumented
208 2 my ($class, $params, $token) = @_;
209 2 ▶ $params ||= {};
Condition50%1/2
$params ||= {}
l!l
20
MC/DC0%0/1
$params ||= {}
$params
Truth table50%1/2
A
A= $params
Aresult
11
00
210 2 my @args = $class->make_id_list($params->{item_type}, $params->{item_id});
211 push @args, (
212 token => $token,
213 group_id => $params->{group_id},
214 target_group_id => $params->{target_group_id},
215 2 );
216 2 return POST 'http://www.nicovideo.jp/api/mylist/copy', \@args;
217 }
218  
219 12 ▶sub make_id_list {
Subroutine make_id_list: called CC=4 SCAR=13.9
Pod undocumented
220 12 my ($class, $item_type, $item_id) = @_;
221 12 ▶ croak "missing mandatory parameter"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $item_type and defined $item_id 2 10 12
Condition100%3/3
defined $item_type and defined $item_id
!ll&&!rl&&r
1110
MC/DC100%2/2
defined $item_type and defined $item_id
defined $item_type defined $item_id
Truth table100%3/3
A and B
A= defined $item_typeB= defined $item_id
ABresult
0X0
100
111
222 if( ! defined $item_type or ! defined $item_id );
223 10 my @id_list = ('id_list['.$item_type.'][]' => $item_id);
224 10 ▶ return wantarray ? @id_list : \@id_list;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 2 10
225 }
226  
227 3 1;
228 __END__
« NicoVideo/Content/Watch.pm ↑ Summary NicoVideo/Decorator.pm »