X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhalcyon.git;a=blobdiff_plain;f=src%2FTwitter%2FUser.hs;h=a1eed3a356dd5922349d02aa29ad71d3e94a51b3;hp=2c199c9d3607d0b3187babaf20c5a3ef44669a08;hb=9b6d95a82745ced2a58d9bc4ded555ee36b36673;hpb=81f6cb2ec955695d8d1a4619dab69e8fa4b3fb27 diff --git a/src/Twitter/User.hs b/src/Twitter/User.hs index 2c199c9..a1eed3a 100644 --- a/src/Twitter/User.hs +++ b/src/Twitter/User.hs @@ -2,32 +2,25 @@ module Twitter.User where -import Text.XML.HaXml - -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 i -> (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)) - +import Control.Applicative ((<$>)) +import Data.Aeson ((.:), FromJSON(..), Value(Object)) +import Data.Text (pack) +import Data.Monoid (mempty) + +-- | 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/" ++)