summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshoshin <shoshin@cicadas.surf>2023-03-19 21:27:43 -0500
committershoshin <shoshin@cicadas.surf>2023-03-19 21:27:43 -0500
commitfa729c028c72b70ecd5cc393ce7889ce77a44b3f (patch)
tree96ac319da8804ca405cea16d84aace82a9fab00b
parent23837aa2f03db36020abb78d890c4303633ca5e2 (diff)
Add: getting and objectifying steam games
-rw-r--r--arclade.asd5
-rw-r--r--model.lisp11
-rw-r--r--steam.lisp42
3 files changed, 46 insertions, 12 deletions
diff --git a/arclade.asd b/arclade.asd
index e0ce1bd..a5fd583 100644
--- a/arclade.asd
+++ b/arclade.asd
@@ -14,9 +14,12 @@
#:ironclad
#:jonathan
#:lazybones-hunchentoot
+ #:quri
#:spinneret
#:swank
#:testiere
#:lazybones)
:components ((:file "package")
- (:file "arclade")))
+ (:file "arclade")
+ (:file "model")
+ (:file "steam")))
diff --git a/model.lisp b/model.lisp
new file mode 100644
index 0000000..4c13185
--- /dev/null
+++ b/model.lisp
@@ -0,0 +1,11 @@
+;;;; model.lisp
+
+(defclass game ()
+ ((name :initarg :name :reader name)
+ (rating :accessor rating)
+ (playtime :accessor playtime)
+ (icon-url :accessor icon-url)
+ (last-played :accessor last-played)))
+
+(defclass steam-game (game)
+ ((appid :initarg :appid :reader appid)))
diff --git a/steam.lisp b/steam.lisp
index 5828b22..35a77f9 100644
--- a/steam.lisp
+++ b/steam.lisp
@@ -6,17 +6,37 @@
(defun set-steam-id (id)
(setf (steam-user-id *config*) id))
-(defun steam-query-key ()
- (format nil "key=~a" (steam-key *config*)))
-
-(defun steam-query-user ()
- (format nil "steamid=~a" (steam-user-id *config*)))
-
(defun steam-games-uri ()
- (quri:make-uri-http
- :host steam-host
- :path "IPlayerService/GetOwnedGames/v0001/"
- :query (format nil "~a&~a" (steam-query-key) (steam-query-user))))
+ (quri:render-uri
+ (quri:make-uri-http
+ :host steam-host
+ :path "IPlayerService/GetOwnedGames/v0001/"
+ :query (quri:url-encode-params `(("key" . ,(steam-key *config*))
+ ("steamid" . ,(steam-user-id *config*))
+ ("include_appinfo" . "true"))))))
(defun steam-games ()
- (drakma:http-request (quri:render-uri (steam-games-uri))))
+ (cadadr
+ (json:parse
+ (flexi-streams:octets-to-string
+ (drakma:http-request (steam-games-uri))))))
+
+;; (:|rtime_last_played| 1674604954
+;; :|playtime_linux_forever| 15
+;; :|playtime_mac_forever| 0
+;; :|playtime_windows_forever| 0
+;; :|has_community_visible_stats| T
+;; :|img_icon_url| "560d02f1edb9bf8a40060ff1c8cf818332cc2c9a"
+;; :|playtime_forever| 15
+;; :|name| "Amazing Cultivation Simulator"
+;; :|appid| 955900)
+
+(defun make-steam-game (json)
+ (with-plist ((id :|appid|) (playtime :|playtime_forever|) (name :|name|)
+ (icon-url :|img_icon_url|) (last-played :|rtime_last_played|))
+ json
+ (let ((game (make-instance 'steam-game :name name :appid id)))
+ (setf (playtime game) playtime
+ (icon-url game) icon-url
+ (last-played game) last-played)
+ game)))