]> gitweb.michael.orlitzky.com - dead/halcyon.git/blobdiff - src/Twitter/User.hs
Add more tests and remove the dependency on regex-compat.
[dead/halcyon.git] / src / Twitter / User.hs
index 75cf4b6f36c3f575ce50830e2abb9f5cee13573a..af3bc1ce3f4faa4945690d0d1195a7d9c45fa1df 100644 (file)
@@ -1,23 +1,40 @@
-module Twitter.User
+-- | Functions and data for working with Twitter users.
+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
 
-data User = User { screen_name :: String }
-          deriving (Show, Eq)
-
-              
-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))
+-- | 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
-    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.
+--
+--   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/" ++)