Skip to content
Browse files

Added a simple helper function for gists.

  • Loading branch information...
1 parent 64dc5f2 commit 9a7fea2e38bf7bf95f8a54983acd69899025db3f @jeluard jeluard committed May 12, 2013
Showing with 18 additions and 1 deletion.
  1. +7 −1 src/tentacles/gists.clj
  2. +11 −0 test/tentacles/gists_test.clj
View
8 src/tentacles/gists.clj
@@ -43,6 +43,12 @@
(assoc options
:files (into {} (for [[k v] files] [k {:content v}]))))
+(defn map-file
+ "Gist files as a human friendly map"
+ [gist]
+ (if-let [files (:files gist)]
+ (zipmap (keys files) (map #(dissoc (second %) :filename) files))))
+
(defn create-gist
"Create a gist. files is a map of filenames to contents.
Options are:
@@ -122,4 +128,4 @@
(defn delete-comment
"Delete a comment."
[comment-id options]
- (no-content? (api-call :delete "gists/comments/%s" [comment-id] options)))
+ (no-content? (api-call :delete "gists/comments/%s" [comment-id] options)))
View
11 test/tentacles/gists_test.clj
@@ -0,0 +1,11 @@
+(ns tentacles.gists-test
+ (:use clojure.test)
+ (:require [tentacles.gists :as gists]))
+
+(def gist {:files {:file1 {:filename "file1" :content "content1" :type "text/plain"} :file2 {:filename "file2" :content "content2"}}})
+
+(deftest files-are-parsed
+ (let [files (gists/map-file gist)]
+ (is (= (count files) 2))
+ (is (= (get-in files [:file1 :content]) "content1"))
+ (is (not (contains? (first files) :filename)))))

0 comments on commit 9a7fea2

Please sign in to comment.
Something went wrong with that request. Please try again.