Last active
August 29, 2015 14:25
-
-
Save josephbales/c7f74ce9f5b3176e2b04 to your computer and use it in GitHub Desktop.
Getting Gist contents via Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.josephbales.test1.testapp1; | |
/* | |
* Github libraries available through Maven | |
* Or here: https://github.com/eclipse/egit-github/tree/master/org.eclipse.egit.github.core | |
*/ | |
import java.io.IOException; | |
import java.util.Collection; | |
import java.util.Map; | |
import org.eclipse.egit.github.core.*; | |
import org.eclipse.egit.github.core.service.*; | |
public class App | |
{ | |
public static void main( String[] args ) | |
{ | |
// String value for a gist | |
String gistID = "24f835c63f4d3c1af777"; | |
// Create a GistService instance | |
GistService gService = new GistService(); | |
try { | |
// Get the Gist you want to find the contents of | |
Gist gist = gService.getGist(gistID); | |
// Obtain a Map of the GistFiles within the Gist | |
Map<String, GistFile> gfMap = gist.getFiles(); | |
// Obtain a Collection of the GistFiles from the Map | |
Collection<GistFile> lGf = gfMap.values(); | |
// For each GistFile in the Collection print the filename and content | |
for (GistFile gf : lGf) { | |
System.out.println(gf.getFilename()); | |
System.out.println(gf.getContent()); | |
} | |
} | |
catch (IOException e) { | |
// Print a nasty stack trace on failure | |
e.printStackTrace(); | |
} | |
// I'm too dumb to know when the script is done so print a message here | |
System.out.println("Done"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment