forked from prowdsponsor/fb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCheckin.hs
More file actions
88 lines (74 loc) · 2.89 KB
/
Checkin.hs
File metadata and controls
88 lines (74 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{-# LANGUAGE DeriveDataTypeable, FlexibleContexts, OverloadedStrings #-}
module Facebook.Object.Checkin
( Checkin(..)
, CheckinFrom(..)
, getCheckin
, createCheckin
) where
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 Control.Monad.Trans.Resource as R
import qualified Data.Aeson as A
import Facebook.Types
import Facebook.Monad
import Facebook.Graph
import Facebook.Pager
-- | A Facebook check-in (see
-- <https://developers.facebook.com/docs/reference/api/checkin/>).
--
-- /NOTE:/ We still don't support all fields supported by
-- Facebook. Please fill an issue if you need access to any other
-- fields.
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
-- | Information about the user who made the check-in.
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
-- | Get a checkin from its ID. The user access token is
-- optional, but when provided more information can be returned
-- back by Facebook.
getCheckin :: (R.MonadResource m, MonadBaseControl IO m) =>
Id -- ^ Checkin ID.
-> [Argument] -- ^ Arguments to be passed to Facebook.
-> Maybe UserAccessToken -- ^ Optional user access token.
-> FacebookT anyAuth m Checkin
getCheckin id_ query mtoken = getObject ("/" <> idCode id_) query mtoken
-- | Creates a 'check-in' and returns its ID. Place and
-- coordinates are both required by Facebook.
createCheckin :: (R.MonadResource m, MonadBaseControl IO m) =>
Id -- ^ Place ID.
-> GeoCoordinates -- ^ Coordinates.
-> [Argument] -- ^ Other arguments of the action.
-> UserAccessToken -- ^ Required user access token.
-> FacebookT Auth m Id
createCheckin pid coords args usertoken = do
let body = ("place" #= pid) : ("coordinates" #= coords) : args
postObject "me/checkins" body usertoken