Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added basic entity support (experimental)

  • Loading branch information...
commit 52c6b8f7f1ccfa4037f20a8d404ee0e391fd7561 1 parent eaae1e4
Doug Burke authored January 07, 2012
10  CHANGES
@@ -13,11 +13,19 @@ Version 0.1.0.1
13 13
 
14 14
   - Changes to the Status record:
15 15
 
16  
-    - added statusRetweetCount and an experimental RetweetCount type;
  16
+    - added statusEntities, statusRetweetCount and an experimental
  17
+      RetweetCount type;
17 18
 
18 19
     - the statusFavorite field of the Status record is now populated
19 20
       from the "favorited" field of the JSON rather than "favorite".
20 21
 
  22
+  - Changes to the RetweetedStatus record:
  23
+
  24
+    - added the rsEntities field.
  25
+
  26
+  - Added the Entities, HashTagEntity, UserEntity, and URLEntity
  27
+    types to record the entity information provided with each tweet.
  28
+
21 29
 Version 0.0.1.2
22 30
 
23 31
   - Restricts the authenticate package since version 0.11 has switched
62  Web/Twitter/Enumerator/Types.hs
@@ -18,6 +18,10 @@ module Web.Twitter.Enumerator.Types
18 18
        , Delete(..)
19 19
        , User(..)
20 20
        , List(..)
  21
+       , Entities(..)
  22
+       , HashTagEntity
  23
+       , UserEntity
  24
+       , URLEntity(..)
21 25
        , checkError
22 26
        )
23 27
        where
@@ -114,6 +118,7 @@ data Status =
114 118
   , statusText          :: T.Text
115 119
   , statusSource        :: String
116 120
   , statusTruncated     :: Bool
  121
+  , statusEntities      :: Entities
117 122
   , statusInReplyTo     :: Maybe StatusId
118 123
   , statusInReplyToUser :: Maybe UserId
119 124
   , statusFavorite      :: Maybe Bool
@@ -128,6 +133,7 @@ instance FromJSON Status where
128 133
            <*> o .:  "text"
129 134
            <*> o .:  "source"
130 135
            <*> o .:  "truncated"
  136
+           <*> o .:  "entities"
131 137
            <*> o .:? "in_reply_to_status_id"
132 138
            <*> o .:? "in_reply_to_user_id"
133 139
            -- <*> o .:? "favorite" -- TODO: check whether it should be favorite or favorited
@@ -143,6 +149,7 @@ data RetweetedStatus =
143 149
   , rsText            :: T.Text
144 150
   , rsSource          :: String
145 151
   , rsTruncated       :: Bool
  152
+  , rsEntities        :: Entities
146 153
   , rsUser            :: User
147 154
   , rsRetweetedStatus :: Status
148 155
   } deriving (Show, Eq)
@@ -154,6 +161,7 @@ instance FromJSON RetweetedStatus where
154 161
                     <*> o .: "text"
155 162
                     <*> o .: "source"
156 163
                     <*> o .: "truncated"
  164
+                    <*> o .: "entities"
157 165
                     <*> o .: "user"
158 166
                     <*> o .: "retweeted_status"
159 167
   parseJSON _ = mzero
@@ -260,3 +268,57 @@ instance FromJSON List where
260 268
          <*> o .: "mode"
261 269
          <*> o .: "user"
262 270
   parseJSON _ = mzero
  271
+
  272
+data HashTagEntity = HashTagEntity T.Text
  273
+                   deriving (Show, Eq)
  274
+                        
  275
+instance FromJSON HashTagEntity where
  276
+  parseJSON (Object o) = 
  277
+    HashTagEntity <$> o .: "text"
  278
+  parseJSON _ = mzero
  279
+  
  280
+{-|
  281
+The 'UserEntity' is just a wrapper around 'User' which is
  282
+a bit wasteful, and should probably be replaced by just
  283
+storing the id, name and screen name here.
  284
+-}
  285
+data UserEntity = UserEntity User
  286
+                deriving (Show, Eq)
  287
+
  288
+instance FromJSON UserEntity where
  289
+  parseJSON = (UserEntity <$>) . parseJSON
  290
+  
  291
+data URLEntity = 
  292
+  URLEntity
  293
+  { ueURL      :: URLString
  294
+  , ueExpanded :: URLString
  295
+  , ueDisplay  :: T.Text
  296
+  } deriving (Show, Eq)
  297
+             
  298
+instance FromJSON URLEntity where
  299
+  parseJSON (Object o) = 
  300
+    URLEntity <$> o .:  "url"
  301
+              <*> o .:  "expanded_url"
  302
+              <*> o .:  "display_url"
  303
+  parseJSON _ = mzero
  304
+
  305
+{-|
  306
+Entity handling. At present the information about where
  307
+in the Tweet the entity was found (the @indices@ information)
  308
+is not retained.
  309
+-}
  310
+
  311
+data Entities = 
  312
+  Entities 
  313
+  { enHashTags     :: [HashTagEntity]
  314
+  , enUserMentions :: [UserEntity]
  315
+  , enURLs         :: [URLEntity]
  316
+  } deriving (Show, Eq)
  317
+             
  318
+instance FromJSON Entities where
  319
+  parseJSON (Object o) = 
  320
+    Entities <$> o .:  "hashtags"
  321
+             <*> o .:  "user_mentions"
  322
+             <*> o .:  "urls"
  323
+  parseJSON _ = mzero
  324
+             

0 notes on commit 52c6b8f

Please sign in to comment.
Something went wrong with that request. Please try again.