Browse Source

Moving things around and updating the documentation

tags/v0.2.2.0
Peter J. Jones 4 years ago
parent
commit
afa6bd0e75

+ 7
- 2
example/Main.hs View File

@@ -10,7 +10,7 @@ contained in the LICENSE file.
-}

--------------------------------------------------------------------------------
module Main where
module Main (main) where

--------------------------------------------------------------------------------
import Control.Monad.IO.Class (liftIO)
@@ -26,7 +26,7 @@ import System.Locale (defaultTimeLocale)
import Text.Printf (printf)

--------------------------------------------------------------------------------
-- | Simple banner style printing of a 'Movie'.
printMovieHeader :: Movie -> IO ()
printMovieHeader m =
printf "%8d: %s (%s)\n" (movieID m) (movieTitle m) year
@@ -35,7 +35,7 @@ printMovieHeader m =
Nothing -> "----"

--------------------------------------------------------------------------------
-- | Print more detailed information for a 'Movie'.
printMovieDetails :: Movie -> IO ()
printMovieDetails m =
do putStrLn $ "Popularity: " ++ show (moviePopularity m)
@@ -45,12 +45,14 @@ printMovieDetails m =
where strJoin = intercalate ", "

--------------------------------------------------------------------------------
-- | Search for movies with a query string.
searchAndListMovies :: Text -> TheMovieDB ()
searchAndListMovies query = do
movies <- search query
liftIO $ mapM_ printMovieHeader movies

--------------------------------------------------------------------------------
-- | Find a specific movie given its ID.
fetchAndPrintMovie :: MovieID -> TheMovieDB ()
fetchAndPrintMovie mid = do
cfg <- config
@@ -62,12 +64,13 @@ fetchAndPrintMovie mid = do
printMovieDetails movie

--------------------------------------------------------------------------------
-- | Low budget command line parsing and dispatch.
main :: IO ()
main = do
args <- getArgs
let key = maybe T.empty T.pack (listToMaybe args)

result <- runTheMovieDB key $ do
result <- runTheMovieDB key $
case args of
[_, "search", query] -> searchAndListMovies (T.pack query)
[_, "fetch", mid] -> fetchAndPrintMovie (read mid)

+ 8
- 29
src/Network/API/TheMovieDB.hs View File

@@ -15,52 +15,31 @@ This library provides some data types and functions for fetching movie
metadata from <http://TheMovieDB.org>. To use this library start by
requesting an API key from <http://docs.themoviedb.apiary.io>.

A typical workflow while using this library is:

1. Place an API 'Key' inside a 'Context' using 'mkContext' or one of
the utility functions in "Network.API.TheMovieDB.Util".

2. Retrieve API 'Configuration' information using either the
'config' function or the 'configErr' function.

3. Search TheMovieDB using either the 'search' function or the
'searchErr' function.

4. Since the search functions don't return a full 'Movie' record
follow them up with the 'fetch' function or the 'fetchErr'
function.

This library also includes an example executable in the @example@
directory.
-}
module Network.API.TheMovieDB
( -- * Types
-- ** TheMovieDB Metadata
TheMovieDB
, Configuration
, Movie(..)
Movie(..)
, Genre(..)

-- ** Errors
, Error(..)

-- ** Type Synonyms
, Key
, MovieID
, GenreID

-- * API Functions
, config
, TheMovieDB
, runTheMovieDB
, runTheMovieDBWithManager
, fetch
, search

-- * Utility functions
-- * Utility Types and Functions
, Configuration
, config
, moviePosterURLs
, runTheMovieDB
, runTheMovieDBWithManager
) where

import Network.API.TheMovieDB.Types
import Network.API.TheMovieDB.Config
import Network.API.TheMovieDB.Fetch
import Network.API.TheMovieDB.Search
import Network.API.TheMovieDB.Action

src/Network/API/TheMovieDB/Search.hs → src/Network/API/TheMovieDB/Action.hs View File

@@ -12,8 +12,9 @@ contained in the LICENSE file.
-}

