| Net-Douban documentation | Contained in the Net-Douban distribution. |
Net::Douban::Subject
version 1.07
use Net::Douban::Subject;
my $user = Net::Douban::Subject->new(
subjectID => 2023013,
apikey => '....',
# or
oauth => $consumer,
);
$atom = $user->get_book(isbnID => 7543639103);
$atom = $user->search_book(tag => 'cowboy', start_index => 5, max_results => 10);
Interface to douban.com API Subject section
Those methods return a Net::Douban::Atom object which can be use to get data conveniently
parameter q(keyword) or tag needed for the search methods
Net::Douban Net::Douban::Atom Moose XML::Atom http://www.douban.com/service/apidoc/reference/subject
woosley.xu<redicaps@gmail.com>
Copyright (C) 2010 by Woosley.Xu
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.
| Net-Douban documentation | Contained in the Net-Douban distribution. |
package Net::Douban::Subject; BEGIN { $Net::Douban::Subject::VERSION = '1.07'; } use Moose; use MooseX::StrictConstructor; use Net::Douban::Atom; use Carp qw/carp croak/; with 'Net::Douban::Roles::More'; has 'subjectID' => (is => 'rw', isa => 'Str'); has 'subject_url' => ( is => 'rw', isa => 'Url', lazy => 1, default => sub { shift->base_url . '/subject' }, ); before qw/search_book search_music search_movie/ => sub { my ($self, %args) = @_; if (!exists $args{q} && !exists $args{tag}) { croak "Missing parameters: tag or q needed"; } }; sub get_book { my ($self, %args) = @_; my $url = $self->base_url; if (exists $args{isbnID}) { $url .= "/book/subject/isbn/$args{isbnID}"; } elsif (exists $args{subjectID}) { $url .= "/book/subject/$args{subjectID}"; } else { $self->subjectID or croak "SubjectID or isbnID missing"; $url .= "/book/subject/" . $self->subjectID; } return Net::Douban::Atom->new($self->get($url)); } sub get_movie { my ($self, %args) = @_; my $url = $self->base_url; if (exists $args{imdbID}) { $url .= "/movie/subject/imdb/$args{imdbID}"; } elsif (exists $args{subjectID}) { $url .= "/movie/subject/$args{subjectID}"; } else { $self->subjectID or croak "imdbID or subjectID missing"; $url .= "/movie/subject/" . $self->subjectID; } return Net::Douban::Atom->new($self->get($url)); } sub get_music { my ($self, %args) = @_; $args{subjectID} ||= $self->subjectID; croak "subjectID missing" unless $args{subjectID}; return Net::Douban::Atom->new( $self->get($self->base_url . "/music/subject/$args{subjectID}")); } sub search_music { my ($self, %args) = @_; return Net::Douban::Atom->new( $self->get($self->base_url . "/music/subjects", %args)); } sub search_book { my ($self, %args) = @_; return Net::Douban::Atom->new( $self->get($self->base_url . "/book/subjects", %args)); } sub search_movie { my ($self, %args) = @_; return Net::Douban::Atom->new( $self->get($self->base_url . "/movie/subjects", %args)); } no Moose; __PACKAGE__->meta->make_immutable; 1; __END__