Permalink
Browse files

added entity support for tweets

Added entity support for tweets (for now…)
  • Loading branch information...
1 parent 8ff7f24 commit 8d28fea79ac31c09ab51edf51f5b0128b9751402 @fons committed Jan 8, 2012
View
@@ -262,6 +262,7 @@
#:twitter-user-following
#:twitter-user-notifications
#:twitter-user-statuses-count
+
;; Tweet Element
#:tweet
#:tweet-id
@@ -274,6 +275,8 @@
#:tweet-in-reply-to-user-id
#:tweet-in-reply-to-screen-name
#:tweet-user
+ #:tweet-entities
+
;; Message element
#:twitter-message
#:twitter-message-id
@@ -428,6 +431,50 @@
#:geo-token
#:geo-print-places
+ ;;twitter-entity exports
+ #:twitter-entities-id
+ #:twitter-entities-hashtags
+ #:twitter-entities-user-mentions
+ #:twitter-entities-media
+ #:twitter-entities-urls
+
+ #:media-entity-id
+ #:media-entity-id-str
+ #:media-entity-media-url
+ #:media-entity-media-url-https
+ #:media-entity-url
+ #:media-entity-display-url
+ #:media-entity-expanded-url
+ #:media-entity-type
+ #:media-entity-sizes
+ #:media-entity-indices
+
+ #:user-mention-id
+ #:user-mention-id-str
+ #:user-mention-screen-name
+ #:user-mention-name
+ #:user-mention-screen-indices
+
+ #:hash-tag-id
+ #:hash-tag-text
+ #:hash-tag-indices
+
+ #:url-entity-id
+ #:url-entity-url
+ #:url-entity-display-url
+ #:url-entity-expanded-url
+ #:url-entity-indices
+
+ #:media-size-id
+ #:media-size-w
+ #:media-size-h
+ #:media-size-resize
+
+ #:entity-hashtags
+ #:entity-user-mentions
+ #:entity-urls
+ #:entity-media
+
;;persistence/lookup hooks
#:register-twitter-object
#:lookup-twitter-object
View
@@ -0,0 +1,106 @@
+(in-package :cl-twitter)
+
+;;indices are lists of ids. See the twitter-social-graph where idendity is defined...
+;;
+(defun parse-identity (ref)
+ ref)
+
+(define-element url-entity ((indices (identity)))
+ "a url entity "
+ (id "" nil)
+ (url "" nil)
+ (display-url "" nil)
+ (expanded-url "" nil)
+ (indices "" nil))
+
+
+(defmethod print-object ((url-entity url-entity) stream)
+ (format stream "#<URL '~A' ~S>" (url-entity-url url-entity) (url-entity-indices url-entity)))
+
+;;-------
+(define-element hashtag ((indices (identity)))
+ "a hash tag entity"
+ (id "" nil)
+ (text "" nil)
+ (indices "" nil))
+
+(defmethod print-object ((hashtag hashtag) stream)
+ (format stream "#<HASHTAG '#~A' ~S>" (hashtag-text hashtag) (hashtag-indices hashtag)))
+;;--------
+
+(define-element user-mention ((indices (identity)))
+ "a user mention"
+ (id "" nil)
+ (id-str "" nil)
+ (screen-name "" nil)
+ (name "" nil)
+ (indices "" nil))
+
+
+(defmethod print-object ((user-mention user-mention) stream)
+ (format stream "#<USER-MENTION id :~A '@~A' ~S>" (user-mention-id user-mention) (user-mention-screen-name user-mention)
+ (user-mention-indices user-mention) ))
+;;--------
+(define-element media-size ()
+ "generic media size"
+ (id "" nil)
+ (w "" nil)
+ (h "" nil)
+ (resize "" nil))
+
+(define-element media-sizes ((large media-size) (medium media-size) (small media-size) (thumb media-size))
+ "media entity size.."
+ (id "" nil)
+ (large "" nil)
+ (medium "" nil)
+ (small "" nil)
+ (thumb "" nil))
+
+(define-element media-entity ((sizes media-sizes) (indices (identity)))
+ " a media entity.."
+ (id "" nil)
+ (id-str "" nil)
+ (media-url "" nil)
+ (media-url-https "" nil)
+ (url "" nil)
+ (display-url "" nil)
+ (expanded-url "" nil)
+ (type "" nil)
+ (sizes "" nil)
+ (indices "" nil))
+
+
+(defmethod print-object ((media-entity media-entity) stream)
+ (format stream "#<MEDIA id :~A ~A url :~A ~S>"
+ (media-entity-id media-entity)
+ (media-entity-type media-entity)
+ (media-entity-display-url media-entity)
+ (media-entity-indices media-entity)))
+
+;;------
+(define-element twitter-entities ((urls (url-entity)) (hashtags (hashtag)) (media (media-entity)) (user-mentions (user-mention)))
+ "twitter entities.."
+ (id "" nil)
+ (hashtags "" nil)
+ (user-mentions "" nil)
+ (media "" nil)
+ (urls "" nil))
+
+;;---helper functions....
+(defmethod entity-hashtags ((tweet tweet))
+ (twitter-entities-hashtags (tweet-entities tweet)))
+
+
+(defmethod entity-user-mentions ((tweet tweet))
+ (twitter-entities-user-mentions (tweet-entities tweet)))
+
+(defmethod entity-media ((tweet tweet))
+ (twitter-entities-media (tweet-entities tweet)))
+
+(defmethod entity-urls ((tweet tweet))
+ (twitter-entities-urls (tweet-entities tweet)))
+
+
+;;---------------------------------
+
+
View
@@ -47,16 +47,8 @@
nil))))
(defun send-command (command args)
- #+nil(format t "command {~A} args : {~A} ~%" command args)
(multiple-value-bind (method url auth post-params) (command-request-arguments command args)
(let ((socket nil))
- #+nil
- (progn
- (format t "args : {~S} ~%" args)
- (format t "post params : {~S} ~%" post-params)
- (format t "method : {~S} ~%" method)
- (format t "url : {~S} ~%" url)
- (format t "act post params : {~S} ~%" (plist->alist post-params)))
(unwind-protect
(multiple-value-bind (response code)
(destructuring-bind (&optional auth-method &rest auth-spec) (or auth (user-http-auth *twitter-user*))
@@ -72,10 +64,12 @@
:parameters (plist->alist post-params)
common-drakma-args)
(destructuring-bind (access-token) auth-spec
- (oauth:access-protected-resource url access-token :consumer-token (oauth:token-consumer (twitter-user-access-token *twitter-user*))
- :request-method method
- :user-parameters (plist->alist post-params)
- :drakma-args common-drakma-args)))))
+ (oauth:access-protected-resource url access-token
+ :consumer-token (oauth:token-consumer (twitter-user-access-token *twitter-user*))
+ :request-method method
+ :user-parameters (plist->alist post-params)
+ :drakma-args common-drakma-args))
+ )))
(setf socket response)
(handler-case
(values (safe-decode-json response) code)
View
@@ -77,6 +77,30 @@
(defmethod show ((cursor-user-lists cursor-user-lists) &optional (s *standard-output*))
(mapcar (lambda (el) (show el s)) (cursor-user-lists-lists cursor-user-lists)))
-
-
-
+(defmethod show ((url-entity url-entity) &optional (s *standard-output*))
+ (format s "~&~1turl: ~a~30tdisplay: ~a~65texpanded: ~a~120t[~a,~a]" (url-entity-url url-entity)
+ (url-entity-display-url url-entity)
+ (url-entity-expanded-url url-entity)
+ (car (url-entity-indices url-entity))
+ (cadr (url-entity-indices url-entity))))
+
+(defmethod show ((hashtag hashtag) &optional (s *standard-output*))
+ (format s "~&~1ttext: #~a~30t[~a,~a]" (hashtag-text hashtag)
+ (car (hashtag-indices hashtag))
+ (cadr (hashtag-indices hashtag))))
+
+(defmethod show ((user-mention user-mention) &optional (s *standard-output*))
+ (format s "~&~1t@~a~25t~a~55t~a~65t[~a,~a]"
+ (user-mention-screen-name user-mention)
+ (user-mention-name user-mention)
+ (user-mention-id user-mention)
+ (car (user-mention-indices user-mention))
+ (cadr (user-mention-indices user-mention))))
+
+(defmethod show ((media-entity media-entity) &optional (s *standard-output*))
+ (format s "~&~1t~a~30turl: ~a~60tdisplay: ~a~95texpanded: ~a~120t[~a,~a]" (media-entity-type media-entity)
+ (media-entity-url media-entity)
+ (media-entity-display-url media-entity)
+ (media-entity-expanded-url media-entity)
+ (car (media-entity-indices media-entity))
+ (cadr (media-entity-indices media-entity))))
@@ -115,7 +115,6 @@
(trim-user nil) (include_rts nil) (include-entities t)) :statuses/user-timeline )
(define-twitter-method mentions (() &key (since-id nil) (max-id nil) (count nil) (page nil) (trim-user nil) (include_rts nil) (include-entities t)) :statuses/mentions)
-
(define-twitter-method retweeted-by-me (() &key (since-id nil) (max-id nil) (count nil)
(page nil) (trim-user nil) (include_rts nil) (include-entities t)) :statuses/retweeted-by-me)
@@ -5,7 +5,7 @@
;; Status/Tweet Element --> depends on twitter user..
;;
-(define-element tweet ((user twitter-user))
+(define-element tweet ((user twitter-user) (entities twitter-entities))
"A status element consisting of information on a status and a nested
user element"
(id "" nil)
@@ -20,6 +20,8 @@
(in-reply-to-screen-name "" nil)
(geo "" nil)
(geo-enabled "" nil)
+ ;; embedded twitter entities
+ (entities "" nil)
;; embedded user
(user "" nil))
View
@@ -233,3 +233,5 @@
(concatenate 'string dir filename)))))
+;;;------------------------
+
@@ -42,8 +42,8 @@
(with-open-file (stream (access-file) :direction :output :if-exists :supersede :if-does-not-exist :create)
(maphash (lambda (key lst) (declare (ignore key)) (format stream "~S~%" lst)) ht))))
-
-(defun read-access-info()
+
+(defun read-access-info ()
(let ((ht (make-hash-table :test 'equal)))
(with-open-file (stream (access-file) :direction :input :if-does-not-exist :create)
(do ((line (read stream nil) (read stream nil)))
View
@@ -27,6 +27,7 @@
(:file "twitter-op")
(:file "twitter-user")
(:file "twitter-tweet-status")
+ (:file "twitter-entity")
(:file "twitter-timeline")
(:file "twitter-trends")
(:file "twitter-social-graph")

0 comments on commit 8d28fea

Please sign in to comment.