]> gitweb.michael.orlitzky.com - dead/halcyon.git/blobdiff - src/Twitter/User.hs
Rewrite everything to use the JSON API with OAuth authentication.
[dead/halcyon.git] / src / Twitter / User.hs
index 2c199c9d3607d0b3187babaf20c5a3ef44669a08..a1eed3a356dd5922349d02aa29ad71d3e94a51b3 100644 (file)
@@ -2,32 +2,25 @@
 module Twitter.User
 where
 
-import Text.XML.HaXml
-
-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)
-
-
--- |Create a 'User' from HaXML 'Content'.
-user_from_content :: Content i -> (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))
-
+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
+  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.
 screen_name_to_timeline_url :: String -> String
-screen_name_to_timeline_url sn =
-    "http://twitter.com/" ++ sn
+screen_name_to_timeline_url =
+  ("http://twitter.com/" ++)