X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhalcyon.git;a=blobdiff_plain;f=src%2FTwitter%2FUser.hs;h=071b0633695f22a1162835d7105cd20c05516e14;hp=ffa01ba747a8a7d7b13e684d6e0204c6c20acaa4;hb=d7c6b5499c0969b6e488d9fc583f93bbb4e3d4c7;hpb=e13f2a1eced5f388b37bc0ed12e9db72eba4b5d4 diff --git a/src/Twitter/User.hs b/src/Twitter/User.hs index ffa01ba..071b063 100644 --- a/src/Twitter/User.hs +++ b/src/Twitter/User.hs @@ -1,33 +1,28 @@ -- | Functions and data for working with Twitter users. -module Twitter.User +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 - --- |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 (Show, Eq) - - --- |Create a 'User' from HaXML 'Content'. -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)) +-- | 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 - names = user_screen_name c + screen_name_field = pack "screen_name" + -- Do whatever. + parseJSON _ = mempty -- |Get the URL for the given screen name's timeline. screen_name_to_timeline_url :: String -> String -screen_name_to_timeline_url sn = - "http://twitter.com/" ++ sn +screen_name_to_timeline_url = + ("http://twitter.com/" ++)