use of me.perrycate.groupmeutils.data.Group in project groupme-utils by TheGuyWithTheFace.
the class Append method main.
public static void main(String[] args) {
System.out.println("starting");
// required info
String token = "YOUR TOKEN HERE";
// Test Group
String groupId = "GROUP ID HERE";
GroupMe groupme = new GroupMe(token);
Group group = groupme.getGroup(groupId);
Dumper dumper = new Dumper(groupme, group);
dumper.append(new File("testfile.txt"));
System.out.println("Complete");
}
use of me.perrycate.groupmeutils.data.Group in project groupme-utils by TheGuyWithTheFace.
the class MessageIterator method getAllMessages.
/*
* Get each message starting from bottom.
*
* @return a ChunkStorage object containing all messages belonging to the
* given group, in chunks of GroupMessages.MAX_MESSAGES.
*
*/
private ChunkStorage getAllMessages(GroupMe api, String groupID) {
// We use hold messages in groups of 100 in ChunkStorage to avoid
// attempting to store the entire group in memory while still not
// duplicating any network calls.
Group group = api.getGroup(groupID);
int totalMessages = group.getMessageCount();
String lastMessageId = group.getLastMessageId();
ChunkStorage storage = new ChunkStorage();
// Dump all messages to chunk storage
GroupMessages messages;
for (int i = 0; i < totalMessages; i += GroupMessages.MAX_MESSAGES) {
messages = api.getMessagesBefore(groupID, lastMessageId);
byte[] data = ByteConverter.objectToBytes(messages);
storage.addFirst(data);
lastMessageId = messages.getMessage(messages.getMessages().length - 1).getId();
}
return storage;
}
use of me.perrycate.groupmeutils.data.Group in project groupme-utils by TheGuyWithTheFace.
the class GroupArrayDeserializer method deserialize.
public Group[] deserialize(JsonElement jsonElement, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonArray response = getResponse(jsonElement).getAsJsonArray();
// Deserialize one group at a time, add to new groups array.
int numGroups = response.size();
Group[] groups = new Group[numGroups];
for (int i = 0; i < numGroups; i++) {
JsonElement elem = response.get(i);
groups[i] = context.deserialize(elem, Group.class);
}
return groups;
}
use of me.perrycate.groupmeutils.data.Group in project groupme-utils by TheGuyWithTheFace.
the class Dumper method main.
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
// User auth
System.out.println("Please enter your GroupMe API Token: ");
String token = s.nextLine();
GroupMe api = new GroupMe(token);
// Group Selection
System.out.println("Fetching groups list...");
Group[] groups = api.getGroups();
for (int i = 0; i < groups.length; i++) {
System.out.format("[%d] %s\n", i, groups[i].getName());
}
System.out.print("Please select a group to dump: ");
Group selectedGroup = groups[s.nextInt()];
System.out.println("Selected \"" + selectedGroup.getName() + "\".");
// Initialize dumper
Dumper dumper = new Dumper(api, selectedGroup);
// Skip newline
s.nextLine();
// Get file to use, determine if we're writing a new one or appending
System.out.print("Enter a file name: ");
File fileToWrite = new File(s.nextLine());
if (fileToWrite.isFile()) {
// Append if applicable
System.out.println("File already exists. Append to this file? [Y/n]");
String response = s.nextLine();
if (response.toLowerCase().trim().startsWith("n")) {
System.out.println("Fine then. Exiting...");
s.close();
return;
}
// Append
long startTime = System.currentTimeMillis();
// int messagesAdded = dumper.append(fileToWrite);
dumper.append(fileToWrite);
long elapsedTime = System.currentTimeMillis() - startTime;
// Exit
System.out.format("Completed in %d seconds. Goodbye!", (int) (elapsedTime / 1000 + .5));
} else {
// Dump otherwise.
System.out.println("Create new file " + fileToWrite + "? [Y/n]");
String response = s.nextLine();
if (response.toLowerCase().trim().startsWith("n")) {
System.out.println("Fine then. Exiting...");
s.close();
return;
}
// Append
long startTime = System.currentTimeMillis();
System.out.println("Dumping...");
int messagesDumped = dumper.dump(fileToWrite);
long elapsedTime = System.currentTimeMillis() - startTime;
// Exit
System.out.format("Dumped %d messages in %.1f seconds. Goodbye!", messagesDumped, (double) (elapsedTime / 1000));
}
s.close();
}
use of me.perrycate.groupmeutils.data.Group in project groupme-utils by TheGuyWithTheFace.
the class GroupMe method getGroups.
/**
* Returns an array of Groups that the user is in.
*/
public Group[] getGroups() {
String target = "/groups";
InputStream resultStream = HTTP.makeGETRequest(createUrl(target));
Reader reader = new InputStreamReader(resultStream);
return gson.fromJson(reader, Group[].class);
}
Aggregations