-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposts.lisp
36 lines (32 loc) · 1.11 KB
/
posts.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
(defpackage #:lem-posts-list/posts
(:import-from #:jonathan)
(:import-from #:dexador)
(:import-from #:trivia
#:match
#:plist)
(:import-from #:quri)
(:use #:cl)
(:export #:post-title
#:post-url
#:post-author
#:fetch-posts))
(in-package #:lem-posts-list/posts)
(defstruct post title url author)
(defun extract-posts (data)
(match data
((plist :|data| (plist :|children| children))
(loop :for child :in children
:collect (match child
((plist :|data|
(plist :|title| title
:|url| url
:|author| author))
(make-post :title title
:url url
:author author)))))))
(defun make-posts-url (subreddit)
(quri:make-uri :scheme "https"
:host "reddit.com"
:path (format nil "/r/~A/.json" subreddit)))
(defun fetch-posts (subreddit)
(extract-posts (jojo:parse (dex:get (make-posts-url subreddit)))))