    {-# LANGUAGE OverloadedStrings #-}
    {-# LANGUAGE GeneralizedNewtypeDeriving#-}
    {-# LANGUAGE StandaloneDeriving#-}
    {-# LANGUAGE GADTs#-}
    {-# LANGUAGE DeriveDataTypeable#-}
    {-# LANGUAGE CPP#-}

    module Facebook.Types
      ( Credentials(..)
      , ApiVersion
      , appIdBS
      , appSecretBS
      , AccessToken(..)
      , UserAccessToken
      , AppAccessToken
      , AccessTokenData
      , Id(..)
      , UserId
      , accessTokenData
      , accessTokenExpires
      , accessTokenUserId
      , UserKind
      , AppKind
      , Argument
      , (<>)
      , FbUTCTime(..)
      , FacebookException(..)
      ) where

    import Control.Applicative ((<$>), (<*>), pure)
    import Control.Monad (mzero)
    import qualified UnliftIO.Exception as E
    import Data.ByteString (ByteString)
    import Data.Int (Int64)
    #if !(MIN_VERSION_base(4,11,0))
    import Data.Monoid (Monoid, mappend)
    #endif
    import Data.String (IsString)
    import Data.Text (Text)
    import Data.Time (UTCTime)
    import Data.Time.Clock.POSIX (posixSecondsToUTCTime)
    import Data.Typeable (Typeable)
    #if MIN_VERSION_time(1,5,0)
    import Data.Time (defaultTimeLocale, parseTimeM)
    #else
    import System.Locale (defaultTimeLocale)
    import Data.Time (parseTime)
    #endif
    import qualified Data.Aeson as A
    import qualified Data.Aeson.Types as A
    import qualified Data.Text as T
    import qualified Data.Text.Encoding as TE
    import qualified Data.Text.Lazy as TL
    import qualified Data.Text.Lazy.Builder as TLB
    import qualified Data.Text.Lazy.Builder.Int as TLBI

    -- | Credentials that you get for your app when you register on
    -- Facebook.
    data Credentials = Credentials
      { Credentials -> AccessTokenData
    appName :: Text -- ^ Your application name (e.g. for Open Graph calls).
      , Credentials -> AccessTokenData
    appId :: Text -- ^ Your application ID.
      , Credentials -> AccessTokenData
    appSecret :: Text -- ^ Your application secret key.
      , Credentials -> Bool
    appSecretProof :: Bool -- ^ To enable app secret proof verification
      } deriving (Credentials -> Credentials -> Bool
    (Credentials -> Credentials -> Bool)
    -> (Credentials -> Credentials -> Bool) -> Eq Credentials
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Credentials -> Credentials -> Bool
    == :: Credentials -> Credentials -> Bool
    $c/= :: Credentials -> Credentials -> Bool
    /= :: Credentials -> Credentials -> Bool
    Eq, Eq Credentials
    Eq Credentials
    -> (Credentials -> Credentials -> Ordering)
    -> (Credentials -> Credentials -> Bool)
    -> (Credentials -> Credentials -> Bool)
    -> (Credentials -> Credentials -> Bool)
    -> (Credentials -> Credentials -> Bool)
    -> (Credentials -> Credentials -> Credentials)
    -> (Credentials -> Credentials -> Credentials)
    -> Ord Credentials
    Credentials -> Credentials -> Bool
    Credentials -> Credentials -> Ordering
    Credentials -> Credentials -> Credentials
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Credentials -> Credentials -> Ordering
    compare :: Credentials -> Credentials -> Ordering
    $c< :: Credentials -> Credentials -> Bool
    < :: Credentials -> Credentials -> Bool
    $c<= :: Credentials -> Credentials -> Bool
    <= :: Credentials -> Credentials -> Bool
    $c> :: Credentials -> Credentials -> Bool
    > :: Credentials -> Credentials -> Bool
    $c>= :: Credentials -> Credentials -> Bool
    >= :: Credentials -> Credentials -> Bool
    $cmax :: Credentials -> Credentials -> Credentials
    max :: Credentials -> Credentials -> Credentials
    $cmin :: Credentials -> Credentials -> Credentials
    min :: Credentials -> Credentials -> Credentials
    Ord, Int -> Credentials -> ShowS
    [Credentials] -> ShowS
    Credentials -> String
    (Int -> Credentials -> ShowS)
    -> (Credentials -> String)
    -> ([Credentials] -> ShowS)
    -> Show Credentials
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Credentials -> ShowS
    showsPrec :: Int -> Credentials -> ShowS
    $cshow :: Credentials -> String
    show :: Credentials -> String
    $cshowList :: [Credentials] -> ShowS
    showList :: [Credentials] -> ShowS
    Show, ReadPrec [Credentials]
    ReadPrec Credentials
    Int -> ReadS Credentials
    ReadS [Credentials]
    (Int -> ReadS Credentials)
    -> ReadS [Credentials]
    -> ReadPrec Credentials
    -> ReadPrec [Credentials]
    -> Read Credentials
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS Credentials
    readsPrec :: Int -> ReadS Credentials
    $creadList :: ReadS [Credentials]
    readList :: ReadS [Credentials]
    $creadPrec :: ReadPrec Credentials
    readPrec :: ReadPrec Credentials
    $creadListPrec :: ReadPrec [Credentials]
    readListPrec :: ReadPrec [Credentials]
    Read, Typeable)

    -- | 'appId' for 'ByteString'.
    appIdBS :: Credentials -> ByteString
    appIdBS :: Credentials -> ByteString
    appIdBS = AccessTokenData -> ByteString
    TE.encodeUtf8 (AccessTokenData -> ByteString)
    -> (Credentials -> AccessTokenData) -> Credentials -> ByteString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Credentials -> AccessTokenData
    appId

    -- | 'appSecret' for 'ByteString'.
    appSecretBS :: Credentials -> ByteString
    appSecretBS :: Credentials -> ByteString
    appSecretBS = AccessTokenData -> ByteString
    TE.encodeUtf8 (AccessTokenData -> ByteString)
    -> (Credentials -> AccessTokenData) -> Credentials -> ByteString
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Credentials -> AccessTokenData
    appSecret

    -- | Graph API version.
    -- See: https://developers.facebook.com/docs/graph-api/changelog
    type ApiVersion = Text

    -- | An access token.  While you can make some API calls without
    -- an access token, many require an access token and some will
    -- give you more information with an appropriate access token.
    --
    -- There are two kinds of access tokens:
    --
    -- [User access token] An access token obtained after an user
    -- accepts your application.  Let's you access more information
    -- about that user and act on their behalf (depending on which
    -- permissions you've asked for).
    --
    -- [App access token] An access token that allows you to take
    -- administrative actions for your application.
    --
    -- These two kinds of access tokens are distinguished by the
    -- phantom type on 'AccessToken', which can be 'UserKind' or
    -- 'AppKind'.
    data AccessToken kind where
            UserAccessToken ::
              UserId -> AccessTokenData -> UTCTime -> AccessToken UserKind
            AppAccessToken :: AccessTokenData -> AccessToken AppKind

    -- | Type synonym for @'AccessToken' 'UserKind'@.
    type UserAccessToken = AccessToken UserKind

    -- | Type synonym for @'AccessToken' 'AppKind'@.
    type AppAccessToken = AccessToken AppKind

    deriving instance Eq (AccessToken kind)

    deriving instance Ord (AccessToken kind)

    deriving instance Show (AccessToken kind)

    deriving instance Typeable AccessToken

    -- | The access token data that is passed to Facebook's API
    -- calls.
    type AccessTokenData = Text

    -- | The identification code of an object.
    newtype Id = Id
      { UserId -> AccessTokenData
    idCode :: Text
      } deriving (UserId -> UserId -> Bool
    (UserId -> UserId -> Bool)
    -> (UserId -> UserId -> Bool) -> Eq UserId
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: UserId -> UserId -> Bool
    == :: UserId -> UserId -> Bool
    $c/= :: UserId -> UserId -> Bool
    /= :: UserId -> UserId -> Bool
    Eq, Eq UserId
    Eq UserId
    -> (UserId -> UserId -> Ordering)
    -> (UserId -> UserId -> Bool)
    -> (UserId -> UserId -> Bool)
    -> (UserId -> UserId -> Bool)
    -> (UserId -> UserId -> Bool)
    -> (UserId -> UserId -> UserId)
    -> (UserId -> UserId -> UserId)
    -> Ord UserId
    UserId -> UserId -> Bool
    UserId -> UserId -> Ordering
    UserId -> UserId -> UserId
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: UserId -> UserId -> Ordering
    compare :: UserId -> UserId -> Ordering
    $c< :: UserId -> UserId -> Bool
    < :: UserId -> UserId -> Bool
    $c<= :: UserId -> UserId -> Bool
    <= :: UserId -> UserId -> Bool
    $c> :: UserId -> UserId -> Bool
    > :: UserId -> UserId -> Bool
    $c>= :: UserId -> UserId -> Bool
    >= :: UserId -> UserId -> Bool
    $cmax :: UserId -> UserId -> UserId
    max :: UserId -> UserId -> UserId
    $cmin :: UserId -> UserId -> UserId
    min :: UserId -> UserId -> UserId
    Ord, Int -> UserId -> ShowS
    [UserId] -> ShowS
    UserId -> String
    (Int -> UserId -> ShowS)
    -> (UserId -> String) -> ([UserId] -> ShowS) -> Show UserId
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> UserId -> ShowS
    showsPrec :: Int -> UserId -> ShowS
    $cshow :: UserId -> String
    show :: UserId -> String
    $cshowList :: [UserId] -> ShowS
    showList :: [UserId] -> ShowS
    Show, ReadPrec [UserId]
    ReadPrec UserId
    Int -> ReadS UserId
    ReadS [UserId]
    (Int -> ReadS UserId)
    -> ReadS [UserId]
    -> ReadPrec UserId
    -> ReadPrec [UserId]
    -> Read UserId
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS UserId
    readsPrec :: Int -> ReadS UserId
    $creadList :: ReadS [UserId]
    readList :: ReadS [UserId]
    $creadPrec :: ReadPrec UserId
    readPrec :: ReadPrec UserId
    $creadListPrec :: ReadPrec [UserId]
    readListPrec :: ReadPrec [UserId]
    Read, Typeable, String -> UserId
    (String -> UserId) -> IsString UserId
    forall a. (String -> a) -> IsString a
    $cfromString :: String -> UserId
    fromString :: String -> UserId
    IsString)

    instance A.FromJSON Id where
      parseJSON :: Value -> Parser UserId
    parseJSON (A.Object Object
    v) = Object
    v Object -> Key -> Parser UserId
    forall a. FromJSON a => Object -> Key -> Parser a
    A..: Key
    "id"
      parseJSON (A.String AccessTokenData
    s) = UserId -> Parser UserId
    forall a. a -> Parser a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (UserId -> Parser UserId) -> UserId -> Parser UserId
    forall a b. (a -> b) -> a -> b
    $ AccessTokenData -> UserId
    Id AccessTokenData
    s
      parseJSON (A.Number Scientific
    d) = UserId -> Parser UserId
    forall a. a -> Parser a
    forall (f :: * -> *) a. Applicative f => a -> f a
    pure (UserId -> Parser UserId) -> UserId -> Parser UserId
    forall a b. (a -> b) -> a -> b
    $ AccessTokenData -> UserId
    Id (AccessTokenData -> UserId) -> AccessTokenData -> UserId
    forall a b. (a -> b) -> a -> b
    $ Int64 -> AccessTokenData
    from (Int64 -> AccessTokenData) -> Int64 -> AccessTokenData
    forall a b. (a -> b) -> a -> b
    $ Scientific -> Int64
    forall b. Integral b => Scientific -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    floor Scientific
    d
        where
          from :: Int64 -> AccessTokenData
    from Int64
    i = Text -> AccessTokenData
    TL.toStrict (Text -> AccessTokenData) -> Text -> AccessTokenData
    forall a b. (a -> b) -> a -> b
    $ Builder -> Text
    TLB.toLazyText (Builder -> Text) -> Builder -> Text
    forall a b. (a -> b) -> a -> b
    $ Int64 -> Builder
    forall a. Integral a => a -> Builder
    TLBI.decimal (Int64
    i :: Int64)
      parseJSON Value
    o = String -> Parser UserId
    forall a. String -> Parser a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    fail (String -> Parser UserId) -> String -> Parser UserId
    forall a b. (a -> b) -> a -> b
    $ String
    "Can't parse Facebook.Id from " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ Value -> String
    forall a. Show a => a -> String
    show Value
    o

    instance A.ToJSON Id where
      toJSON :: UserId -> Value
    toJSON (Id AccessTokenData
    t) = AccessTokenData -> Value
    A.String AccessTokenData
    t

    -- | A Facebook user ID such as @1008905713901@.
    type UserId = Id

    -- | Get the access token data.
    accessTokenData :: AccessToken anyKind -> AccessTokenData
    accessTokenData :: forall anyKind. AccessToken anyKind -> AccessTokenData
    accessTokenData (UserAccessToken UserId
    _ AccessTokenData
    d UTCTime
    _) = AccessTokenData
    d
    accessTokenData (AppAccessToken AccessTokenData
    d) = AccessTokenData
    d

    -- | Expire time of an access token.  It may never expire, in
    -- which case it will be @Nothing@.
    accessTokenExpires :: AccessToken anyKind -> Maybe UTCTime
    accessTokenExpires :: forall anyKind. AccessToken anyKind -> Maybe UTCTime
    accessTokenExpires (UserAccessToken UserId
    _ AccessTokenData
    _ UTCTime
    expt) = UTCTime -> Maybe UTCTime
    forall a. a -> Maybe a
    Just UTCTime
    expt
    accessTokenExpires (AppAccessToken AccessTokenData
    _) = Maybe UTCTime
    forall a. Maybe a
    Nothing

    -- | Get the user ID of an user access token.
    accessTokenUserId :: UserAccessToken -> UserId
    accessTokenUserId :: UserAccessToken -> UserId
    accessTokenUserId (UserAccessToken UserId
    uid AccessTokenData
    _ UTCTime
    _) = UserId
    uid

    -- | Phantom type used mark an 'AccessToken' as an user access
    -- token.
    data UserKind
      deriving (Typeable)

    -- | Phantom type used mark an 'AccessToken' as an app access
    -- token.
    data AppKind
      deriving (Typeable)

    -- | An argument given to an API call.
    type Argument = (ByteString, ByteString)

    -- | Synonym for 'mappend'.
    #if !(MIN_VERSION_base(4,11,0))
    (<>)
      :: Monoid a
      => a -> a -> a
    (<>) = mappend
    #endif

    ----------------------------------------------------------------------
    -- | /Since 0.14.9./ Not a Facebook JSON format, but a custom @fb@
    -- format for convenience if you need to serialize access tokens.
    instance A.ToJSON (AccessToken kind) where
      toJSON :: AccessToken kind -> Value
    toJSON (UserAccessToken UserId
    uid AccessTokenData
    data_ UTCTime
    expires) =
        [Pair] -> Value
    A.object
          [ Key
    "kind" Key -> AccessTokenData -> Pair
    forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
    forall v. ToJSON v => Key -> v -> Pair
    A..= (AccessTokenData
    "user" :: Text)
          , Key
    "id" Key -> UserId -> Pair
    forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
    forall v. ToJSON v => Key -> v -> Pair
    A..= UserId
    uid
          , Key
    "token" Key -> AccessTokenData -> Pair
    forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
    forall v. ToJSON v => Key -> v -> Pair
    A..= AccessTokenData
    data_
          , Key
    "expires" Key -> UTCTime -> Pair
    forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
    forall v. ToJSON v => Key -> v -> Pair
    A..= UTCTime
    expires
          ]
      toJSON (AppAccessToken AccessTokenData
    data_) =
        [Pair] -> Value
    A.object [Key
    "kind" Key -> AccessTokenData -> Pair
    forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
    forall v. ToJSON v => Key -> v -> Pair
    A..= (AccessTokenData
    "app" :: Text), Key
    "token" Key -> AccessTokenData -> Pair
    forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
    forall v. ToJSON v => Key -> v -> Pair
    A..= AccessTokenData
    data_]

    -- | (Internal) Since the user of 'parseJSON' is going to choose
    -- via its @kind@ whether a 'UserAccessToken' or an
    -- 'AppAccessToken' is wanted, we need this type class to
    -- implement 'FromJSON'.
    class ParseAccessToken kind  where
      parseTokenJSON :: A.Object -> A.Parser (AccessToken kind)

    instance ParseAccessToken UserKind where
      parseTokenJSON :: Object -> Parser UserAccessToken
    parseTokenJSON Object
    v = Object
    -> AccessTokenData
    -> Parser UserAccessToken
    -> Parser UserAccessToken
    forall a. Object -> AccessTokenData -> Parser a -> Parser a
    checkKind Object
    v AccessTokenData
    "user" (Parser UserAccessToken -> Parser UserAccessToken)
    -> Parser UserAccessToken -> Parser UserAccessToken
    forall a b. (a -> b) -> a -> b
    $ UserId -> AccessTokenData -> UTCTime -> UserAccessToken
    UserAccessToken (UserId -> AccessTokenData -> UTCTime -> UserAccessToken)
    -> Parser UserId
    -> Parser (AccessTokenData -> UTCTime -> UserAccessToken)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Object
    v Object -> Key -> Parser UserId
    forall a. FromJSON a => Object -> Key -> Parser a
    A..: Key
    "id" Parser (AccessTokenData -> UTCTime -> UserAccessToken)
    -> Parser AccessTokenData -> Parser (UTCTime -> UserAccessToken)
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Object
    v Object -> Key -> Parser AccessTokenData
    forall a. FromJSON a => Object -> Key -> Parser a
    A..: Key
    "token" Parser (UTCTime -> UserAccessToken)
    -> Parser UTCTime -> Parser UserAccessToken
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Object
    v Object -> Key -> Parser UTCTime
    forall a. FromJSON a => Object -> Key -> Parser a
    A..: Key
    "expires"

    instance ParseAccessToken AppKind where
      parseTokenJSON :: Object -> Parser (AccessToken AppKind)
    parseTokenJSON Object
    v = Object
    -> AccessTokenData
    -> Parser (AccessToken AppKind)
    -> Parser (AccessToken AppKind)
    forall a. Object -> AccessTokenData -> Parser a -> Parser a
    checkKind Object
    v AccessTokenData
    "app" (Parser (AccessToken AppKind) -> Parser (AccessToken AppKind))
    -> Parser (AccessToken AppKind) -> Parser (AccessToken AppKind)
    forall a b. (a -> b) -> a -> b
    $ AccessTokenData -> AccessToken AppKind
    AppAccessToken (AccessTokenData -> AccessToken AppKind)
    -> Parser AccessTokenData -> Parser (AccessToken AppKind)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Object
    v Object -> Key -> Parser AccessTokenData
    forall a. FromJSON a => Object -> Key -> Parser a
    A..: Key
    "token"

    -- | (Internal) Used to implement 'parseTokenJSON'.
    checkKind :: A.Object -> Text -> A.Parser a -> A.Parser a
    checkKind :: forall a. Object -> AccessTokenData -> Parser a -> Parser a
    checkKind Object
    v AccessTokenData
    kind Parser a
    ok = do
      AccessTokenData
    kind' <- Object
    v Object -> Key -> Parser AccessTokenData
    forall a. FromJSON a => Object -> Key -> Parser a
    A..: Key
    "kind"
      if AccessTokenData
    kind AccessTokenData -> AccessTokenData -> Bool
    forall a. Eq a => a -> a -> Bool
    == AccessTokenData
    kind'
        then Parser a
    ok
        else String -> Parser a
    forall a. String -> Parser a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    fail (String -> Parser a) -> String -> Parser a
    forall a b. (a -> b) -> a -> b
    $
             String
    "Expected access token kind " String -> ShowS
    forall a. Semigroup a => a -> a -> a
    <> AccessTokenData -> String
    forall a. Show a => a -> String
    show AccessTokenData
    kind String -> ShowS
    forall a. Semigroup a => a -> a -> a
    <> String
    " but found " String -> ShowS
    forall a. Semigroup a => a -> a -> a
    <> AccessTokenData -> String
    forall a. Show a => a -> String
    show AccessTokenData
    kind' String -> ShowS
    forall a. Semigroup a => a -> a -> a
    <>
             String
    "."

    -- | /Since 0.14.9./ Parses the format that 'ToJSON' produces.
    -- Note that you need to statically decide whether you want to
    -- parse a user access token or an app access token.
    instance ParseAccessToken kind =>
             A.FromJSON (AccessToken kind) where
      parseJSON :: Value -> Parser (AccessToken kind)
    parseJSON (A.Object Object
    v) = Object -> Parser (AccessToken kind)
    forall kind.
    ParseAccessToken kind =>
    Object -> Parser (AccessToken kind)
    parseTokenJSON Object
    v
      parseJSON Value
    _ = Parser (AccessToken kind)
    forall a. Parser a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero

    ----------------------------------------------------------------------
    -- | @newtype@ for 'UTCTime' that follows Facebook's
    -- conventions of JSON parsing.
    --
    --  * As a string, while @aeson@ expects a format of @%FT%T%Q@,
    --    Facebook gives time values formatted as @%FT%T%z@.
    --
    --  * As a number, 'FbUTCTime' accepts a number of seconds since
    --    the Unix epoch.
    newtype FbUTCTime = FbUTCTime
      { FbUTCTime -> UTCTime
    unFbUTCTime :: UTCTime
      } deriving (FbUTCTime -> FbUTCTime -> Bool
    (FbUTCTime -> FbUTCTime -> Bool)
    -> (FbUTCTime -> FbUTCTime -> Bool) -> Eq FbUTCTime
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: FbUTCTime -> FbUTCTime -> Bool
    == :: FbUTCTime -> FbUTCTime -> Bool
    $c/= :: FbUTCTime -> FbUTCTime -> Bool
    /= :: FbUTCTime -> FbUTCTime -> Bool
    Eq, Eq FbUTCTime
    Eq FbUTCTime
    -> (FbUTCTime -> FbUTCTime -> Ordering)
    -> (FbUTCTime -> FbUTCTime -> Bool)
    -> (FbUTCTime -> FbUTCTime -> Bool)
    -> (FbUTCTime -> FbUTCTime -> Bool)
    -> (FbUTCTime -> FbUTCTime -> Bool)
    -> (FbUTCTime -> FbUTCTime -> FbUTCTime)
    -> (FbUTCTime -> FbUTCTime -> FbUTCTime)
    -> Ord FbUTCTime
    FbUTCTime -> FbUTCTime -> Bool
    FbUTCTime -> FbUTCTime -> Ordering
    FbUTCTime -> FbUTCTime -> FbUTCTime
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: FbUTCTime -> FbUTCTime -> Ordering
    compare :: FbUTCTime -> FbUTCTime -> Ordering
    $c< :: FbUTCTime -> FbUTCTime -> Bool
    < :: FbUTCTime -> FbUTCTime -> Bool
    $c<= :: FbUTCTime -> FbUTCTime -> Bool
    <= :: FbUTCTime -> FbUTCTime -> Bool
    $c> :: FbUTCTime -> FbUTCTime -> Bool
    > :: FbUTCTime -> FbUTCTime -> Bool
    $c>= :: FbUTCTime -> FbUTCTime -> Bool
    >= :: FbUTCTime -> FbUTCTime -> Bool
    $cmax :: FbUTCTime -> FbUTCTime -> FbUTCTime
    max :: FbUTCTime -> FbUTCTime -> FbUTCTime
    $cmin :: FbUTCTime -> FbUTCTime -> FbUTCTime
    min :: FbUTCTime -> FbUTCTime -> FbUTCTime
    Ord, Int -> FbUTCTime -> ShowS
    [FbUTCTime] -> ShowS
    FbUTCTime -> String
    (Int -> FbUTCTime -> ShowS)
    -> (FbUTCTime -> String)
    -> ([FbUTCTime] -> ShowS)
    -> Show FbUTCTime
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> FbUTCTime -> ShowS
    showsPrec :: Int -> FbUTCTime -> ShowS
    $cshow :: FbUTCTime -> String
    show :: FbUTCTime -> String
    $cshowList :: [FbUTCTime] -> ShowS
    showList :: [FbUTCTime] -> ShowS
    Show, ReadPrec [FbUTCTime]
    ReadPrec FbUTCTime
    Int -> ReadS FbUTCTime
    ReadS [FbUTCTime]
    (Int -> ReadS FbUTCTime)
    -> ReadS [FbUTCTime]
    -> ReadPrec FbUTCTime
    -> ReadPrec [FbUTCTime]
    -> Read FbUTCTime
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS FbUTCTime
    readsPrec :: Int -> ReadS FbUTCTime
    $creadList :: ReadS [FbUTCTime]
    readList :: ReadS [FbUTCTime]
    $creadPrec :: ReadPrec FbUTCTime
    readPrec :: ReadPrec FbUTCTime
    $creadListPrec :: ReadPrec [FbUTCTime]
    readListPrec :: ReadPrec [FbUTCTime]
    Read, Typeable)

    instance A.FromJSON FbUTCTime where
      parseJSON :: Value -> Parser FbUTCTime
    parseJSON (A.String AccessTokenData
    t) =
    #if MIN_VERSION_time(1,5,0)
        case Bool -> TimeLocale -> String -> String -> Maybe UTCTime
    forall (m :: * -> *) t.
    (MonadFail m, ParseTime t) =>
    Bool -> TimeLocale -> String -> String -> m t
    parseTimeM Bool
    True TimeLocale
    defaultTimeLocale String
    "%FT%T%z" (AccessTokenData -> String
    T.unpack AccessTokenData
    t) of
    #else
        case parseTime defaultTimeLocale "%FT%T%z" (T.unpack t) of
    #endif
          Just UTCTime
    d -> FbUTCTime -> Parser FbUTCTime
    forall a. a -> Parser a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (UTCTime -> FbUTCTime
    FbUTCTime UTCTime
    d)
          Maybe UTCTime
    _ -> String -> Parser FbUTCTime
    forall a. String -> Parser a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    fail (String -> Parser FbUTCTime) -> String -> Parser FbUTCTime
    forall a b. (a -> b) -> a -> b
    $ String
    "could not parse FbUTCTime string " String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ AccessTokenData -> String
    forall a. Show a => a -> String
    show AccessTokenData
    t
      parseJSON (A.Number Scientific
    n) =
        FbUTCTime -> Parser FbUTCTime
    forall a. a -> Parser a
    forall (m :: * -> *) a. Monad m => a -> m a
    return (FbUTCTime -> Parser FbUTCTime) -> FbUTCTime -> Parser FbUTCTime
    forall a b. (a -> b) -> a -> b
    $ UTCTime -> FbUTCTime
    FbUTCTime (UTCTime -> FbUTCTime) -> UTCTime -> FbUTCTime
    forall a b. (a -> b) -> a -> b
    $ POSIXTime -> UTCTime
    posixSecondsToUTCTime (POSIXTime -> UTCTime) -> POSIXTime -> UTCTime
    forall a b. (a -> b) -> a -> b
    $ Integer -> POSIXTime
    forall a. Num a => Integer -> a
    fromInteger (Integer -> POSIXTime) -> Integer -> POSIXTime
    forall a b. (a -> b) -> a -> b
    $ Scientific -> Integer
    forall b. Integral b => Scientific -> b
    forall a b. (RealFrac a, Integral b) => a -> b
    floor Scientific
    n
      parseJSON Value
    _ =
        String -> Parser FbUTCTime
    forall a. String -> Parser a
    forall (m :: * -> *) a. MonadFail m => String -> m a
    fail
          String
    "could not parse FbUTCTime from something which is not a string or number"

    -- | An exception that may be thrown by functions on this
    -- package.  Includes any information provided by Facebook.
    data FacebookException =
        -- | An exception coming from Facebook.
        FacebookException { FacebookException -> AccessTokenData
    fbeType    :: Text
                          , FacebookException -> AccessTokenData
    fbeMessage :: Text
                          }
        -- | An exception coming from the @fb@ package's code.
      | FbLibraryException { fbeMessage :: Text }
        deriving (FacebookException -> FacebookException -> Bool
    (FacebookException -> FacebookException -> Bool)
    -> (FacebookException -> FacebookException -> Bool)
    -> Eq FacebookException
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: FacebookException -> FacebookException -> Bool
    == :: FacebookException -> FacebookException -> Bool
    $c/= :: FacebookException -> FacebookException -> Bool
    /= :: FacebookException -> FacebookException -> Bool
    Eq, Eq FacebookException
    Eq FacebookException
    -> (FacebookException -> FacebookException -> Ordering)
    -> (FacebookException -> FacebookException -> Bool)
    -> (FacebookException -> FacebookException -> Bool)
    -> (FacebookException -> FacebookException -> Bool)
    -> (FacebookException -> FacebookException -> Bool)
    -> (FacebookException -> FacebookException -> FacebookException)
    -> (FacebookException -> FacebookException -> FacebookException)
    -> Ord FacebookException
    FacebookException -> FacebookException -> Bool
    FacebookException -> FacebookException -> Ordering
    FacebookException -> FacebookException -> FacebookException
    forall a.
    Eq a
    -> (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: FacebookException -> FacebookException -> Ordering
    compare :: FacebookException -> FacebookException -> Ordering
    $c< :: FacebookException -> FacebookException -> Bool
    < :: FacebookException -> FacebookException -> Bool
    $c<= :: FacebookException -> FacebookException -> Bool
    <= :: FacebookException -> FacebookException -> Bool
    $c> :: FacebookException -> FacebookException -> Bool
    > :: FacebookException -> FacebookException -> Bool
    $c>= :: FacebookException -> FacebookException -> Bool
    >= :: FacebookException -> FacebookException -> Bool
    $cmax :: FacebookException -> FacebookException -> FacebookException
    max :: FacebookException -> FacebookException -> FacebookException
    $cmin :: FacebookException -> FacebookException -> FacebookException
    min :: FacebookException -> FacebookException -> FacebookException
    Ord, Int -> FacebookException -> ShowS
    [FacebookException] -> ShowS
    FacebookException -> String
    (Int -> FacebookException -> ShowS)
    -> (FacebookException -> String)
    -> ([FacebookException] -> ShowS)
    -> Show FacebookException
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> FacebookException -> ShowS
    showsPrec :: Int -> FacebookException -> ShowS
    $cshow :: FacebookException -> String
    show :: FacebookException -> String
    $cshowList :: [FacebookException] -> ShowS
    showList :: [FacebookException] -> ShowS
    Show, ReadPrec [FacebookException]
    ReadPrec FacebookException
    Int -> ReadS FacebookException
    ReadS [FacebookException]
    (Int -> ReadS FacebookException)
    -> ReadS [FacebookException]
    -> ReadPrec FacebookException
    -> ReadPrec [FacebookException]
    -> Read FacebookException
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    $creadsPrec :: Int -> ReadS FacebookException
    readsPrec :: Int -> ReadS FacebookException
    $creadList :: ReadS [FacebookException]
    readList :: ReadS [FacebookException]
    $creadPrec :: ReadPrec FacebookException
    readPrec :: ReadPrec FacebookException
    $creadListPrec :: ReadPrec [FacebookException]
    readListPrec :: ReadPrec [FacebookException]
    Read, Typeable)

    instance A.FromJSON FacebookException where
        parseJSON :: Value -> Parser FacebookException
    parseJSON (A.Object Object
    v) =
            AccessTokenData -> AccessTokenData -> FacebookException
    FacebookException (AccessTokenData -> AccessTokenData -> FacebookException)
    -> Parser AccessTokenData
    -> Parser (AccessTokenData -> FacebookException)
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
    <$> Object
    v Object -> Key -> Parser AccessTokenData
    forall a. FromJSON a => Object -> Key -> Parser a
    A..: Key
    "type"
                              Parser (AccessTokenData -> FacebookException)
    -> Parser AccessTokenData -> Parser FacebookException
    forall a b. Parser (a -> b) -> Parser a -> Parser b
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
    <*> Object
    v Object -> Key -> Parser AccessTokenData
    forall a. FromJSON a => Object -> Key -> Parser a
    A..: Key
    "message"
        parseJSON Value
    _ = Parser FacebookException
    forall a. Parser a
    forall (m :: * -> *) a. MonadPlus m => m a
    mzero

    instance E.Exception FacebookException where