groupme/groupmeExt/client.go

53 lines
1.2 KiB
Go
Raw Normal View History

2021-02-21 05:58:50 +00:00
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{
2021-02-27 22:38:47 +00:00
// Omit: "memberships",
2021-02-21 05:58:50 +00:00
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
}