| Safe Haskell | None |
|---|
Network.API.TheMovieDB
Contents
Description
This library provides some data types and functions for fetching movie metadata from http://TheMovieDB.com. To use this library start by requesting an API key from http://docs.themoviedb.apiary.io.
A typical workflow while using this library is:
- Place an API
Keyinside aContextusingmkContextor one of the utility functions in Network.API.TheMovieDB.Util. - Retrieve API
Configurationinformation using either theconfigfunction or theconfigErrfunction. - Search TheMovieDB using either the
searchfunction or thesearchErrfunction. - Since the search functions don't return a full
Movierecord follow them up with thefetchfunction or thefetchErrfunction.
This library also includes an example executable in the example
directory.
- data Configuration
- data Movie = Movie {}
- data Genre = Genre {}
- data Context
- data Error
- type Key = String
- type MovieID = Int
- type GenreID = Int
- type SearchQuery = String
- config :: Context -> IO Configuration
- fetch :: Context -> MovieID -> IO Movie
- search :: Context -> SearchQuery -> IO [Movie]
- configErr :: Context -> IO (Either Error Configuration)
- fetchErr :: Context -> MovieID -> IO (Either Error Movie)
- searchErr :: Context -> SearchQuery -> IO (Either Error [Movie])
- mkContext :: Key -> Context
- apiKey :: Context -> Key
- moviePosterURLs :: Configuration -> Movie -> [String]
Types
TheMovieDB Metadata
data Configuration Source
TheMovieDB API tries to preserve bandwidth by omitting
information (such as full URLs for poster images) from most of the
API calls. Therefore in order to construct a complete URL for a
movie poster you'll need to use the config or configErr
function to retrieve API configuration information.
A helper function is provided (moviePosterURLs) that constructs a
list of all poster URLs given a Movie and Configuration.
Instances
Metadata for a movie.
- The
moviePosterPathis an incomplete URL. To construct a complete URL you'll need to use theConfigurationtype. You can also usemoviePosterURLs.
Constructors
| Movie | |
Fields
| |
Metadata for a genre.
Constructors
| Genre | |
Context and Errors
Possible errors returned by the API.
Constructors
| NetworkError String | Network or HTTP error. |
| ParseError String | Invalid or error response from the API. |
Type Synonyms
type SearchQuery = StringSource
A search query for TheMovieDB API.
API Functions
Functions That Fail
config :: Context -> IO ConfigurationSource
Fetch the API configuration information or fail. For a function
that returns an error instead of failing see configErr.
fetch :: Context -> MovieID -> IO MovieSource
Fetch the metadata for the movie with the given ID and fail if
any errors are encountered along the way. For a function that
returns an error instead of failing see fetchErr.
search :: Context -> SearchQuery -> IO [Movie]Source
Search TheMovieDB using the given query string and return a list
of movies. This function fails if there are any errors. For a
function that returns an error instead of failing see searchErr.
The movies returned will not have all their fields completely
filled out, to get a complete record you'll need to follow this
call up with a call to fetchErr or fetch.
Functions That Return Errors
configErr :: Context -> IO (Either Error Configuration)Source
Fetch the API configuration information such as base URLs for
movie posters. Results in either an Error or a Configuration.
Utility functions
moviePosterURLs :: Configuration -> Movie -> [String]Source
Return a list of URLs for all possible movie posters.