{-This file is part of the Haskell package themoviedb. It is subject tothe license terms in the LICENSE file found in the top-level directoryof this distribution and at git://pmade.com/themoviedb/LICENSE. Nopart of themoviedb package, including this file, may be copied,modified, propagated, or distributed except according to the termscontained in the LICENSE file.-}module Network.API.TheMovieDB.HTTP ( apiGET ) whereimport Network.API.TheMovieDB.Types.APIimport qualified Network.HTTP as Himport Network.URI-- The base URL for the version of the API we're using.apiBaseURL :: StringapiBaseURL = "http://api.themoviedb.org/3/"-- Build a Network.HTTP.Request that can be used to access the API.mkAPIRequest :: Key -> Path -> Params -> H.Request BodymkAPIRequest key path params = case parseURI url of Nothing -> error ("generated an invalid URI: " ++ url) Just uri -> H.insertHeaders headers $ request uri where query = H.urlEncodeVars $ params ++ [("api_key", key)] url = apiBaseURL ++ path ++ "?" ++ query headers = [H.Header H.HdrAccept "application/json"] request = H.mkRequest H.GET-- Build a URL and do an HTTP GET to TheMovieDB.apiGET :: Key -> Path -> Params -> IO ResponseapiGET key path params = do result <- H.simpleHTTP $ mkAPIRequest key path params return $ case result of Left err -> Left $ NetworkError (show err) Right r -> Right $ H.rspBody r