{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
module Pinboard.ApiRequest
(
getPostsRecentRequest
, getPostsForDateRequest
, getPostsAllRequest
, getPostsDatesRequest
, getPostsMRUTimeRequest
, getSuggestedTagsRequest
, addPostRequest
, addPostRecRequest
, deletePostRequest
, getTagsRequest
, renameTagRequest
, deleteTagRequest
, getUserSecretRssKeyRequest
, getUserApiTokenRequest
, getNoteListRequest
, getNoteRequest
) where
import Pinboard.Types
(PinboardRequest(..), Param(..), ResultFormatType(..))
import Pinboard.Util ((</>))
import Data.Text (unwords)
import Data.Maybe (catMaybes)
import Pinboard.ApiTypes
import Control.Applicative
import Prelude hiding (unwords)
getPostsRecentRequest
:: ResultFormatType
-> Maybe [Tag]
-> Maybe Count
-> PinboardRequest
getPostsRecentRequest fmt tags count = PinboardRequest path params
where
path = "posts/recent"
params =
catMaybes [Just (Format fmt), Tag . unwords <$> tags, Count <$> count]
getPostsAllRequest
:: ResultFormatType
-> Maybe [Tag]
-> Maybe StartOffset
-> Maybe NumResults
-> Maybe FromDateTime
-> Maybe ToDateTime
-> Maybe Meta
-> PinboardRequest
getPostsAllRequest fmt tags start results fromdt todt meta =
PinboardRequest path params
where
path = "posts/all"
params =
catMaybes
[ Just (Format fmt)
, Tag . unwords <$> tags
, Start <$> start
, Results <$> results
, FromDateTime <$> fromdt
, ToDateTime <$> todt
, Meta <$> meta
]
getPostsForDateRequest
:: ResultFormatType
-> Maybe [Tag]
-> Maybe Date
-> Maybe Url
-> PinboardRequest
getPostsForDateRequest fmt tags date url = PinboardRequest path params
where
path = "posts/get"
params =
catMaybes
[Just (Format fmt), Tag . unwords <$> tags, Date <$> date, Url <$> url]
getPostsDatesRequest
:: ResultFormatType
-> Maybe [Tag]
-> PinboardRequest
getPostsDatesRequest fmt tags = PinboardRequest path params
where
path = "posts/dates"
params = catMaybes [Just (Format fmt), Tag . unwords <$> tags]
getPostsMRUTimeRequest :: ResultFormatType -> PinboardRequest
getPostsMRUTimeRequest fmt = PinboardRequest path params
where
path = "posts/update"
params = [Format fmt]
getSuggestedTagsRequest :: ResultFormatType -> Url -> PinboardRequest
getSuggestedTagsRequest fmt url = PinboardRequest path params
where
path = "posts/suggest"
params = [Format fmt, Url url]
deletePostRequest :: ResultFormatType -> Url -> PinboardRequest
deletePostRequest fmt url = PinboardRequest path params
where
path = "posts/delete"
params = [Format fmt, Url url]
addPostRequest
:: ResultFormatType
-> Url
-> Description
-> Maybe Extended
-> Maybe [Tag]
-> Maybe DateTime
-> Maybe Replace
-> Maybe Shared
-> Maybe ToRead
-> PinboardRequest
addPostRequest fmt url descr ext tags ctime repl shared toread =
PinboardRequest path params
where
path = "posts/add"
params =
catMaybes
[ Just (Format fmt)
, Just $ Url url
, Just $ Description descr
, Extended <$> ext
, Tags . unwords <$> tags
, DateTime <$> ctime
, Replace <$> repl
, Shared <$> shared
, ToRead <$> toread
]
addPostRecRequest
:: ResultFormatType
-> Post
-> Replace
-> PinboardRequest
addPostRecRequest fmt Post {..} replace =
addPostRequest
fmt
postHref
postDescription
(Just postExtended)
(Just postTags)
(Just postTime)
(Just replace)
(Just postShared)
(Just postToRead)
getTagsRequest :: ResultFormatType -> PinboardRequest
getTagsRequest fmt = PinboardRequest path params
where
path = "tags/get"
params = [Format fmt]
deleteTagRequest :: ResultFormatType -> Tag -> PinboardRequest
deleteTagRequest fmt tag = PinboardRequest path params
where
path = "tags/delete"
params = [Format fmt, Tag tag]
renameTagRequest
:: ResultFormatType
-> Old
-> New
-> PinboardRequest
renameTagRequest fmt old new = PinboardRequest path params
where
path = "tags/rename"
params = [Format fmt, Old old, New new]
getUserSecretRssKeyRequest :: ResultFormatType -> PinboardRequest
getUserSecretRssKeyRequest fmt = PinboardRequest path params
where
path = "user/secret"
params = [Format fmt]
getUserApiTokenRequest :: ResultFormatType -> PinboardRequest
getUserApiTokenRequest fmt = PinboardRequest path params
where
path = "user/api_token"
params = [Format fmt]
getNoteListRequest :: ResultFormatType -> PinboardRequest
getNoteListRequest fmt = PinboardRequest path params
where
path = "notes/list"
params = [Format fmt]
getNoteRequest :: ResultFormatType -> NoteId -> PinboardRequest
getNoteRequest fmt noteid = PinboardRequest path params
where
path = "notes" </> noteid
params = [Format fmt]