kino/src/Request.hs

25 lines
630 B
Haskell
Raw Normal View History

2021-09-05 19:30:29 +02:00
{-# LANGUAGE OverloadedStrings #-}
module Request where
import JSONTypes
import Network.Wreq
import Control.Lens
import Data.Aeson
import Data.Text as T
import Data.Aeson.Lens (key, nth)
import qualified Data.ByteString.Lazy.Internal as BL
testFunc :: IO (JSONResponse JSONListMovies)
testFunc = do
r <- asJSON =<< get "https://yts.mx/api/v2/list_movies.json"
pure $ r ^. responseBody
getMovies :: IO (Either T.Text JSONListMovies)
getMovies = do
r <- asJSON =<< get "https://yts.mx/api/v2/list_movies.json"
pure $ case (r ^. responseBody) of
(JSONResponse "ok" _ d) -> Right d
(JSONResponse _ m _) -> Left m