X-Git-Url: http://gitweb.michael.orlitzky.com/?p=dead%2Fhalcyon.git;a=blobdiff_plain;f=src%2FTwitter%2FUser.hs;h=af3bc1ce3f4faa4945690d0d1195a7d9c45fa1df;hp=a6fd3f6a459f1d547c10b736a853014964c59101;hb=518f0ba7d66d93fdda2a5dd7b8ea90b59d874b27;hpb=69b8af30f49aaad0f5c051998d2556b9ec291df7 diff --git a/src/Twitter/User.hs b/src/Twitter/User.hs index a6fd3f6..af3bc1c 100644 --- a/src/Twitter/User.hs +++ b/src/Twitter/User.hs @@ -1,27 +1,40 @@ -- | 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) +-- | 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 + -- | Parse the JSON we get from the Twitter API into a 'User' if we + -- can. + -- + parseJSON (Object u) = + User <$> (u .: screen_name_field) + where + screen_name_field = pack "screen_name" --- |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)) + -- Do whatever. + parseJSON _ = mempty - where - names = user_screen_name c + +-- | Get the URL for the given screen name's timeline. +-- +-- Examples: +-- +-- >>> screen_name_to_timeline_url "washington_irving" +-- "http://twitter.com/washington_irving" +-- +screen_name_to_timeline_url :: String -> String +screen_name_to_timeline_url = + ("http://twitter.com/" ++)