|
|
@@ -2,23 +2,25 @@
|
|
|
|
|
|
(defparameter *fsq-checkins-url* "https://api.foursquare.com/v2/checkins/recent"
|
|
|
"URL of recent checkins API")
|
|
|
+(defparameter *fsq-api-url* "https://api.foursquare.com/v2/~A"
|
|
|
+ "Foursquare API URL")
|
|
|
|
|
|
(defvar *fsq-access-token* nil "Access token for a user under which the process is run")
|
|
|
(defvar *fsq-last-timestamp* nil "Timestamp of the last checkin. To only fetch latest")
|
|
|
|
|
|
-(defun fsq-fetch-checkins (&optional after-timestamp)
|
|
|
+(defun %fsq-api-call (method &optional params)
|
|
|
(let* ((resp
|
|
|
(yason:parse
|
|
|
(flexi-streams:octets-to-string
|
|
|
(handler-case
|
|
|
(bordeaux-threads:with-timeout (5)
|
|
|
(drakma:http-request
|
|
|
- *fsq-checkins-url*
|
|
|
- :parameters
|
|
|
- (list
|
|
|
+ (format nil *fsq-api-url* method)
|
|
|
+ :parameters
|
|
|
+ (list*
|
|
|
(cons "oauth_token" *fsq-access-token*)
|
|
|
- (cons "afterTimestamp" (or after-timestamp "0"))
|
|
|
- (cons "v" "20150811"))))
|
|
|
+ (cons "v" "20150811")
|
|
|
+ params)))
|
|
|
(bordeaux-threads:timeout (e)
|
|
|
(declare (ignore e))
|
|
|
(error "Timeout")))
|
|
|
@@ -28,7 +30,12 @@
|
|
|
(when (not (= 200 (aget "code" meta)))
|
|
|
(error (format nil "Foursquare API error, code ~A, errorType '~A', errorDetail '~A'"
|
|
|
(aget "code" meta) (aget "errorType" meta) (aget "errorDetail" meta))))
|
|
|
- (aget "recent" (aget "response" resp))))
|
|
|
+ (aget "response" resp)))
|
|
|
+
|
|
|
+(defun fsq-fetch-checkins (&optional after-timestamp)
|
|
|
+ (aget "recent"
|
|
|
+ (%fsq-api-call "checkins/recent"
|
|
|
+ (list (cons "afterTimestamp" (or after-timestamp "0"))))))
|
|
|
|
|
|
(defun fsq-fetch-new-checkins ()
|
|
|
(let ((recent (fsq-fetch-checkins *fsq-last-timestamp*)))
|
|
|
@@ -36,6 +43,12 @@
|
|
|
(setf *fsq-last-timestamp* (princ-to-string (1+ (aget "createdAt" (first recent))))))
|
|
|
recent))
|
|
|
|
|
|
+(defun fsq-friends (&optional offset)
|
|
|
+ (aget "items"
|
|
|
+ (aget "friends"
|
|
|
+ (%fsq-api-call "users/self/friends"
|
|
|
+ (list (cons "offset" (or offset "0")))))))
|
|
|
+
|
|
|
(defun fsq-format-checkin (checkin &optional with-dates)
|
|
|
(when checkin
|
|
|
(let ((user (aget "user" checkin))
|