module Network.API.TheMovieDB.Actions
( searchMovies,
fetchMovie,
searchTV,
fetchTV,
fetchTVSeason,
fetchFullTVSeries,
config,
)
where
import Network.API.TheMovieDB.Internal.Configuration
import Network.API.TheMovieDB.Internal.SearchResults
import Network.API.TheMovieDB.Internal.TheMovieDB
import Network.API.TheMovieDB.Internal.Types
import Network.API.TheMovieDB.Types.Movie
import Network.API.TheMovieDB.Types.Season
import Network.API.TheMovieDB.Types.TV
searchMovies :: Text -> TheMovieDB [Movie]
searchMovies :: Text -> TheMovieDB [Movie]
searchMovies Text
query = SearchResults Movie -> [Movie]
forall a. SearchResults a -> [a]
searchResults (SearchResults Movie -> [Movie])
-> TheMovieDB (SearchResults Movie) -> TheMovieDB [Movie]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TheMovieDB (SearchResults Movie)
search
where
search :: TheMovieDB (SearchResults Movie)
search = Path -> QueryText -> TheMovieDB (SearchResults Movie)
forall a. FromJSON a => Path -> QueryText -> TheMovieDB a
getAndParse Path
"search/movie" [(Text
"query", Text -> Maybe Text
forall a. a -> Maybe a
Just Text
query)]
fetchMovie ::
ItemID ->
TheMovieDB Movie
fetchMovie :: ItemID -> TheMovieDB Movie
fetchMovie ItemID
mid = Path -> QueryText -> TheMovieDB Movie
forall a. FromJSON a => Path -> QueryText -> TheMovieDB a
getAndParse (Path
"movie/" Path -> Path -> Path
forall a. [a] -> [a] -> [a]
++ ItemID -> Path
forall b a. (Show a, IsString b) => a -> b
show ItemID
mid) []
searchTV :: Text -> TheMovieDB [TV]
searchTV :: Text -> TheMovieDB [TV]
searchTV Text
query = SearchResults TV -> [TV]
forall a. SearchResults a -> [a]
searchResults (SearchResults TV -> [TV])
-> TheMovieDB (SearchResults TV) -> TheMovieDB [TV]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TheMovieDB (SearchResults TV)
search
where
search :: TheMovieDB (SearchResults TV)
search = Path -> QueryText -> TheMovieDB (SearchResults TV)
forall a. FromJSON a => Path -> QueryText -> TheMovieDB a
getAndParse Path
"search/tv" [(Text
"query", Text -> Maybe Text
forall a. a -> Maybe a
Just Text
query)]
fetchTV ::
ItemID ->
TheMovieDB TV
fetchTV :: ItemID -> TheMovieDB TV
fetchTV ItemID
i = Path -> QueryText -> TheMovieDB TV
forall a. FromJSON a => Path -> QueryText -> TheMovieDB a
getAndParse (Path
"tv/" Path -> Path -> Path
forall a. [a] -> [a] -> [a]
++ ItemID -> Path
forall b a. (Show a, IsString b) => a -> b
show ItemID
i) []
fetchTVSeason ::
ItemID ->
Int ->
TheMovieDB Season
fetchTVSeason :: ItemID -> ItemID -> TheMovieDB Season
fetchTVSeason ItemID
i ItemID
n = Path -> QueryText -> TheMovieDB Season
forall a. FromJSON a => Path -> QueryText -> TheMovieDB a
getAndParse (Path
"tv/" Path -> Path -> Path
forall a. [a] -> [a] -> [a]
++ ItemID -> Path
forall b a. (Show a, IsString b) => a -> b
show ItemID
i Path -> Path -> Path
forall a. [a] -> [a] -> [a]
++ Path
"/season/" Path -> Path -> Path
forall a. [a] -> [a] -> [a]
++ ItemID -> Path
forall b a. (Show a, IsString b) => a -> b
show ItemID
n) []
fetchFullTVSeries ::
ItemID ->
TheMovieDB TV
fetchFullTVSeries :: ItemID -> TheMovieDB TV
fetchFullTVSeries ItemID
i = do
TV
tv <- ItemID -> TheMovieDB TV
fetchTV ItemID
i
[Season]
seasons <- (Season -> TheMovieDB Season) -> [Season] -> TheMovieDB [Season]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (ItemID -> ItemID -> TheMovieDB Season
fetchTVSeason ItemID
i (ItemID -> TheMovieDB Season)
-> (Season -> ItemID) -> Season -> TheMovieDB Season
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Season -> ItemID
seasonNumber) (TV -> [Season]
tvSeasons TV
tv)
TV -> TheMovieDB TV
forall (m :: * -> *) a. Monad m => a -> m a
return TV
tv {tvSeasons :: [Season]
tvSeasons = [Season]
seasons}
config :: TheMovieDB Configuration
config :: TheMovieDB Configuration
config = Path -> QueryText -> TheMovieDB Configuration
forall a. FromJSON a => Path -> QueryText -> TheMovieDB a
getAndParse Path
"configuration" []