NAME
WWW::Netflix::API - Interface for Netflix's API
VERSION
Version 0.03
OVERVIEW
This module is to provide your perl applications with easy access to the Netflix API (http://developer.netflix.com/). The Netflix API allows access to movie and user information, including queues, rating, rental history, and more.
SYNOPSIS
use WWW::Netflix::API;
use Data::Dumper;
my %auth = Your::Custom::getAuthFromCache();
# consumer key/secret values below are fake
my $netflix = WWW::Netflix::API->new({
consumer_key => '4958gj86hj6g99',
consumer_secret => 'QWEas1zxcv',
access_token => $auth{access_token},
access_secret => $auth{access_secret},
user_id => $auth{user_id},
content_filter => sub { use XML::Simple; XMLin(@_) }, # optional
});
if( ! $auth{user_id} ){
my ( $user, $pass ) = .... ;
@auth{qw/access_token access_secret user_id/} = $netflix->RequestAccess( $user, $pass );
Your::Custom::storeAuthInCache( %auth );
}
$netflix->REST->Users->Feeds;
$netflix->Get() or die 'request failed';
print Dumper $netflix->content;
$netflix->REST->Catalog->Titles->Movies('18704531');
$netflix->Get() or die 'request failed';
print Dumper $netflix->content;
GETTING STARTED
The first step to using this module is to register at http://developer.netflix.com -- you will need to register your application, for which you'll receive a consumer_key and consumer_secret keypair.
Any applications written with the Netflix API must adhere to the Terms of Use (http://developer.netflix.com/page/Api_terms_of_use) and Branding Requirements (http://developer.netflix.com/docs/Branding).
Usage
This module provides access to the REST API via perl syntactical sugar. For example, to find a user's queue, the REST url is of the form users/userID/feeds :
http://api.netflix.com/users/T1tareQFowlmc8aiTEXBcQ5aed9h_Z8zdmSX1SnrKoOCA-/queues/disc
Using this module, the syntax would be:
$netflix->REST->Users->Queues->Disc;
$netflix->Get(%$params) or die;
print $netflix->content;
Other examples include:
$netflix->REST->Users;
$netflix->REST->Users->At_Home;
$netflix->REST->Catalog->Titles->Movies('18704531');
$netflix->REST->Users->Feeds;
$netflix->REST->Users->Rental_History;
All of the possibilities (and parameter details) are outlined here: http://developer.netflix.com/docs/REST_API_Reference
There is a helper method "rest2sugar" included that will provide the proper syntax given a url. This is handy for translating the example urls in the REST API Reference.
Resources
The following describe the authentication that's happening under the hood and were used heavily in writing this module:
http://developer.netflix.com/docs/Security
http://josephsmarr.com/2008/10/01/using-netflixs-new-api-a-step-by-step-guide/#
EXAMPLES
The examples/ directory in the distribution has several examples to use as starting points.
METHODS
new
This is the constructor. Takes a hashref of "ATTRIBUTES". Inherited from Class::Accessor.
Most important options to pass are the "consumer_key" and "consumer_secret".
REST
This is used to change the resource that is being accessed. Some examples:
# The user-friendly way:
$netflix->REST->Users->Feeds;
# Including numeric parts:
$netflix->REST->Catalog->Titles->Movies('60021896');
# Load a pre-formed url (e.g. a title_ref from a previous query)
$netflix->REST('http://api.netflix.com/users/T1tareQFowlmc8aiTEXBcQ5aed9h_Z8zdmSX1SnrKoOCA-/queues/disc?feed_token=T1u.tZSbY9311F5W0C5eVQXaJ49.KBapZdwjuCiUBzhoJ_.lTGnmES6JfOZbrxsFzf&oauth_consumer_key=v9s778n692e9qvd83wfj9t8c&output=atom');
RequestAccess
This is used to login as a netflix user in order to get an access token.
my ($access_token, $access_secret, $user_id) = $netflix->RequestAccess( $user, $pass );
Get
Post
Delete
rest2sugar
ATTRIBUTES
consumer_key
consumer_secret
access_token
access_secret
user_id
content_filter
The content returned by the REST calls is POX (plain old XML). Setting this attribute to a code ref will cause the content to be "piped" through it.
use XML::Simple;
$netflix->content_filter( sub { XMLin(@_) } ); # Parse the XML into a perl data structure
content
Read-Only.
original_content
Read-Only.
content_error
Read-Only.
url
Read-Only.
rest_url
Read-Only.
INTERNAL
_url
_params
_levels
_submit
__get_token_response
__get_request_token
__get_access_token
WWW::Netflix::API::_UrlAppender
AUTHOR
David Westbrook (CPAN: davidrw), <dwestbrook at gmail.com>
BUGS
Please report any bugs or feature requests to bug-www-netflix-api at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Netflix-API. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc WWW::Netflix::API
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
COPYRIGHT & LICENSE
Copyright 2008 David Westbrook, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.