Commits

Richo Healey committed be3cc6d

First draft of how I intended for this to look.

  • Participants
  • Parent commits 32d5f89

Comments (0)

Files changed (3)

File lib/user.scm

     (substring path 1 (string-length path))))
 
 (define get-user-page
-  (lambda (user response)
-    (set-response-body
-      (string-append "Hello " user)
-      response)))
+  (lambda (u response)
+    (let ((user-data (get-user-by-name u)))
+      (cond (user-data
+          (set-response-body
+            user-data
+          (set-response-header
+            "Content-Type" "text/json"
+          response)))
+      (else
+        (set-response-body
+            "No such user"
+            response))))))
+
+
+; TODO Obviously this isn't done.
+(define get-user-by-name
+  (lambda (name)
+    (let ((u (assoc name user-mapping)))
+      (if u
+        (cadr u)
+        #f))))
+
+(define user-mapping
+  (map
+    (lambda (file)
+      (let ((username (if (string-suffix? "json" file)
+                          (substring file 0 (- (string-length file) 5))
+                          file)))
+        (list username . ((read-all (string-append "people/" file))))))
+    (directory "people")))
 (use srfi-13)
 (use srfi-18)
 (use tcp)
+(use posix)
+(use utils)
 ; (require-extension intarweb)
 (require "lib/response")
 (require "lib/request")

File people/richo.json

+{
+    "github_username": "richo",
+    "primary_email": "richo@psych0tik.net",
+    "twitter_username": "rich0H"
+}