summaryrefslogtreecommitdiff
path: root/steam.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'steam.lisp')
-rw-r--r--steam.lisp51
1 files changed, 46 insertions, 5 deletions
diff --git a/steam.lisp b/steam.lisp
index 0e29c73..8d61514 100644
--- a/steam.lisp
+++ b/steam.lisp
@@ -6,6 +6,15 @@
(defun set-steam-id (id)
(setf (steam-user-id *config*) id))
+;; JSON
+;; * The API returns an object containing the named object with the result data.
+;; * Arrays are represented as an array with the name of the type of the objects
+;; in the array (ie. an object named "items" containing an array of objects
+;; of type "item" would be represented as an object named "items" containing
+;; an array named "item" containing several objects following the "item" structure).
+;; * Null is represented as JSON's null.
+
+
(defun steam-games-uri ()
(quri:render-uri
(quri:make-uri-http
@@ -15,11 +24,12 @@
("steamid" . ,(steam-user-id *config*))
("include_appinfo" . "true"))))))
-(defun steam-games ()
- (cadadr
- (json:parse
- (flexi-streams:octets-to-string
- (drakma:http-request (steam-games-uri))))))
+(defun fetch-steam-games ()
+ (derrida:with-keypaths ((games :|response| :|games|))
+ (json:parse
+ (flexi-streams:octets-to-string
+ (drakma:http-request (steam-games-uri))))
+ games))
(defun make-steam-game (json)
(with-plist ((id :|appid|) (playtime :|playtime_forever|) (name :|name|)
@@ -30,3 +40,34 @@
(icon-url game) icon-url
(last-played game) last-played)
game)))
+
+(defun steam-achievements-uri (game)
+ (quri:render-uri
+ (quri:make-uri-http
+ :host steam-host
+ :path "ISteamUserStats/GetPlayerAchievements/v0001/"
+ :query (quri:url-encode-params `(("key" . ,(steam-key *config*))
+ ("steamid" . ,(steam-user-id *config*))
+ ("appid" . ,(appid game))
+ ("l" . "en"))))))
+
+(defun fetch-steam-achievements (steam-game)
+ (derrida:with-keypaths ((success :|playerstats| :|success|)
+ (achievements :|playerstats| :|achievements|))
+ (json:parse
+ (flexi-streams:octets-to-string
+ (drakma:http-request (steam-achievements-uri steam-game))))
+ (when success achievements)))
+
+(defun steam-game-schema-uri (game)
+ "Returns URI and query params to get detailed info about a game. This is where
+the image links for achievements can be found."
+ (quri:render-uri
+ (quri:make-uri-http
+ :host steam-host
+ :path "ISteamUserStats/GetSchemaForGame/v2/"
+ :query (quri:url-encode-params `(("key" . ,(steam-key *config*))
+ ("appid" . ,(appid game))
+ ("l" . "en"))))))
+
+