Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

A simple function to help with file content access #25

Merged
merged 3 commits into from

2 participants

@jeluard

No description provided.

test/tentacles/gists_test.clj
@@ -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 (= (get-in files [:file1]) "content1"))))
@Raynes Owner
Raynes added a note

This is just (:file1 files).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/tentacles/gists.clj
@@ -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 #(:content (second %)) files))))
@Raynes Owner
Raynes added a note

(comp :content second)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jeluard

Thanks for the comments! Should be cleaned now.

@Raynes Raynes merged commit f28a7c8 into Raynes:master
@Raynes
Owner

Awesome! Thank you.

Sorry it took me so long to get to this.

@jeluard

No worries! It wasn't very important anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 13, 2013
  1. @jeluard
  2. @jeluard

    Make helper content centric.

    jeluard authored
Commits on Jul 17, 2013
  1. @jeluard

    Fixed styling issues.

    jeluard authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 1 deletion.
  1. +7 −1 src/tentacles/gists.clj
  2. +10 −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 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)))
View
10 test/tentacles/gists_test.clj
@@ -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"))))
Something went wrong with that request. Please try again.