Skip to content

Commit ad3d86c

Browse files
committed
Add contents sample
1 parent 89b80c6 commit ad3d86c

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

samples/Repos/Contents.hs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module GetContents where
2+
3+
import qualified Github.Repos as Github
4+
import Data.List
5+
import Prelude hiding (truncate, getContents)
6+
7+
main = do
8+
putStrLn "Root"
9+
putStrLn "===="
10+
getContents ""
11+
12+
putStrLn "LICENSE"
13+
putStrLn "======="
14+
getContents "LICENSE"
15+
16+
getContents path = do
17+
contents <- Github.contentsFor "mike-burns" "ohlaunch" path Nothing
18+
putStrLn $ either (("Error: " ++) . show) formatContents contents
19+
20+
formatContents (Github.ContentFile fileData) =
21+
formatContentInfo (Github.contentFileInfo fileData) ++
22+
unlines
23+
[ show (Github.contentFileSize fileData) ++ " bytes"
24+
, "encoding: " ++ Github.contentFileEncoding fileData
25+
, "data: " ++ truncate (Github.contentFileContent fileData)
26+
]
27+
28+
formatContents (Github.ContentDirectory items) =
29+
intercalate "\n\n" $ map formatItem items
30+
31+
formatContentInfo contentInfo =
32+
unlines
33+
[ "name: " ++ Github.contentName contentInfo
34+
, "path: " ++ Github.contentPath contentInfo
35+
, "sha: " ++ Github.contentSha contentInfo
36+
, "url: " ++ Github.contentUrl contentInfo
37+
, "git url: " ++ Github.contentGitUrl contentInfo
38+
, "html url: " ++ Github.contentHtmlUrl contentInfo
39+
]
40+
41+
formatItem item =
42+
"type: " ++ show (Github.contentItemType item) ++ "\n" ++
43+
formatContentInfo (Github.contentItemInfo item)
44+
45+
46+
truncate str = take 40 str ++ "... (truncated)"

0 commit comments

Comments
 (0)