1 -- | Functions and data for working with Twitter users.
4 screen_name_to_timeline_url )
7 import Control.Applicative ( (<$>) )
8 import Data.Aeson ( (.:), FromJSON(..), Value(Object) )
9 import Data.Text ( pack )
10 import Data.Monoid ( mempty )
13 -- | Represents a Twitter user, and contains the only attribute
14 -- thereof that we care about: the screen (user) name.
16 data User = User { screen_name :: String } deriving (Eq, Show)
18 instance FromJSON User where
19 -- | Parse the JSON we get from the Twitter API into a 'User' if we
22 parseJSON (Object u) =
23 User <$> (u .: screen_name_field)
25 screen_name_field = pack "screen_name"
31 -- | Get the URL for the given screen name's timeline.
35 -- >>> screen_name_to_timeline_url "washington_irving"
36 -- "http://twitter.com/washington_irving"
38 screen_name_to_timeline_url :: String -> String
39 screen_name_to_timeline_url =
40 ("http://twitter.com/" ++)