{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ConstraintKinds #-}
module Pinboard.Api
(
getPostsRecent
, getPostsForDate
, getPostsAll
, getPostsDates
, getPostsMRUTime
, getSuggestedTags
, addPost
, addPostRec
, deletePost
, getTags
, renameTag
, deleteTag
, getUserSecretRssKey
, getUserApiToken
, getNoteList
, getNote
) where
import Pinboard.Client (pinboardJson)
import Data.Text (Text)
import Data.Time (UTCTime)
import Pinboard.Types (MonadPinboard, ResultFormatType(..))
import Pinboard.ApiTypes
import Pinboard.ApiRequest
import Pinboard.Error
import Control.Applicative
import Prelude
getPostsRecent
:: MonadPinboard m
=> Maybe [Tag]
-> Maybe Count
-> m (Either PinboardError Posts)
getPostsRecent tags count =
pinboardJson $ getPostsRecentRequest FormatJson tags count
getPostsAll
:: MonadPinboard m
=> Maybe [Tag]
-> Maybe StartOffset
-> Maybe NumResults
-> Maybe FromDateTime
-> Maybe ToDateTime
-> Maybe Meta
-> m (Either PinboardError [Post])
getPostsAll tags start results fromdt todt meta =
pinboardJson $ getPostsAllRequest FormatJson tags start results fromdt todt meta
getPostsForDate
:: MonadPinboard m
=> Maybe [Tag]
-> Maybe Date
-> Maybe Url
-> m (Either PinboardError Posts)
getPostsForDate tags date url =
pinboardJson $ getPostsForDateRequest FormatJson tags date url
getPostsDates
:: MonadPinboard m
=> Maybe [Tag]
-> m (Either PinboardError PostDates)
getPostsDates tags = pinboardJson $ getPostsDatesRequest FormatJson tags
getPostsMRUTime
:: MonadPinboard m
=> m (Either PinboardError UTCTime)
getPostsMRUTime =
fmap fromUpdateTime <$> pinboardJson (getPostsMRUTimeRequest FormatJson)
getSuggestedTags
:: MonadPinboard m
=> Url -> m (Either PinboardError [Suggested])
getSuggestedTags url = pinboardJson $ getSuggestedTagsRequest FormatJson url
deletePost
:: MonadPinboard m
=> Url -> m (Either PinboardError ())
deletePost url =
fmap fromDoneResult <$> pinboardJson (deletePostRequest FormatJson url)
addPost
:: MonadPinboard m
=> Url
-> Description
-> Maybe Extended
-> Maybe [Tag]
-> Maybe DateTime
-> Maybe Replace
-> Maybe Shared
-> Maybe ToRead
-> m (Either PinboardError ())
addPost url descr ext tags ctime repl shared toread =
fmap fromDoneResult <$>
pinboardJson
(addPostRequest FormatJson url descr ext tags ctime repl shared toread)
addPostRec
:: MonadPinboard m
=> Post
-> Replace
-> m (Either PinboardError ())
addPostRec post replace =
fmap fromDoneResult <$> pinboardJson (addPostRecRequest FormatJson post replace)
getTags
:: MonadPinboard m
=> m (Either PinboardError TagMap)
getTags = fmap fromJsonTagMap <$> pinboardJson (getTagsRequest FormatJson)
deleteTag
:: MonadPinboard m
=> Tag -> m (Either PinboardError ())
deleteTag tag =
fmap fromDoneResult <$> pinboardJson (deleteTagRequest FormatJson tag)
renameTag
:: MonadPinboard m
=> Old
-> New
-> m (Either PinboardError ())
renameTag old new =
fmap fromDoneResult <$> pinboardJson (renameTagRequest FormatJson old new)
getUserSecretRssKey
:: MonadPinboard m
=> m (Either PinboardError Text)
getUserSecretRssKey =
fmap fromTextResult <$> pinboardJson (getUserSecretRssKeyRequest FormatJson)
getUserApiToken
:: MonadPinboard m
=> m (Either PinboardError Text)
getUserApiToken =
fmap fromTextResult <$> pinboardJson (getUserApiTokenRequest FormatJson)
getNoteList
:: MonadPinboard m
=> m (Either PinboardError NoteList)
getNoteList = pinboardJson (getNoteListRequest FormatJson)
getNote
:: MonadPinboard m
=> NoteId -> m (Either PinboardError Note)
getNote noteid = pinboardJson (getNoteRequest FormatJson noteid)