Skip to content

Commit

Permalink
add support for movie discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
mithun committed Jun 17, 2013
1 parent acb7c58 commit 3ade1fd
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .author/_pod_helpers/synopsis.pl
Expand Up @@ -109,6 +109,15 @@
my @results = $search->collection('Star Wars'); # Search for collections
my @results = $search->list('top 250'); # Search lists

# Discover
my @results = $search->discover(
{
sort_by => 'popularity.asc',
'vote_average.gte' => '7.2',
'vote_count.gte' => '10',
}
);

# Get Lists
my $lists = $tmdb->search();
my $latest = $lists->latest(); # Latest movie added to TheMovieDB
Expand Down
21 changes: 20 additions & 1 deletion .author/_tests/00_test.pl
Expand Up @@ -41,8 +41,9 @@
a => 0, # All
cm => 0, # Company
g => 0, # Genre
d => 0, # Discover
);
GetOptions( \%opts, 'c', 'm', 's', 'p', 'a', 'cm', 'g', )
GetOptions( \%opts, 'c', 'm', 's', 'p', 'a', 'cm', 'g', 'd', )
or die "Invalid Options";

if ( $opts{a} ) {
Expand Down Expand Up @@ -130,6 +131,24 @@
);
} ## end if ( $opts{s} )
####################
# DISCOVER
####################
if ( $opts{d} ) {
_dump(
o => [
$tmdb->search->discover(
{
sort_by => 'popularity.asc',
'vote_average.gte' => '7.2',
'vote_count.gte' => '10',
}
)
],
m => 'Discover Movies',
);
} ## end if ( $opts{d} )
####################
# MOVIE
####################
Expand Down
9 changes: 9 additions & 0 deletions lib/TMDB.pm
Expand Up @@ -232,6 +232,15 @@ L<http://docs.themoviedb.apiary.io/#configuration> for more details.
my @results = $search->collection('Star Wars'); # Search for collections
my @results = $search->list('top 250'); # Search lists
# Discover
my @results = $search->discover(
{
sort_by => 'popularity.asc',
'vote_average.gte' => '7.2',
'vote_count.gte' => '10',
}
);
# Get Lists
my $lists = $tmdb->search();
my $latest = $lists->latest(); # Latest movie added to TheMovieDB
Expand Down
75 changes: 75 additions & 0 deletions lib/TMDB/Search.pm
Expand Up @@ -256,6 +256,81 @@ sub latest_person {
);
} ## end sub latest_person

#######################
# DISCOVER
#######################
sub discover {
my ( $self, @args ) = @_;
my %options = validate_with(
params => [@args],
spec => {
sort_by => {
type => SCALAR,
optional => 1,
default => 'popularity.asc',
callbacks => {
'valid flag' => sub {
( lc $_[0] eq 'vote_average.desc' )
or ( lc $_[0] eq 'vote_average.asc' )
or ( lc $_[0] eq 'release_date.desc' )
or ( lc $_[0] eq 'release_date.asc' )
or ( lc $_[0] eq 'popularity.desc' )
or ( lc $_[0] eq 'popularity.asc' );
},
},
},
year => {
type => SCALAR,
optional => 1,
regex => qr/^\d{4}\-\d{2}\-\d{2}$/
},
'release_date.gte' => {
type => SCALAR,
optional => 1,
regex => qr/^\d{4}\-\d{2}\-\d{2}$/
},
'release_date.lte' => {
type => SCALAR,
optional => 1,
regex => qr/^\d{4}\-\d{2}\-\d{2}$/
},
'vote_count.gte' => {
type => SCALAR,
optional => 1,
regex => qr/^\d+$/
},
'vote_average.gte' => {
type => SCALAR,
optional => 1,
regex => qr/^\d{1,2}\.\d{1,}$/,
callbacks => {
average => sub { $_[0] <= 10 },
},
},
with_genres => {
type => SCALAR,
optional => 1,
},
with_companies => {
type => SCALAR,
optional => 1,
},
},
);

return $self->_search(
{
method => 'discover/movie',
params => {
language => $self->session->lang ? $self->session->lang : undef,
include_adult => $self->include_adult,
%options,
},
}
);

} ## end sub discover

#######################
# PRIVATE METHODS
#######################
Expand Down

0 comments on commit 3ade1fd

Please sign in to comment.