{-# LANGUAGE OverloadedStrings #-}
module Follow.Digesters.Pocket
( requestTokenStep
, accessTokenStep
, digest
) where
import Control.Monad.Catch (MonadThrow)
import Data.Aeson (Value, object, (.=))
import qualified Data.HashMap.Strict as HS
import Data.Maybe (fromJust, isJust)
import Data.Text (Text)
import Follow.Digesters.Pocket.Auth
import Follow.Types (Digester, Directory (..),
Entry (..))
import Network.HTTP.Req (MonadHttp, https, (/:))
digest ::
(MonadHttp m, MonadThrow m) => Text -> Digester (m (HS.HashMap Text Value))
digest token directory = jsonPostResponseBody url body jsonHeaders
where
url = https "getpocket.com" /: "v3" /: "send"
body =
object
[ "consumer_key" .= consumerKey
, "access_token" .= token
, "actions" .=
(entryToAction <$> filter (isJust . eURI) (dEntries directory))
]
entryToAction entry =
object
[ "action" .= ("add" :: Text)
, "url" .= ((fromJust $ eURI entry) :: Text)
]