Commit bb2c5f5c authored by ieslick's avatar ieslick

More repl api features and bug fixes

parent 27089c60
......@@ -100,7 +100,7 @@
(command-base-url cmd)
(user-http-auth (get-user (getf args :user nil)))
(plist->uri-params (append (when *twitter-client-source-param*
'("source" *twitter-client-source-param*))
`("source" ,*twitter-client-source-param*))
(strip-keyword :user args)))))
(defun post-id-command-request (cmd args)
......@@ -139,7 +139,3 @@
(format nil "~A?~{~A=~A~^&~}" (command-base-url cmd)
(plist->uri-params args t)))
(defun user-http-auth (user)
(when user
(list (twitter-user-screen-name user)
(twitter-user-password user))))
......@@ -19,7 +19,7 @@
(define-command user-timeline (:get (:tweet))
"Returns 20 most recent statuss from provided users friends"
"Returns 20 most recent statuses from provided users friends"
:id "Optional. Specifies the ID or screen name of the user for whom to return the friends_timeline"
:since "Optional. Narrows returned results to those created after
the HTTP-formatted date."
......@@ -46,7 +46,7 @@
that this post is in reply to. This sets the appropriate
attribute of the result status.")
(define-command tweet-replies (:get (:tweet))
(define-command tweet-replies (:post (:tweet))
"Updates the authenticating user's status. Requires status parameter"
:page "Optional. Returns the statuses at page * 20"
......@@ -187,7 +187,8 @@
(defun get-user (ref)
(if (twitter-user-p ref) ref
(gethash ref *twitter-users*)))
(aif (gethash ref *twitter-users*) it
(defun lookup-twitter-user (rec)
(let ((name (get-value :screen-name rec)))
......@@ -253,6 +254,13 @@
(tweet-created-at tweet)))
(defmethod print-tweet (tweet)
(format t "~A~%by ~A at ~A~%~%"
(tweet-text tweet)
(twitter-user-screen-name (tweet-user tweet))
(tweet-created-at tweet)))
(defun lookup-tweet (rec)
(declare (ignore rec))
This diff is collapsed.
......@@ -16,12 +16,12 @@
(multiple-value-bind (method url auth post-params)
(command-request-arguments command args)
(multiple-value-bind (response code)
(apply #'http-request url
:method method
:basic-authorization (or auth (user-http-auth *twitter-user*))
:parameters (plist->alist post-params)
:want-stream t
:additional-headers *twitter-client-headers*)
(http-request url
:method method
:basic-authorization (or auth (user-http-auth *twitter-user*))
:parameters (plist->alist post-params)
:want-stream t
:additional-headers *twitter-client-headers*)
(values (safe-decode-json response) code))))
(defun safe-decode-json (response)
......@@ -44,9 +44,7 @@
(defun authenticate-user (username password)
(let ((user (or (get-user username)
(setf (twitter-user-screen-name user) username)
(let ((user (get-user username)))
(setf (twitter-user-password user) password)
(handler-case (twitter-op :verify-credentials :user user)
(twitter-api-condition () (return-from authenticate-user nil)))
......@@ -60,14 +58,14 @@
;; Updates
(defun timeline (&rest args)
(defun public-timeline (&rest args)
(apply 'twitter-op :public-timeline args))
(defun user-timeline (&rest args)
(defun timeline (&rest args)
(apply 'twitter-op :user-timeline args))
(defun @replies (&rest args)
(apply 'twitter-op :messages-received args))
(defun friends-timeline (&rest args)
(print-tweets (apply 'twitter-op :friends-timeline args)))
(defun send-tweet (text &rest args &key (tiny-url-p t) &allow-other-keys)
(let ((newtext (if tiny-url-p (convert-to-tinyurl text) text)))
......@@ -79,41 +77,39 @@
(defun update (text &rest args)
(apply 'send-tweet text args))
(defun reply-to (tweet text &rest args)
(apply 'send-tweet text :in-reply-to-status-id (tweet-id tweet) args))
(defun reply-to (status-ref text)
(send-tweet text :in-reply-to-status-id message
(defun @reply-to (status-ref text)
(defun @reply-to (tweet text &rest args)
(let ((fmt (format nil "@~A ~A"
(user-screen-name (status-user (find-status id)))
(twitter-user-screen-name (tweet-user tweet))
(reply-to message text)))
(apply 'reply-to tweet fmt args)))
;; Messages
(defun messages ()
(twitter-op :messages-received))
(defun messages (&rest args)
(apply 'twitter-op :messages-received args))
(defun sent-messages ()
(twitter-op :messages-sent))
(defun sent-messages (&rest args)
(apply 'twitter-op :messages-sent args))
(defun send-message (user message)
(twitter-op :message-new
:user (aif (get-user user)
(twitter-user-id it)
:text message))
(defun send-message (user message &rest args)
(apply 'twitter-op :message-new
:user (aif (get-user user)
(twitter-user-id it)
:text message
;; Objects
(defun print-tweets (tweets)
(dolist (tweet tweets)
(describe tweet)
(format t "~%~%")))
(mapc #'print-tweet tweets))
;; Search API
......@@ -151,7 +147,7 @@
(defun convert-to-tinyurl (text)
(let ((result text)
(regex (ppcre:create-scanner "http:[^\\s]+")))
(regex (ppcre:create-scanner "http:[^\\s\\)\\]\\'\\\"]+")))
(ppcre:do-matches (start end regex result result)
(when (> (- end start) 24)
(setf result (ppcre:regex-replace
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment