groupme/groupmeExt/client.go
Karmanyaah Malhotra 7cb9983da8 super basic
2021-02-21 00:59:07 -05:00

53 lines
1.2 KiB
Go

package groupmeExt
import (
"context"
"fmt"
"github.com/karmanyaahm/groupme"
)
type Client struct {
*groupme.Client
}
// NewClient creates a new GroupMe API Client
func NewClient(authToken string) *Client {
n := Client{
Client: groupme.NewClient(authToken),
}
return &n
}
func (c Client) IndexAllGroups() ([]*groupme.Group, error) {
return c.IndexGroups(context.TODO(), &groupme.GroupsQuery{
Omit: "memberships",
PerPage: 100, //TODO: Configurable and add multipage support
})
}
func (c Client) LoadMessagesAfter(groupID, lastMessageID string, lastMessageFromMe bool, num int) ([]*groupme.Message, error) {
//TODO: limit max 100
i, e := c.IndexMessages(context.TODO(), groupme.ID(groupID), &groupme.IndexMessagesQuery{
AfterID: groupme.ID(lastMessageID),
Limit: num,
})
if e != nil {
return nil, e
}
return i.Messages, nil
}
func (c Client) LoadMessagesBefore(groupID, lastMessageID string, num int) ([]*groupme.Message, error) {
//TODO: limit max 100
i, e := c.IndexMessages(context.TODO(), groupme.ID(groupID), &groupme.IndexMessagesQuery{
BeforeID: groupme.ID(lastMessageID),
Limit: num,
})
fmt.Println(groupID, lastMessageID, num, i.Count, e)
if e != nil {
return nil, e
}
return i.Messages, nil
}