| 1 | package WWW::TVMaze; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 2 | ▶ | use 5.006; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 2 | ▶ | use Mouse; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 2 | ▶ | use JSON::XS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 2 | ▶ | use DateTime; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 2 | ▶ | use Params::Validate qw(:all); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | WWW::TVMaze - Interface to TVMaze API | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 VERSION | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | Version 0.01 | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | =cut | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 2 | our $VERSION = '0.03'; | |||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 2 | has '_endpoint' => ( | |||||||||||||||||||
| 25 | isa => 'Str', | ||||||||||||||||||||
| 26 | is =>'ro', | ||||||||||||||||||||
| 27 | default => 'http://api.tvmaze.com' | ||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 2 | has 'error' => ( | |||||||||||||||||||
| 31 | isa => 'Maybe[Str]', | ||||||||||||||||||||
| 32 | is => 'rw', | ||||||||||||||||||||
| 33 | default => undef, | ||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 2 | has 'http_status' => ( | |||||||||||||||||||
| 37 | isa => 'Maybe[Str]', | ||||||||||||||||||||
| 38 | is =>'rw', | ||||||||||||||||||||
| 39 | default => undef, | ||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | =head1 SYNOPSIS | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | This module allows you to user TVMaze API (L<http://www.tvmaze.com/api>) | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | use WWW::TVMaze; | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | my $tv_maze = WWW::TVMaze->new(); | ||||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | my $shows = $tv_maze->show_search('Arrow'); | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head1 METHODS | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =head2 shows | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | my $show = $tv_maze->shows($id); | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | Returns a show by its ID | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =head2 show_search | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | my $shows = $tv_maze->show_search($search_keyword); | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | Returns a list of shows that match your search keyword | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =head2 show_single_search | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | my $show = $tv_maze->show_single_search($search_keyword); | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | Returns a single show that match your search keyword | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =head2 show_lookup | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | my $show = $tv_maze->show_lookup( $id, $id_type ); # $id_type can be 'tvrage' or 'thetvdb' | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | Returns a show by its TVRage ID or by its THETVDB ID | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =head2 show_episode_list | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | my $ep_list = $self->show_episode_list($show_id, $include_specials); # $include_specials can be 0 or 1 and is optional; | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | Returns a complete list of episodes for a given show. by defauls specials are not included | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | =head2 show_cast | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | my $cast = $tv_maze->show_cast($show_id); | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | Returns a list of main cast for a given show | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =head2 show_akas | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | my $akas = $tv_maze->show_akas($show_id); | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | Returns a list of AKA's for a show | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =head2 show_index | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | my $index = $tv_maze->show_index($page); ## $page is optional, pagination starts on page 0 | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | Returns all TV Maze shows , 250 results per page | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | =head2 episode_by_number | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | my $ep = $tv_maze->episode_by_number($show_id, $season, $ep_number); | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | Returns a show episode | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | =head2 episodes_by_date | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | my $eps = $tv_maze->episodes_by_date($show_id, $date); | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | Returns a list of episodes for a given show aired on a given date | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | =head2 schedule | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | my $schedule = $tv_maze->schedule($country_code, $date); # $country_code is an ISO 3166-1 code of the country, $date an ISO 8601 formatted date, both parameters are optional, defaults to 'US' and current day | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | Returns a complete list of episodes for the date and country provided | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head2 full_schedule | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | my $schedule = $tv_maze->full_schedule(); | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | Returns a list of all future episodes known to TVmaze | ||||||||||||||||||||
| 131 | |||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | =head2 people_search | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | my $people = $tv_maze->people_search($search_keyword); | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | Returns a list of persons that match your search keyword | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =head2 people | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | my $people = $tv_maze->people($id); | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | Returns a person by its ID | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | =head2 person_cast_credits | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | my $person_credits = $tv_maze->person_cast_credits($person_id, $emded_show); # $embed_show is optional, can be 1 or 0; | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | Returns alll show-level cast credits for a person | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =head2 person_crew_credits | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | my $person_credits = $tv_maze->person_crew_credits($person_id, $emded_show); # $embed_show is optional, can be 1 or 0; | ||||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | Returns alll show-level crew credits for a person | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =head2 updates | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | my $updates = $tv_maze->updates(); | ||||||||||||||||||||
| 162 | |||||||||||||||||||||
| 163 | Returns a list of all the shows in the database with a timestamp of when they were last updated | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =head2 error | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | my $error = $tv_maze->error(); | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | Returns the last error | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | =head2 http_status | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | my $http_status = $tv_maze->http_status(); | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | Returns the last HTTP status received | ||||||||||||||||||||
| 177 | =cut | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | |||||||||||||||||||||
| 180 | sub shows { | ||||||||||||||||||||
| 181 | 0 | ▶ | my ($self, $id) = @_; | ||||||||||||||||||
|
Subroutine
shows: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 182 | 0 | shift @_; | |||||||||||||||||||
| 183 | 0 | validate_pos(@_, { type => SCALAR } ); | |||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | 0 | return $self->_request('shows/' . $id); | |||||||||||||||||||
| 186 | } | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | sub show_search { | ||||||||||||||||||||
| 189 | 0 | ▶ | my ($self, $search) = @_; | ||||||||||||||||||
|
Subroutine
show_search: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 190 | 0 | shift @_; | |||||||||||||||||||
| 191 | 0 | validate_pos(@_ , { type => SCALAR } ); | |||||||||||||||||||
| 192 | 0 | return $self->_request('search/shows?q=' . $search); | |||||||||||||||||||
| 193 | } | ||||||||||||||||||||
| 194 | |||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | sub show_single_search { | ||||||||||||||||||||
| 197 | 0 | ▶ | my ($self, $search) = @_; | ||||||||||||||||||
|
Subroutine
show_single_search: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 198 | 0 | shift @_; | |||||||||||||||||||
| 199 | 0 | validate_pos(@_ , { type => SCALAR } ); | |||||||||||||||||||
| 200 | 0 | return $self->_request('singlesearch/shows?q=' . $search); | |||||||||||||||||||
| 201 | } | ||||||||||||||||||||
| 202 | |||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | sub show_lookup { | ||||||||||||||||||||
| 205 | 0 | ▶ | my ($self, $id, $id_type) = @_; | ||||||||||||||||||
|
Subroutine
show_lookup: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 206 | 0 | shift @_; | |||||||||||||||||||
| 207 | 0 | validate_pos (@_ , { type => SCALAR }, { type => SCALAR, regex => qr/^tvrage$|^thetvdb$/ } ); | |||||||||||||||||||
| 208 | 0 | return $self->_request('lookup/shows?' . $id_type .'=' . $id); | |||||||||||||||||||
| 209 | } | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | |||||||||||||||||||||
| 213 | sub people_search { | ||||||||||||||||||||
| 214 | 0 | ▶ | my ($self, $search) = @_; | ||||||||||||||||||
|
Subroutine
people_search: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 215 | 0 | shift @_; | |||||||||||||||||||
| 216 | 0 | validate_pos(@_ , { type => SCALAR } ); | |||||||||||||||||||
| 217 | 0 | return $self->_request('search/people?q=' . $search); | |||||||||||||||||||
| 218 | } | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | sub schedule { | ||||||||||||||||||||
| 223 | 0 | ▶ | my ($self, $country_code, $date) = @_; | ||||||||||||||||||
|
Subroutine
schedule: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 224 | 0 | shift @_; | |||||||||||||||||||
| 225 | 0 | validate_pos(@_ , { type => SCALAR, optional => 1 , regex => qr/^\w{2}$/}, { type => SCALAR , optional => 1 , regex => qw/\d{4}-\d{2}-\d{2}$/ } ); | |||||||||||||||||||
| 226 | 0 | ▶ | $country_code ||= 'US'; | ||||||||||||||||||
|
Condition0%0/2
$country_code ||= "US"
MC/DC0%0/1
$country_code ||= "US"
$country_code
Truth table0%0/2
A
A= $country_code
| |||||||||||||||||||||
| 227 | 0 | ▶ | $date ||= DateTime->now->ymd('-'); | ||||||||||||||||||
|
Condition0%0/3
$date ||= "DateTime"->now->ymd("-")
MC/DC0%0/2
$date ||= "DateTime"->now->ymd("-")
$date
"DateTime"->now->ymd("-")
Truth table0%0/3
A ||= B
A= $dateB= "DateTime"->now->ymd("-")
| |||||||||||||||||||||
| 228 | 0 | return $self->_request('schedule?country=' . $country_code . '&date=' .$date); | |||||||||||||||||||
| 229 | } | ||||||||||||||||||||
| 230 | |||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | sub full_schedule { | ||||||||||||||||||||
| 233 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
full_schedule: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 234 | 0 | return $self->_request('schedule/full'); | |||||||||||||||||||
| 235 | } | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | |||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | |||||||||||||||||||||
| 240 | sub show_episode_list { | ||||||||||||||||||||
| 241 | 0 | ▶ | my ($self, $tvmaze_id, $specials) = @_; | ||||||||||||||||||
|
Subroutine
show_episode_list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 242 | 0 | shift @_; | |||||||||||||||||||
| 243 | 0 | validate_pos(@_, { type => SCALAR }, { type => BOOLEAN , optional => 1 } ); | |||||||||||||||||||
| 244 | 0 | ▶ | $specials ||= 0; | ||||||||||||||||||
|
Condition0%0/2
$specials ||= 0
MC/DC0%0/1
$specials ||= 0
$specials
Truth table0%0/2
A
A= $specials
| |||||||||||||||||||||
| 245 | 0 | return $self->_request('shows/' . $tvmaze_id .'/episodes?specials=' . $specials); | |||||||||||||||||||
| 246 | } | ||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | sub episode_by_number { | ||||||||||||||||||||
| 250 | 0 | ▶ | my ($self, $tvmaze_id, $season, $number) = @_; | ||||||||||||||||||
|
Subroutine
episode_by_number: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 251 | 0 | shift @_; | |||||||||||||||||||
| 252 | 0 | validate_pos(@_, { type => SCALAR }, { type => SCALAR , optional => 1, regex => qr/^\d+$/ }, { type => SCALAR , optional => 1, regex => qr/^\d+$/ } ); | |||||||||||||||||||
| 253 | 0 | $season |= 1; | |||||||||||||||||||
| 254 | 0 | $number |= 1; | |||||||||||||||||||
| 255 | 0 | return $self->_request('shows/' . $tvmaze_id . '/episodebynumber?season=' . $season .'&number=' . $number); | |||||||||||||||||||
| 256 | } | ||||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | sub episodes_by_date { | ||||||||||||||||||||
| 260 | 0 | ▶ | my ($self, $tvmaze_id, $date) = @_; | ||||||||||||||||||
|
Subroutine
episodes_by_date: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 261 | |||||||||||||||||||||
| 262 | 0 | ▶ | if ($date !~/^\d{4}-\d{2}-\d{2}$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 263 | 0 | $self->error('invalid date'); | |||||||||||||||||||
| 264 | 0 | return undef; | |||||||||||||||||||
| 265 | } | ||||||||||||||||||||
| 266 | 0 | return $self->_request('shows/' . $tvmaze_id .'/episodesbydate?date=' . $date); | |||||||||||||||||||
| 267 | } | ||||||||||||||||||||
| 268 | |||||||||||||||||||||
| 269 | |||||||||||||||||||||
| 270 | |||||||||||||||||||||
| 271 | |||||||||||||||||||||
| 272 | sub show_cast { | ||||||||||||||||||||
| 273 | 0 | ▶ | my ($self, $tvmaze_id) = @_; | ||||||||||||||||||
|
Subroutine
show_cast: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 274 | 0 | return $self->_request('shows/' . $tvmaze_id .'/cast'); | |||||||||||||||||||
| 275 | } | ||||||||||||||||||||
| 276 | |||||||||||||||||||||
| 277 | |||||||||||||||||||||
| 278 | sub show_akas { | ||||||||||||||||||||
| 279 | 0 | ▶ | my ($self, $tvmaze_id) = @_; | ||||||||||||||||||
|
Subroutine
show_akas: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 280 | 0 | return $self->_request('shows/' . $tvmaze_id .'/akas'); | |||||||||||||||||||
| 281 | } | ||||||||||||||||||||
| 282 | |||||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | |||||||||||||||||||||
| 285 | |||||||||||||||||||||
| 286 | sub show_index { | ||||||||||||||||||||
| 287 | 0 | ▶ | my ($self, $page) = @_; | ||||||||||||||||||
|
Subroutine
show_index: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 288 | 0 | ▶ | $page ||= 0; | ||||||||||||||||||
|
Condition0%0/2
$page ||= 0
MC/DC0%0/1
$page ||= 0
$page
Truth table0%0/2
A
A= $page
| |||||||||||||||||||||
| 289 | 0 | return $self->_request('shows?page=' . $page); | |||||||||||||||||||
| 290 | } | ||||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | |||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | sub people { | ||||||||||||||||||||
| 295 | 0 | ▶ | my ($self, $tvmaze_id) = @_; | ||||||||||||||||||
|
Subroutine
people: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 296 | 0 | return $self->_request('people/' . $tvmaze_id); | |||||||||||||||||||
| 297 | } | ||||||||||||||||||||
| 298 | |||||||||||||||||||||
| 299 | |||||||||||||||||||||
| 300 | |||||||||||||||||||||
| 301 | sub person_cast_credits { | ||||||||||||||||||||
| 302 | 0 | ▶ | my ($self, $tvmaze_id, $embed) = @_; | ||||||||||||||||||
|
Subroutine
person_cast_credits: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 303 | 0 | ▶ | return $self->_request('people/' . $tvmaze_id .'/castcredits' . ( $embed ? '?embed=show' : '' )); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 304 | } | ||||||||||||||||||||
| 305 | |||||||||||||||||||||
| 306 | |||||||||||||||||||||
| 307 | sub person_crew_credits { | ||||||||||||||||||||
| 308 | 0 | ▶ | my ($self, $tvmaze_id, $embed) = @_; | ||||||||||||||||||
|
Subroutine
person_crew_credits: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 309 | 0 | ▶ | return $self->_request('people/' . $tvmaze_id .'/crewcredits' . ( $embed ? '?embed=show' : '' )); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 310 | } | ||||||||||||||||||||
| 311 | |||||||||||||||||||||
| 312 | |||||||||||||||||||||
| 313 | |||||||||||||||||||||
| 314 | sub updates { | ||||||||||||||||||||
| 315 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
updates: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 316 | 0 | return $self->_request('updates/shows'); | |||||||||||||||||||
| 317 | } | ||||||||||||||||||||
| 318 | |||||||||||||||||||||
| 319 | |||||||||||||||||||||
| 320 | |||||||||||||||||||||
| 321 | |||||||||||||||||||||
| 322 | |||||||||||||||||||||
| 323 | sub _request { | ||||||||||||||||||||
| 324 | 0 | ▶ | my ($self, $uri) = @_; | ||||||||||||||||||
|
Subroutine
_request: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 325 | |||||||||||||||||||||
| 326 | 0 | my $ua = LWP::UserAgent->new(); | |||||||||||||||||||
| 327 | 0 | my $url = $self->_endpoint .'/' . $uri; | |||||||||||||||||||
| 328 | 0 | my $response = $ua->get($url); | |||||||||||||||||||
| 329 | |||||||||||||||||||||
| 330 | 0 | $self->http_status($response->code); | |||||||||||||||||||
| 331 | |||||||||||||||||||||
| 332 | 0 | ▶ | if (!$response->is_success) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 333 | 0 | $self->error('request error'); | |||||||||||||||||||
| 334 | 0 | return {}; | |||||||||||||||||||
| 335 | } | ||||||||||||||||||||
| 336 | |||||||||||||||||||||
| 337 | 0 | my $data = {}; | |||||||||||||||||||
| 338 | 0 | eval { | |||||||||||||||||||
| 339 | 0 | $data = decode_json($response->decoded_content); | |||||||||||||||||||
| 340 | }; | ||||||||||||||||||||
| 341 | 0 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 342 | 0 | $self->error('problem decoding json'); | |||||||||||||||||||
| 343 | 0 | return undef; | |||||||||||||||||||
| 344 | } | ||||||||||||||||||||
| 345 | 0 | return $data; | |||||||||||||||||||
| 346 | } | ||||||||||||||||||||
| 347 | |||||||||||||||||||||
| 348 | |||||||||||||||||||||
| 349 | |||||||||||||||||||||
| 350 | |||||||||||||||||||||
| 351 | |||||||||||||||||||||
| 352 | |||||||||||||||||||||
| 353 | |||||||||||||||||||||
| 354 | =head1 AUTHOR | ||||||||||||||||||||
| 355 | |||||||||||||||||||||
| 356 | Bruno Martins, C<< <bscmartins at gmail.com> >> | ||||||||||||||||||||
| 357 | |||||||||||||||||||||
| 358 | =head1 BUGS | ||||||||||||||||||||
| 359 | |||||||||||||||||||||
| 360 | Please report any bugs or feature requests at L<https://github.com/bmartins/WWW-TVMaze> | ||||||||||||||||||||
| 361 | |||||||||||||||||||||
| 362 | |||||||||||||||||||||
| 363 | |||||||||||||||||||||
| 364 | |||||||||||||||||||||
| 365 | =head1 SUPPORT | ||||||||||||||||||||
| 366 | |||||||||||||||||||||
| 367 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||
| 368 | |||||||||||||||||||||
| 369 | perldoc WWW::TVMaze | ||||||||||||||||||||
| 370 | |||||||||||||||||||||
| 371 | |||||||||||||||||||||
| 372 | |||||||||||||||||||||
| 373 | =head1 LICENSE AND COPYRIGHT | ||||||||||||||||||||
| 374 | |||||||||||||||||||||
| 375 | Copyright 2015 Bruno Martins. | ||||||||||||||||||||
| 376 | |||||||||||||||||||||
| 377 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 378 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||
| 379 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||
| 380 | |||||||||||||||||||||
| 381 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||
| 382 | |||||||||||||||||||||
| 383 | |||||||||||||||||||||
| 384 | =cut | ||||||||||||||||||||
| 385 | |||||||||||||||||||||
| 386 | 2 | 1; # End of WWW::TVMaze | |||||||||||||||||||