X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhalcyon.git;a=blobdiff_plain;f=src%2FTwitter%2FUser.hs;h=988cf3c65b46f258991e5161f3344e8482263c22;hp=217ee7ddeed4e223b415d5d175947f9ff2c39dad;hb=7bb00e04c15781d889f950d00babf3f183047bff;hpb=94484087fbfe98d6735aa82798a9bf506f97fd19 diff --git a/src/Twitter/User.hs b/src/Twitter/User.hs index 217ee7d..988cf3c 100644 --- a/src/Twitter/User.hs +++ b/src/Twitter/User.hs @@ -1,23 +1,29 @@ -module Twitter.User +-- | Functions and data for working with Twitter users. +module Twitter.User ( + User(..), + screen_name_to_timeline_url + ) where -import Text.XML.HaXml +import Control.Applicative ((<$>)) +import Data.Aeson ((.:), FromJSON(..), Value(Object)) +import Data.Text (pack) +import Data.Monoid (mempty) -import Twitter.Xml - -data User = User { screen_name :: String } - deriving (Show, Eq) +-- | Represents a Twitter user, and contains the only attribute +-- thereof that we care about: the screen (user) name. +data User = User { screen_name :: String } deriving (Eq, Show) +instance FromJSON User where + parseJSON (Object u) = + User <$> (u .: screen_name_field) + where + screen_name_field = pack "screen_name" -user_from_content :: Content -> (Maybe User) -user_from_content c = - if (length names) == 0 - then - Nothing - else - case (get_char_data (names !! 0)) of - Nothing -> Nothing - (Just content) -> Just (User (content)) + -- Do whatever. + parseJSON _ = mempty - where - names = user_screen_name c +-- |Get the URL for the given screen name's timeline. +screen_name_to_timeline_url :: String -> String +screen_name_to_timeline_url = + ("http://twitter.com/" ++)