Skip to content

Commit

Permalink
Add geFeed to Web.Hatena.Bookmark
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitsutoshi Aoe committed Mar 19, 2012
1 parent b85bc1c commit a6df71c
Showing 1 changed file with 31 additions and 21 deletions.
52 changes: 31 additions & 21 deletions src/Web/Hatena/Bookmark.hs
Expand Up @@ -4,13 +4,14 @@
module Web.Hatena.Bookmark
( getPostEndPoint
, PostEndPoint(..)
, getFeedEndPoint
, FeedEndPoint(..)
, postBookmark
, getBookmark
, editBookmark
, deleteBookmark
, EditEndPoint(..)
, getFeedEndPoint
, FeedEndPoint(..)
, getFeed
) where
import Control.Applicative ((<$>))
import Control.Monad.Trans (lift)
Expand Down Expand Up @@ -48,25 +49,6 @@ instance FromAtom PostEndPoint where
href = fromDocument doc $// "rel" `attributeIs` "service.post"
>=> attribute "href"

getFeedEndPoint :: (ResourceIO m, Failure HttpException m)
=> HatenaT (Either (OAuth scope) WSSE) m FeedEndPoint
getFeedEndPoint = do
req <- lift $ parseUrl "http://b.hatena.ne.jp/atom"
req' <- authenticate req
atom <- atomResponse req'
case fromAtom atom of
Just endPoint -> return endPoint
Nothing -> fail "failed"

newtype FeedEndPoint = FeedEndPoint { feedEndPoint :: Text }
deriving Show

instance FromAtom FeedEndPoint where
fromAtom doc = FeedEndPoint <$> listToMaybe href
where
href = fromDocument doc $// "rel" `attributeIs` "service.feed"
>=> attribute "href"

postBookmark
:: (ResourceIO m, Failure HttpException m)
=> Text -- ^ URI
Expand Down Expand Up @@ -126,3 +108,31 @@ deleteBookmark (EditEndPoint url) = do
req <- deleteAtom (T.unpack url) []
req' <- authenticate req
emptyResponse req'

getFeedEndPoint :: (ResourceIO m, Failure HttpException m)
=> HatenaT (Either (OAuth scope) WSSE) m FeedEndPoint
getFeedEndPoint = do
req <- lift $ parseUrl "http://b.hatena.ne.jp/atom"
req' <- authenticate req
atom <- atomResponse req'
case fromAtom atom of
Just endPoint -> return endPoint
Nothing -> fail "failed"

newtype FeedEndPoint = FeedEndPoint { feedEndPoint :: Text }
deriving Show

instance FromAtom FeedEndPoint where
fromAtom doc = FeedEndPoint <$> listToMaybe href
where
href = fromDocument doc $// "rel" `attributeIs` "service.feed"
>=> attribute "href"

getFeed :: (ResourceIO m, Failure HttpException m)
=> HatenaT (Either (OAuth scope) WSSE) m Document
getFeed = do
FeedEndPoint url <- getFeedEndPoint
req <- lift $ parseUrl $ T.unpack url
req' <- authenticate req
atomResponse req'

0 comments on commit a6df71c

Please sign in to comment.