module Network.API.TheMovieDB.Internal.Settings
( Settings (..),
defaultSettings,
)
where
import qualified Data.Aeson as Aeson
import Network.API.TheMovieDB.Internal.Types
data Settings = Settings
{
Settings -> Key
tmdbKey :: Key,
Settings -> Maybe Key
tmdbLanguage :: Maybe LanguageCode
}
instance Aeson.FromJSON Settings where
parseJSON :: Value -> Parser Settings
parseJSON = forall a. String -> (Object -> Parser a) -> Value -> Parser a
Aeson.withObject String
"Settings" forall a b. (a -> b) -> a -> b
$ \Object
v ->
Key -> Maybe Key -> Settings
Settings
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
v forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"key"
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object
v forall a. FromJSON a => Object -> Key -> Parser a
Aeson..: Key
"lang"
instance Aeson.ToJSON Settings where
toJSON :: Settings -> Value
toJSON Settings {Maybe Key
Key
tmdbLanguage :: Maybe Key
tmdbKey :: Key
tmdbLanguage :: Settings -> Maybe Key
tmdbKey :: Settings -> Key
..} =
[Pair] -> Value
Aeson.object
[ Key
"key" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Aeson..= Key
tmdbKey,
Key
"lang" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Aeson..= Maybe Key
tmdbLanguage
]
defaultSettings :: Key -> Settings
defaultSettings :: Key -> Settings
defaultSettings Key
key =
Settings
{ tmdbKey :: Key
tmdbKey = Key
key,
tmdbLanguage :: Maybe Key
tmdbLanguage = forall a. Maybe a
Nothing
}