Search in sources :

Example 1 with Group

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");
}
Also used : Group(me.perrycate.groupmeutils.data.Group) GroupMe(me.perrycate.groupmeutils.api.GroupMe) Dumper(me.perrycate.groupmeutils.Dumper) File(java.io.File)

Example 2 with Group

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;
}
Also used : Group(me.perrycate.groupmeutils.data.Group) GroupMessages(me.perrycate.groupmeutils.data.GroupMessages) ChunkStorage(me.perrycate.groupmeutils.util.ChunkStorage)

Example 3 with Group

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;
}
Also used : JsonArray(com.google.gson.JsonArray) Group(me.perrycate.groupmeutils.data.Group) JsonElement(com.google.gson.JsonElement)

Example 4 with Group

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();
}
Also used : Scanner(java.util.Scanner) Group(me.perrycate.groupmeutils.data.Group) GroupMe(me.perrycate.groupmeutils.api.GroupMe) File(java.io.File)

Example 5 with Group

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);
}
Also used : Group(me.perrycate.groupmeutils.data.Group) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader)

Aggregations

Group (me.perrycate.groupmeutils.data.Group)8 GroupMe (me.perrycate.groupmeutils.api.GroupMe)5 File (java.io.File)4 Scanner (java.util.Scanner)3 Dumper (me.perrycate.groupmeutils.Dumper)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 GroupMessages (me.perrycate.groupmeutils.data.GroupMessages)1 Member (me.perrycate.groupmeutils.data.Member)1 ChunkStorage (me.perrycate.groupmeutils.util.ChunkStorage)1