]> gitweb.michael.orlitzky.com - dead/halcyon.git/blob - src/Twitter/User.hs
Add more tests and remove the dependency on regex-compat.
[dead/halcyon.git] / src / Twitter / User.hs
1 -- | Functions and data for working with Twitter users.
2 module Twitter.User (
3 User(..),
4 screen_name_to_timeline_url )
5 where
6
7 import Control.Applicative ( (<$>) )
8 import Data.Aeson ( (.:), FromJSON(..), Value(Object) )
9 import Data.Text ( pack )
10 import Data.Monoid ( mempty )
11
12
13 -- | Represents a Twitter user, and contains the only attribute
14 -- thereof that we care about: the screen (user) name.
15 --
16 data User = User { screen_name :: String } deriving (Eq, Show)
17
18 instance FromJSON User where
19 -- | Parse the JSON we get from the Twitter API into a 'User' if we
20 -- can.
21 --
22 parseJSON (Object u) =
23 User <$> (u .: screen_name_field)
24 where
25 screen_name_field = pack "screen_name"
26
27 -- Do whatever.
28 parseJSON _ = mempty
29
30
31 -- | Get the URL for the given screen name's timeline.
32 --
33 -- Examples:
34 --
35 -- >>> screen_name_to_timeline_url "washington_irving"
36 -- "http://twitter.com/washington_irving"
37 --
38 screen_name_to_timeline_url :: String -> String
39 screen_name_to_timeline_url =
40 ("http://twitter.com/" ++)