{-# 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 :: Maybe [Tag] -> Maybe Count -> m (Either PinboardError Posts)
getPostsRecent Maybe [Tag]
tags Maybe Count
count =
PinboardRequest -> m (Either PinboardError Posts)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (PinboardRequest -> m (Either PinboardError Posts))
-> PinboardRequest -> m (Either PinboardError Posts)
forall a b. (a -> b) -> a -> b
$ ResultFormatType -> Maybe [Tag] -> Maybe Count -> PinboardRequest
getPostsRecentRequest ResultFormatType
FormatJson Maybe [Tag]
tags Maybe Count
count
getPostsAll
:: MonadPinboard m
=> Maybe [Tag]
-> Maybe StartOffset
-> Maybe NumResults
-> Maybe FromDateTime
-> Maybe ToDateTime
-> Maybe Meta
-> m (Either PinboardError [Post])
getPostsAll :: Maybe [Tag]
-> Maybe Count
-> Maybe Count
-> Maybe FromDateTime
-> Maybe FromDateTime
-> Maybe Count
-> m (Either PinboardError [Post])
getPostsAll Maybe [Tag]
tags Maybe Count
start Maybe Count
results Maybe FromDateTime
fromdt Maybe FromDateTime
todt Maybe Count
meta =
PinboardRequest -> m (Either PinboardError [Post])
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (PinboardRequest -> m (Either PinboardError [Post]))
-> PinboardRequest -> m (Either PinboardError [Post])
forall a b. (a -> b) -> a -> b
$ ResultFormatType
-> Maybe [Tag]
-> Maybe Count
-> Maybe Count
-> Maybe FromDateTime
-> Maybe FromDateTime
-> Maybe Count
-> PinboardRequest
getPostsAllRequest ResultFormatType
FormatJson Maybe [Tag]
tags Maybe Count
start Maybe Count
results Maybe FromDateTime
fromdt Maybe FromDateTime
todt Maybe Count
meta
getPostsForDate
:: MonadPinboard m
=> Maybe [Tag]
-> Maybe Date
-> Maybe Url
-> m (Either PinboardError Posts)
getPostsForDate :: Maybe [Tag]
-> Maybe Date -> Maybe Tag -> m (Either PinboardError Posts)
getPostsForDate Maybe [Tag]
tags Maybe Date
date Maybe Tag
url =
PinboardRequest -> m (Either PinboardError Posts)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (PinboardRequest -> m (Either PinboardError Posts))
-> PinboardRequest -> m (Either PinboardError Posts)
forall a b. (a -> b) -> a -> b
$ ResultFormatType
-> Maybe [Tag] -> Maybe Date -> Maybe Tag -> PinboardRequest
getPostsForDateRequest ResultFormatType
FormatJson Maybe [Tag]
tags Maybe Date
date Maybe Tag
url
getPostsDates
:: MonadPinboard m
=> Maybe [Tag]
-> m (Either PinboardError PostDates)
getPostsDates :: Maybe [Tag] -> m (Either PinboardError PostDates)
getPostsDates Maybe [Tag]
tags = PinboardRequest -> m (Either PinboardError PostDates)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (PinboardRequest -> m (Either PinboardError PostDates))
-> PinboardRequest -> m (Either PinboardError PostDates)
forall a b. (a -> b) -> a -> b
$ ResultFormatType -> Maybe [Tag] -> PinboardRequest
getPostsDatesRequest ResultFormatType
FormatJson Maybe [Tag]
tags
getPostsMRUTime
:: MonadPinboard m
=> m (Either PinboardError UTCTime)
getPostsMRUTime :: m (Either PinboardError FromDateTime)
getPostsMRUTime =
(UpdateTime -> FromDateTime)
-> Either PinboardError UpdateTime
-> Either PinboardError FromDateTime
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap UpdateTime -> FromDateTime
fromUpdateTime (Either PinboardError UpdateTime
-> Either PinboardError FromDateTime)
-> m (Either PinboardError UpdateTime)
-> m (Either PinboardError FromDateTime)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PinboardRequest -> m (Either PinboardError UpdateTime)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (ResultFormatType -> PinboardRequest
getPostsMRUTimeRequest ResultFormatType
FormatJson)
getSuggestedTags
:: MonadPinboard m
=> Url -> m (Either PinboardError [Suggested])
getSuggestedTags :: Tag -> m (Either PinboardError [Suggested])
getSuggestedTags Tag
url = PinboardRequest -> m (Either PinboardError [Suggested])
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (PinboardRequest -> m (Either PinboardError [Suggested]))
-> PinboardRequest -> m (Either PinboardError [Suggested])
forall a b. (a -> b) -> a -> b
$ ResultFormatType -> Tag -> PinboardRequest
getSuggestedTagsRequest ResultFormatType
FormatJson Tag
url
deletePost
:: MonadPinboard m
=> Url -> m (Either PinboardError ())
deletePost :: Tag -> m (Either PinboardError ())
deletePost Tag
url =
(DoneResult -> ())
-> Either PinboardError DoneResult -> Either PinboardError ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DoneResult -> ()
fromDoneResult (Either PinboardError DoneResult -> Either PinboardError ())
-> m (Either PinboardError DoneResult)
-> m (Either PinboardError ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PinboardRequest -> m (Either PinboardError DoneResult)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (ResultFormatType -> Tag -> PinboardRequest
deletePostRequest ResultFormatType
FormatJson Tag
url)
addPost
:: MonadPinboard m
=> Url
-> Description
-> Maybe Extended
-> Maybe [Tag]
-> Maybe DateTime
-> Maybe Replace
-> Maybe Shared
-> Maybe ToRead
-> m (Either PinboardError ())
addPost :: Tag
-> Tag
-> Maybe Tag
-> Maybe [Tag]
-> Maybe FromDateTime
-> Maybe Replace
-> Maybe Replace
-> Maybe Replace
-> m (Either PinboardError ())
addPost Tag
url Tag
descr Maybe Tag
ext Maybe [Tag]
tags Maybe FromDateTime
ctime Maybe Replace
repl Maybe Replace
shared Maybe Replace
toread =
(DoneResult -> ())
-> Either PinboardError DoneResult -> Either PinboardError ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DoneResult -> ()
fromDoneResult (Either PinboardError DoneResult -> Either PinboardError ())
-> m (Either PinboardError DoneResult)
-> m (Either PinboardError ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
PinboardRequest -> m (Either PinboardError DoneResult)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson
(ResultFormatType
-> Tag
-> Tag
-> Maybe Tag
-> Maybe [Tag]
-> Maybe FromDateTime
-> Maybe Replace
-> Maybe Replace
-> Maybe Replace
-> PinboardRequest
addPostRequest ResultFormatType
FormatJson Tag
url Tag
descr Maybe Tag
ext Maybe [Tag]
tags Maybe FromDateTime
ctime Maybe Replace
repl Maybe Replace
shared Maybe Replace
toread)
addPostRec
:: MonadPinboard m
=> Post
-> Replace
-> m (Either PinboardError ())
addPostRec :: Post -> Replace -> m (Either PinboardError ())
addPostRec Post
post Replace
replace =
(DoneResult -> ())
-> Either PinboardError DoneResult -> Either PinboardError ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DoneResult -> ()
fromDoneResult (Either PinboardError DoneResult -> Either PinboardError ())
-> m (Either PinboardError DoneResult)
-> m (Either PinboardError ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PinboardRequest -> m (Either PinboardError DoneResult)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (ResultFormatType -> Post -> Replace -> PinboardRequest
addPostRecRequest ResultFormatType
FormatJson Post
post Replace
replace)
getTags
:: MonadPinboard m
=> m (Either PinboardError TagMap)
getTags :: m (Either PinboardError TagMap)
getTags = (JsonTagMap -> TagMap)
-> Either PinboardError JsonTagMap -> Either PinboardError TagMap
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap JsonTagMap -> TagMap
fromJsonTagMap (Either PinboardError JsonTagMap -> Either PinboardError TagMap)
-> m (Either PinboardError JsonTagMap)
-> m (Either PinboardError TagMap)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PinboardRequest -> m (Either PinboardError JsonTagMap)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (ResultFormatType -> PinboardRequest
getTagsRequest ResultFormatType
FormatJson)
deleteTag
:: MonadPinboard m
=> Tag -> m (Either PinboardError ())
deleteTag :: Tag -> m (Either PinboardError ())
deleteTag Tag
tag =
(DoneResult -> ())
-> Either PinboardError DoneResult -> Either PinboardError ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DoneResult -> ()
fromDoneResult (Either PinboardError DoneResult -> Either PinboardError ())
-> m (Either PinboardError DoneResult)
-> m (Either PinboardError ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PinboardRequest -> m (Either PinboardError DoneResult)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (ResultFormatType -> Tag -> PinboardRequest
deleteTagRequest ResultFormatType
FormatJson Tag
tag)
renameTag
:: MonadPinboard m
=> Old
-> New
-> m (Either PinboardError ())
renameTag :: Tag -> Tag -> m (Either PinboardError ())
renameTag Tag
old Tag
new =
(DoneResult -> ())
-> Either PinboardError DoneResult -> Either PinboardError ()
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap DoneResult -> ()
fromDoneResult (Either PinboardError DoneResult -> Either PinboardError ())
-> m (Either PinboardError DoneResult)
-> m (Either PinboardError ())
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PinboardRequest -> m (Either PinboardError DoneResult)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (ResultFormatType -> Tag -> Tag -> PinboardRequest
renameTagRequest ResultFormatType
FormatJson Tag
old Tag
new)
getUserSecretRssKey
:: MonadPinboard m
=> m (Either PinboardError Text)
=
(TextResult -> Tag)
-> Either PinboardError TextResult -> Either PinboardError Tag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TextResult -> Tag
fromTextResult (Either PinboardError TextResult -> Either PinboardError Tag)
-> m (Either PinboardError TextResult)
-> m (Either PinboardError Tag)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PinboardRequest -> m (Either PinboardError TextResult)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (ResultFormatType -> PinboardRequest
getUserSecretRssKeyRequest ResultFormatType
FormatJson)
getUserApiToken
:: MonadPinboard m
=> m (Either PinboardError Text)
getUserApiToken :: m (Either PinboardError Tag)
getUserApiToken =
(TextResult -> Tag)
-> Either PinboardError TextResult -> Either PinboardError Tag
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TextResult -> Tag
fromTextResult (Either PinboardError TextResult -> Either PinboardError Tag)
-> m (Either PinboardError TextResult)
-> m (Either PinboardError Tag)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> PinboardRequest -> m (Either PinboardError TextResult)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (ResultFormatType -> PinboardRequest
getUserApiTokenRequest ResultFormatType
FormatJson)
getNoteList
:: MonadPinboard m
=> m (Either PinboardError NoteList)
getNoteList :: m (Either PinboardError NoteList)
getNoteList = PinboardRequest -> m (Either PinboardError NoteList)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (ResultFormatType -> PinboardRequest
getNoteListRequest ResultFormatType
FormatJson)
getNote
:: MonadPinboard m
=> NoteId -> m (Either PinboardError Note)
getNote :: Tag -> m (Either PinboardError Note)
getNote Tag
noteid = PinboardRequest -> m (Either PinboardError Note)
forall (m :: * -> *) a.
(MonadPinboard m, FromJSON a) =>
PinboardRequest -> m (Either PinboardError a)
pinboardJson (ResultFormatType -> Tag -> PinboardRequest
getNoteRequest ResultFormatType
FormatJson Tag
noteid)