Wednesday, October 12, 2011

Dropbox Updates Have Landed

Just wanted to let you guys know that I have made some updates to the Dropbox API Library. These changes are in reaction to the new functionality available in the new Dropbox API. There are a few new methods and I removed the link method. I will outline the changes below.

Here is the Github Repo

I did make some changes to some of the existing methods. The now accept an array of parameters so that you can specify different parameters that can be passed to the API. There were a few new methods that were added, they are as follows:
revisions($path, array $params = array(), $root='dropbox')
restore($path, $revision, $root='dropbox')
search($path, $query, array $params = array(), $root='dropbox')
shares($path, $root='dropbox')
media($path, $root='dropbox')
The revisions method
revisions($path, array $params = array(), $root='dropbox')
Will return an array of revisions for a particular file or the revisions of files in a particular folder.

The restore method
restore($path, $revision, $root='dropbox')
Will roll a particular file back to a previous revision. Specify the revision by using the 'rev' hash that is returned when you make a call to the revisions method.

The search method
search($path, $query, array $params = array(), $root='dropbox')
Will search a particular path in your dropbox folders for any files that match the query.

The shares and media methods have replaced the link method.
shares($path, $root='dropbox')
media($path, $root='dropbox')
Both methods link to a file in dropbox the difference is that media links directly to the file and should be used for things link streaming. Shares creates a new link to a file and is more geared towards publicly displaying your content. Both calls also return an expiration date which indicate when the link will become invalid.

As always if you have any questions or problems post them in the comments but as it stands right now things seem to be pretty stable.

Sunday, October 2, 2011

Probably bad timing but here is the netflix API I promised.

Well I finally finished the netflix api I promised. Sorry for the delay it just took time to get motivated to finish it. Since I waited it probably doesn't have near the interest that it might have, had netflix not made the silly choices they did.

Anyway without further ado here is the netflix api.

Here is the github repo for it.

As with the other APIs you need to have a developer key for your application so head over to the netflix development docs to register an account and get an API key and secret. Put those values into a config so that they can be included when you initialize the library. Next download the api files and put them in your application directory.

Once they are in place you need to authenticate the API with a netflix account. We do this using OAuth. Checkout the included example controller for how to implement your request and access methods.

Use the oauth access token and token secret to make authenticated requests to the api. This token is a long lived token so you should only need to generate one per netflix user.

Now you can use every method in the library, but I have to warn you the Netflix API responses are XML and are complex. It is by far the most difficult API to work with as many of the requests require data from other requests in order to function properly. We will start with some of the most basic.

$this->netflix->search_title('Jurassic Park');

This command will do a search on the specified title which in this case is the amazing movie "Jurassic Park". No further parameters are needed but the returned data isn't all that useful.

Next we will look at the command to get data on the currently authenticated user.

$this->netflix->get_user();

This command is very important as it will return the ID netflix provides for each user. This ID can be used in future API calls for tasks like managing the users queue. Using this ID we can now make a call to:

$this->netflix->get_queues($id, $type);

This will return all of the titles in the users queue. Use the $type parameter to specify if you want the instant queue or the disc queue. One thing to really keep track of when you are working with a users queue is the returned etag. This is a value that is returned in the XML response that is used to maintain concurrency when managing the queue. Every call to a queue management function will have an etag in the response.

Say you want to add a title to your queue.

$this->netflix->add_queue_entry($id, 'disc', 'http://api.netflix.com/catalog/titles/movies/60002360', $etag);

This will add the title Jurassic Park to your disc queue provided to specified the correct $id for the user and the correct $etag value. There is an optional 5th parameter that lets you specify the position in the queue of the movie.

Now I know what you are thinking: 'Where the crap does he get Jurassic Park from that URL?' Well you have to get that data from another request like search_title. Like I said Netflix doesn't make it easy to use their API.

That is just a taste of what this library can do, it isn't the easiest API to work with unfortunately but it is functional and you can get around in it if you know what you are doing. Now because of that I highly recommend reading the Netflix API documentation you can find it here. It outlines all of the methods this library uses as well as all of the additional parameters you can specify for each call.

Here is a list of all of the currently available methods in the library.

$this->netflix->search_title($title, array $params = array());
$this->netflix->search_title_autocomplete($title);
$this->netflix->all_titles(array $params = array());
$this->netflix->get_title_details($id, $type, $season = false);
$this->netflix->get_title_similars($id, $type, $season = false, array $params = array());
$this->netflix->search_people($name, array $params = array());
$this->netflix->get_person_details($id);
$this->netflix->get_user($id = 'current');
$this->netflix->get_user_feeds($id, array $params = array());
$this->netflix->get_user_title_states($id, array $params = array());
$this->netflix->get_queues($id, $type = '', array $params = array());
$this->netflix->get_queue_state($id, $type, $state, $entry = '', array $params = array());
$this->netflix->remove_queue_entry($id, $type, $state, $entry);
$this->netflix->add_queue_entry($id, $type, $title_ref, $etag, $position = '1');
$this->netflix->get_rental_history($id, $instant_watched = false, array $params = array());
$this->netflix->get_title_rating($id, $title_refs, $predicted = false);
$this->netflix->set_title_rating($id, $title_ref, $rating, $ratingId = false);
$this->netflix->get_recommendations($id, array $params = array());

As always if you have any questions just leave a comment and I will do my best to help you out.