-- | Functions and data for working with Twitter users. module Twitter.User ( User(..), screen_name_to_timeline_url ) where 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 -- | 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" -- Do whatever. parseJSON _ = mempty -- | 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/" ++)