Permalink
Browse files

Merge pull request #25 from jeluard/master

A simple function to help with file content access
  • Loading branch information...
2 parents eea3eee + f25b5db commit f28a7c8b75d53e5e7763894fdc762f7330eb0110 @Raynes committed Jul 17, 2013
Showing with 17 additions and 1 deletion.
  1. +7 −1 src/tentacles/gists.clj
  2. +10 −0 test/tentacles/gists_test.clj
View
@@ -43,6 +43,12 @@
(assoc options
:files (into {} (for [[k v] files] [k {:content v}]))))
+(defn file-contents
+ "Extract a file->content map from a gist"
+ [gist]
+ (if-let [files (:files gist)]
+ (zipmap (keys files) (map (comp :content second) 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)))
@@ -0,0 +1,10 @@
+(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/file-contents gist)]
+ (is (= (count files) 2))
+ (is (= (:file1 files) "content1"))))

0 comments on commit f28a7c8

Please sign in to comment.