--------------------------------------------------------------------------------
module Network.API.TheMovieDB.Search
( search
module Network.API.TheMovieDB.Action
( fetch
, search
) where

--------------------------------------------------------------------------------
@@ -23,6 +24,11 @@ import Network.API.TheMovieDB.Internal.SearchResults
import Network.API.TheMovieDB.Internal.TheMovieDB
import Network.API.TheMovieDB.Types

--------------------------------------------------------------------------------
-- | Fetch the metadata for the movie with the given ID.
fetch :: MovieID -> TheMovieDB Movie
fetch mid = getAndParse ("movie/" ++ show mid) []

--------------------------------------------------------------------------------
-- | Internal function to translate search results to a list of movies.
fetchSearchResults :: Text -> TheMovieDB SearchResults

+ 0
- 23
src/Network/API/TheMovieDB/Fetch.hs View File

@@ -1,24 +0,0 @@
{-

This file is part of the Haskell package themoviedb. It is subject to
the license terms in the LICENSE file found in the top-level directory
of this distribution and at git://pmade.com/themoviedb/LICENSE. No
part of themoviedb package, including this file, may be copied,
modified, propagated, or distributed except according to the terms
contained in the LICENSE file.

-}

--------------------------------------------------------------------------------
module Network.API.TheMovieDB.Fetch
( fetch
) where

--------------------------------------------------------------------------------
import Network.API.TheMovieDB.Internal.TheMovieDB
import Network.API.TheMovieDB.Types

--------------------------------------------------------------------------------
fetch :: MovieID -> TheMovieDB Movie
fetch mid = getAndParse ("movie/" ++ show mid) []

src/Network/API/TheMovieDB/Types/Configuration.hs → src/Network/API/TheMovieDB/Internal/Configuration.hs View File

@@ -12,8 +12,9 @@ contained in the LICENSE file.
-}

--------------------------------------------------------------------------------
module Network.API.TheMovieDB.Types.Configuration
( Configuration(..)
-- | Internal configuration information for TheMovieDB API.
module Network.API.TheMovieDB.Internal.Configuration
( Configuration (..)
) where

--------------------------------------------------------------------------------
@@ -24,8 +25,8 @@ import Data.Aeson
-- | 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' 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'.

+ 3
- 3
src/Network/API/TheMovieDB/Internal/TheMovieDB.hs View File

@@ -42,16 +42,16 @@ type RequestFunction = (Path -> QueryText -> IO (Either Error Body))
-- | Result type for operations involving TheMovieDB API.
newtype TheMovieDB a =
TheMovieDB {unTMDB :: ReaderT RequestFunction (EitherT Error IO) a}
deriving (Functor, Applicative, Monad, MonadIO, MonadReader RequestFunction)
deriving (Functor, Applicative, Monad, MonadIO)

--------------------------------------------------------------------------------
-- | Helper function for making a request using the request function
-- stashed away in the reader monad.
runRequest :: Path -> QueryText -> TheMovieDB Body
runRequest path params = do
runRequest path params = TheMovieDB $ do
func <- ask
result <- liftIO (func path params)
TheMovieDB $ lift $ hoistEither result
lift (hoistEither result)

--------------------------------------------------------------------------------
-- | Helper function to preform an HTTP GET and decode the JSON result.

+ 1
- 1
src/Network/API/TheMovieDB/Types.hs View File

@@ -26,6 +26,6 @@ module Network.API.TheMovieDB.Types

import Network.API.TheMovieDB.Internal.TheMovieDB
import Network.API.TheMovieDB.Internal.Types
import Network.API.TheMovieDB.Types.Configuration
import Network.API.TheMovieDB.Internal.Configuration
import Network.API.TheMovieDB.Types.Genre
import Network.API.TheMovieDB.Types.Movie

+ 1
- 1
src/Network/API/TheMovieDB/Types/Movie.hs View File

@@ -22,8 +22,8 @@ module Network.API.TheMovieDB.Types.Movie
import Control.Applicative
import Data.Aeson
import Data.Time (Day (..))
import Network.API.TheMovieDB.Internal.Configuration
import Network.API.TheMovieDB.Internal.ReleaseDate
import Network.API.TheMovieDB.Types.Configuration
import Network.API.TheMovieDB.Types.Genre

--------------------------------------------------------------------------------

+ 2
- 3
themoviedb.cabal View File

@@ -40,16 +40,15 @@ flag maintainer
library
exposed-modules:
Network.API.TheMovieDB
Network.API.TheMovieDB.Action
Network.API.TheMovieDB.Config
Network.API.TheMovieDB.Fetch
Network.API.TheMovieDB.Internal.Configuration
Network.API.TheMovieDB.Internal.HTTP
Network.API.TheMovieDB.Internal.ReleaseDate
Network.API.TheMovieDB.Internal.SearchResults
Network.API.TheMovieDB.Internal.TheMovieDB
Network.API.TheMovieDB.Internal.Types
Network.API.TheMovieDB.Search
Network.API.TheMovieDB.Types
Network.API.TheMovieDB.Types.Configuration
Network.API.TheMovieDB.Types.Genre
Network.API.TheMovieDB.Types.Movie


Loading…
Cancel
Save