module Facebook.Object.Checkin
( Checkin(..)
, CheckinFrom(..)
, getCheckin
, createCheckin
) where
import Control.Applicative
import Control.Monad (mzero)
import Control.Monad.Trans.Control (MonadBaseControl)
import Data.Aeson ((.:), (.:?))
import Data.Text (Text)
import Data.Time (UTCTime)
import Data.Typeable (Typeable)
import qualified Data.Aeson as A
import qualified Data.Conduit as C
import Facebook.Types
import Facebook.Monad
import Facebook.Graph
data Checkin =
Checkin { checkinId :: Id
, checkinFrom :: Maybe CheckinFrom
, checkinPlace :: Maybe Place
, checkinCreatedTime :: Maybe UTCTime
, checkinTags :: Maybe (Pager Tag)
, checkinMessage :: Maybe Text
}
deriving (Eq, Ord, Show, Read, Typeable)
instance A.FromJSON Checkin where
parseJSON (A.Object v) =
Checkin <$> v .: "id"
<*> v .:? "from"
<*> v .:? "place"
<*> ((unFbUTCTime <$>) <$> v .:? "created_time")
<*> v .:? "tags"
<*> v .:? "message"
parseJSON _ = mzero
data CheckinFrom =
CheckinFrom { checkinFromId :: UserId
, checkinFromName :: Text
}
deriving (Eq, Ord, Show, Read, Typeable)
instance A.FromJSON CheckinFrom where
parseJSON (A.Object v) =
CheckinFrom <$> v .: "id"
<*> v .: "name"
parseJSON _ = mzero
getCheckin :: (C.MonadResource m, MonadBaseControl IO m) =>
Id
-> [Argument]
-> Maybe UserAccessToken
-> FacebookT anyAuth m Checkin
getCheckin id_ query mtoken = getObject ("/" <> idCode id_) query mtoken
createCheckin :: (C.MonadResource m, MonadBaseControl IO m) =>
Id
-> GeoCoordinates
-> [Argument]
-> UserAccessToken
-> FacebookT Auth m Id
createCheckin pid coords args usertoken = do
let body = ("place" #= pid) : ("coordinates" #= coords) : args
postObject "me/checkins" body usertoken