String password="";
SketchCode[] theSketches;
String[] theSketchesContent;
GitHubClient client;
GistService service;
GistFile[] file;
String[] filename;
Gist gist = new Gist();
Map<String,GistFile> mp=new HashMap<String, GistFile>();
theSketches=editor.getSketch().getCode();
theSketchesContent = new String[theSketches.length];
file=new GistFile[theSketches.length];
filename = new String[theSketches.length];
int indexOfUsername=-1;
boolean makePrivate=false;
for(int j =0; j<theSketches.length; j++){
file[j]=new GistFile();
if(theSketches[j]==editor.getSketch().getCurrentCode()){//so you don't need to save
theSketchesContent[j]=editor.getText();
}else{
theSketchesContent[j]=theSketches[j].getProgram();
}
if(theSketches[j].getExtension()=="ino" || theSketches[j].getExtension()=="pde"){
indexOfUsername=theSketchesContent[j].indexOf("USE_GITHUB_USERNAME=");
makePrivate=theSketchesContent[j].contains("MAKE_PRIVATE_ON_GITHUB");
if(indexOfUsername!=-1){//if the user specifies a username in the code comments
username=theSketchesContent[j].substring(indexOfUsername+20);
username=username.substring(0,username.indexOf('\n')).trim();
if(table.containsKey(username)){
password=(String) table.get(username);
}else{
System.out.println("No entry found for specified username in gistCredentials.txt, check spelling and try again");
return;
}
}else{ //defaults to first entry in gistCredentials.txt
username=table.keySet().toArray()[0].toString(); //first entry
password=(String) table.get(table.keySet().toArray()[0]);
}
}
}
System.out.println("Sending source to "+username+"'s github account...");
client = new GitHubClient().setCredentials(username, password);
service = new GistService(client);
try{
List<Gist> gists = service.getGists(username);
Boolean foundMatchingGist=false;