v0.1.0 release
Updated tests and client to use the authorization token Fixed readme and added the example to the examples folder
This commit is contained in:
parent
31885d2726
commit
c6f6857cfa
55
README.md
55
README.md
@ -4,6 +4,8 @@ I would like to add common helper functions/features inspired by the package use
|
|||||||
<br>
|
<br>
|
||||||
|
|
||||||
# GroupMe API Wrapper
|
# GroupMe API Wrapper
|
||||||
|

|
||||||
|
[](https://pkg.go.dev/github.com/densestvoid/groupme)
|
||||||
## Description
|
## Description
|
||||||
The design of this package is meant to be super simple. Wrap the exposed API endpoints [documented](https://dev.groupme.com/docs/v3#v3) by the GroupMe team. While you can achieve the core of this package with cURL, there are some small added features, coupled along with a modern language, that should simplify writing GroupMe [bots](https://dev.groupme.com/bots) and [applications](https://dev.groupme.com/applications).
|
The design of this package is meant to be super simple. Wrap the exposed API endpoints [documented](https://dev.groupme.com/docs/v3#v3) by the GroupMe team. While you can achieve the core of this package with cURL, there are some small added features, coupled along with a modern language, that should simplify writing GroupMe [bots](https://dev.groupme.com/bots) and [applications](https://dev.groupme.com/applications).
|
||||||
|
|
||||||
@ -17,51 +19,50 @@ I enjoy programming, I use GroupMe with friends, and I wanted to write a fun add
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/densestvoid/groupme"
|
"github.com/densestvoid/groupme"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This is not a real token. Please find yours by logging
|
// This is not a real token. Please find yours by logging
|
||||||
// into the GroupMe development website: https://dev.groupme.com/
|
// into the GroupMe development website: https://dev.groupme.com/
|
||||||
const authorizationToken = "0123456789ABCDEF"
|
const authorizationToken = "0123456789ABCDEF"
|
||||||
|
|
||||||
|
|
||||||
// A short program that gets the gets the first 5 groups
|
// A short program that gets the gets the first 5 groups
|
||||||
// the user is part of, and then the first 10 messages of
|
// the user is part of, and then the first 10 messages of
|
||||||
// the first group in that list
|
// the first group in that list
|
||||||
func main() {
|
func main() {
|
||||||
// Create a new client with your auth token
|
// Create a new client with your auth token
|
||||||
client := groupme.NewClient(authorizationToken)
|
client := groupme.NewClient(authorizationToken)
|
||||||
|
|
||||||
// Get the groups your user is part of
|
// Get the groups your user is part of
|
||||||
groups, err := client.IndexGroups(&GroupsQuery{
|
groups, err := client.IndexGroups(&groupme.GroupsQuery{
|
||||||
Page: 0,
|
Page: 0,
|
||||||
PerPage: 5,
|
PerPage: 5,
|
||||||
Omit: "memberships",
|
Omit: "memberships",
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(groups)
|
fmt.Println(groups)
|
||||||
|
|
||||||
// Get first 10 messages of the first group
|
// Get first 10 messages of the first group
|
||||||
if len(groups) <= 0 {
|
if len(groups) <= 0 {
|
||||||
fmt.Println("No groups")
|
fmt.Println("No groups")
|
||||||
}
|
}
|
||||||
|
|
||||||
messages, err := client.IndexMessages(groups[0].ID, &IndexMessagesQuery{
|
messages, err := client.IndexMessages(groups[0].ID, &groupme.IndexMessagesQuery{
|
||||||
Limit: 10,
|
Limit: 10,
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(messages)
|
fmt.Println(messages)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ func TestBlocksAPISuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func blocksTestRouter() *mux.Router {
|
func blocksTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
router.Path("/blocks").
|
router.Path("/blocks").
|
||||||
|
@ -73,6 +73,7 @@ Parameters:
|
|||||||
pictureURL - string; image must be processed through image
|
pictureURL - string; image must be processed through image
|
||||||
service (https://dev.groupme.com/docs/image_service)
|
service (https://dev.groupme.com/docs/image_service)
|
||||||
*/
|
*/
|
||||||
|
// TODO: Move PostBotMessage to bot object, since it doesn't require access token
|
||||||
func (c *Client) PostBotMessage(botID ID, text string, pictureURL *string) error {
|
func (c *Client) PostBotMessage(botID ID, text string, pictureURL *string) error {
|
||||||
URL := fmt.Sprintf(c.endpointBase + postBotMessageEndpoint)
|
URL := fmt.Sprintf(c.endpointBase + postBotMessageEndpoint)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ func TestBotsAPISuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botsTestRouter() *mux.Router {
|
func botsTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
router.Path("/bots").
|
router.Path("/bots").
|
||||||
|
@ -35,7 +35,7 @@ func TestChatsAPISuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func chatsTestRouter() *mux.Router {
|
func chatsTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
router.Path("/chats").
|
router.Path("/chats").
|
||||||
|
@ -59,6 +59,11 @@ func (r response) UnmarshalJSON(bs []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) do(req *http.Request, i interface{}) error {
|
func (c Client) do(req *http.Request, i interface{}) error {
|
||||||
|
URL := req.URL
|
||||||
|
query := URL.Query()
|
||||||
|
query.Set("token", c.authorizationToken)
|
||||||
|
URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
getResp, err := c.httpClient.Do(req)
|
getResp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -48,7 +48,7 @@ func TestDirectMessagesAPISuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func directMessagesTestRouter() *mux.Router {
|
func directMessagesTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
router.Path("/direct_messages").
|
router.Path("/direct_messages").
|
||||||
|
48
examples/group_messages/main.go
Normal file
48
examples/group_messages/main.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/densestvoid/groupme"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is not a real token. Please find yours by logging
|
||||||
|
// into the GroupMe development website: https://dev.groupme.com/
|
||||||
|
const authorizationToken = "0123456789ABCDEF"
|
||||||
|
|
||||||
|
// A short program that gets the gets the first 5 groups
|
||||||
|
// the user is part of, and then the first 10 messages of
|
||||||
|
// the first group in that list
|
||||||
|
func main() {
|
||||||
|
// Create a new client with your auth token
|
||||||
|
client := groupme.NewClient(authorizationToken)
|
||||||
|
|
||||||
|
// Get the groups your user is part of
|
||||||
|
groups, err := client.IndexGroups(&groupme.GroupsQuery{
|
||||||
|
Page: 0,
|
||||||
|
PerPage: 5,
|
||||||
|
Omit: "memberships",
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(groups)
|
||||||
|
|
||||||
|
// Get first 10 messages of the first group
|
||||||
|
if len(groups) <= 0 {
|
||||||
|
fmt.Println("No groups")
|
||||||
|
}
|
||||||
|
|
||||||
|
messages, err := client.IndexMessages(groups[0].ID, &groupme.IndexMessagesQuery{
|
||||||
|
Limit: 10,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(messages)
|
||||||
|
}
|
@ -110,7 +110,7 @@ func TestGroupsAPISuite(t *testing.T) {
|
|||||||
////////// Test Groups Router //////////
|
////////// Test Groups Router //////////
|
||||||
|
|
||||||
func groupsTestRouter() *mux.Router {
|
func groupsTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
router.Path("/groups").
|
router.Path("/groups").
|
||||||
|
@ -48,7 +48,7 @@ func TestLeaderboardAPISuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func leaderboardTestRouter() *mux.Router {
|
func leaderboardTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
router.Path("/groups/{id:[0-9]+}/likes").
|
router.Path("/groups/{id:[0-9]+}/likes").
|
||||||
|
@ -29,7 +29,7 @@ func TestLikesAPISuite(t *testing.T) {
|
|||||||
suite.Run(t, new(LikesAPISuite))
|
suite.Run(t, new(LikesAPISuite))
|
||||||
}
|
}
|
||||||
func likesTestRouter() *mux.Router {
|
func likesTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
router.Path(`/messages/{conversation_id}/{message_id}/like`).
|
router.Path(`/messages/{conversation_id}/{message_id}/like`).
|
||||||
|
@ -44,7 +44,7 @@ func TestMembersAPISuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func membersTestRouter() *mux.Router {
|
func membersTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Add
|
// Add
|
||||||
router.Path("/groups/{id:[0-9]+}/members/add").
|
router.Path("/groups/{id:[0-9]+}/members/add").
|
||||||
|
@ -50,7 +50,7 @@ func TestMessagesAPISuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func messagesTestRouter() *mux.Router {
|
func messagesTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
router.Path("/groups/{id:[0-9]+}/messages").
|
router.Path("/groups/{id:[0-9]+}/messages").
|
||||||
|
@ -27,7 +27,7 @@ func TestSMSModeAPISuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func smsModeTestRouter() *mux.Router {
|
func smsModeTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
router.Path("/users/sms_mode").
|
router.Path("/users/sms_mode").
|
||||||
|
@ -32,7 +32,7 @@ func TestUsersAPISuite(t *testing.T) {
|
|||||||
suite.Run(t, new(UsersAPISuite))
|
suite.Run(t, new(UsersAPISuite))
|
||||||
}
|
}
|
||||||
func usersTestRouter() *mux.Router {
|
func usersTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter().Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Me
|
// Me
|
||||||
router.Path("/users/me").
|
router.Path("/users/me").
|
||||||
|
Loading…
x
Reference in New Issue
Block a user