Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
d657643538 | |||
3e663f8615 | |||
eea12a3b50 | |||
e6f29c4e73 | |||
cd2551461d | |||
2ff9a03a8c | |||
f900b99dac | |||
d8cdcf4ef2 | |||
010fd832ac | |||
bd76de2ffe | |||
537a97ebe7 | |||
9ee368f10d | |||
d9dec16e27 | |||
755d681f86 | |||
f0aa4a6d73 |
29
.github/workflows/go-test.yml
vendored
Normal file
29
.github/workflows/go-test.yml
vendored
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
name: test
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- v*
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: 1.14
|
||||||
|
|
||||||
|
- name: Check out code
|
||||||
|
uses: actions/checkout@v1
|
||||||
|
|
||||||
|
- name: Run Unit tests.
|
||||||
|
run: go test -coverprofile cover.out -covermode=atomic ${PKG_LIST} && cat cover.out >> coverage.txt
|
||||||
|
|
||||||
|
- name: Upload Coverage report to CodeCov
|
||||||
|
uses: codecov/codecov-action@v1.0.0
|
||||||
|
with:
|
||||||
|
token: ${{secrets.CODECOV_TOKEN}}
|
||||||
|
file: ./coverage.txt
|
15
.github/workflows/golangci-lint.yml
vendored
Normal file
15
.github/workflows/golangci-lint.yml
vendored
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
- name: Run golangci-lint
|
||||||
|
# You may pin to the exact commit or the version.
|
||||||
|
# uses: golangci/golangci-lint-action@04eca2038305127fb1e6683425b6864cd5612f2d
|
||||||
|
uses: golangci/golangci-lint-action@v1.2.1
|
||||||
|
with:
|
||||||
|
# version of golangci-lint to use in form of v1.2.3
|
||||||
|
version:
|
||||||
|
# golangci-lint command line arguments
|
||||||
|
args: # optional, default is
|
||||||
|
# golangci-lint working directory, default is project root
|
||||||
|
working-directory: # optional
|
||||||
|
# the token is used for fetching patch of a pull request to show only new issues
|
||||||
|
github-token: # default is ${{ github.token }}
|
||||||
|
# if set to true and the action runs on a pull request - the action outputs only newly found issues
|
||||||
|
only-new-issues:
|
@ -6,6 +6,7 @@ I would like to add common helper functions/features inspired by the package use
|
|||||||
# GroupMe API Wrapper
|
# GroupMe API Wrapper
|
||||||

|

|
||||||
[](https://pkg.go.dev/github.com/densestvoid/groupme)
|
[](https://pkg.go.dev/github.com/densestvoid/groupme)
|
||||||
|
[](https://codecov.io/gh/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).
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ func (c *Client) IndexBlock(userID ID) ([]*Block, error) {
|
|||||||
var resp struct {
|
var resp struct {
|
||||||
Blocks []*Block `json:"blocks"`
|
Blocks []*Block `json:"blocks"`
|
||||||
}
|
}
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -77,7 +77,7 @@ func (c *Client) BlockBetween(userID, otherUserID ID) (bool, error) {
|
|||||||
var resp struct {
|
var resp struct {
|
||||||
Between bool `json:"between"`
|
Between bool `json:"between"`
|
||||||
}
|
}
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ func (c *Client) CreateBlock(userID, otherUserID ID) (*Block, error) {
|
|||||||
var resp struct {
|
var resp struct {
|
||||||
Block *Block `json:"block"`
|
Block *Block `json:"block"`
|
||||||
}
|
}
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -142,7 +142,7 @@ func (c *Client) Unblock(userID, otherUserID ID) error {
|
|||||||
query.Set("otherUser", otherUserID.String())
|
query.Set("otherUser", otherUserID.String())
|
||||||
URL.RawQuery = query.Encode()
|
URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
err = c.do(httpReq, nil)
|
err = c.doWithAuthToken(httpReq, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
68
bots_api.go
68
bots_api.go
@ -1,10 +1,10 @@
|
|||||||
package groupme
|
package groupme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GroupMe documentation: https://dev.groupme.com/docs/v3#bots
|
// GroupMe documentation: https://dev.groupme.com/docs/v3#bots
|
||||||
@ -37,22 +37,26 @@ Parameters:
|
|||||||
GroupID - required
|
GroupID - required
|
||||||
*/
|
*/
|
||||||
func (c *Client) CreateBot(bot *Bot) (*Bot, error) {
|
func (c *Client) CreateBot(bot *Bot) (*Bot, error) {
|
||||||
httpReq, err := http.NewRequest("POST", c.endpointBase+createBotEndpoint, nil)
|
URL := c.endpointBase + createBotEndpoint
|
||||||
|
|
||||||
|
var data = struct {
|
||||||
|
Bot *Bot `json:"bot,omitempty"`
|
||||||
|
}{
|
||||||
|
bot,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if bot == nil {
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
return nil, errors.New("bot cannot be nil")
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
|
||||||
data.Add("bot", bot.String())
|
|
||||||
|
|
||||||
httpReq.PostForm = data
|
|
||||||
|
|
||||||
var resp Bot
|
var resp Bot
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -77,20 +81,26 @@ Parameters:
|
|||||||
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)
|
||||||
|
|
||||||
httpReq, err := http.NewRequest("POST", URL, nil)
|
var data = struct {
|
||||||
|
BotID ID `json:"bot_id"`
|
||||||
|
Text string `json:"text"`
|
||||||
|
PictureURL *string `json:",omitempty"`
|
||||||
|
}{
|
||||||
|
botID,
|
||||||
|
text,
|
||||||
|
pictureURL,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
data.Add("bot_id", string(botID))
|
if err != nil {
|
||||||
data.Add("text", text)
|
return err
|
||||||
if pictureURL != nil {
|
|
||||||
data.Add("picture_url", *pictureURL)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
httpReq.PostForm = data
|
|
||||||
|
|
||||||
return c.do(httpReq, nil)
|
return c.do(httpReq, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,7 +118,7 @@ func (c *Client) IndexBots() ([]*Bot, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resp []*Bot
|
var resp []*Bot
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -129,15 +139,21 @@ Parameters:
|
|||||||
func (c *Client) DestroyBot(botID ID) error {
|
func (c *Client) DestroyBot(botID ID) error {
|
||||||
URL := fmt.Sprintf(c.endpointBase + destroyBotEndpoint)
|
URL := fmt.Sprintf(c.endpointBase + destroyBotEndpoint)
|
||||||
|
|
||||||
httpReq, err := http.NewRequest("POST", URL, nil)
|
var data = struct {
|
||||||
|
BotID ID `json:"bot_id"`
|
||||||
|
}{
|
||||||
|
botID,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
data.Add("bot_id", string(botID))
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
httpReq.PostForm = data
|
return c.doWithAuthToken(httpReq, nil)
|
||||||
|
|
||||||
return c.do(httpReq, nil)
|
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,11 @@ func TestBotsAPISuite(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func botsTestRouter() *mux.Router {
|
func botsTestRouter() *mux.Router {
|
||||||
router := mux.NewRouter().Queries("token", "").Subrouter()
|
router := mux.NewRouter()
|
||||||
|
authRouter := router.Queries("token", "").Subrouter()
|
||||||
|
|
||||||
// Create
|
// Create
|
||||||
router.Path("/bots").
|
authRouter.Path("/bots").
|
||||||
Methods("POST").
|
Methods("POST").
|
||||||
Name("CreateBot").
|
Name("CreateBot").
|
||||||
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
@ -84,7 +85,7 @@ func botsTestRouter() *mux.Router {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Index
|
// Index
|
||||||
router.Path("/bots").
|
authRouter.Path("/bots").
|
||||||
Methods("GET").
|
Methods("GET").
|
||||||
Name("IndexBots").
|
Name("IndexBots").
|
||||||
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
@ -108,7 +109,7 @@ func botsTestRouter() *mux.Router {
|
|||||||
})
|
})
|
||||||
|
|
||||||
// Destroy
|
// Destroy
|
||||||
router.Path("/bots/destroy").
|
authRouter.Path("/bots/destroy").
|
||||||
Methods("POST").
|
Methods("POST").
|
||||||
Name("DestroyBot").
|
Name("DestroyBot").
|
||||||
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
|
@ -52,7 +52,7 @@ func (c *Client) IndexChats(req *IndexChatsQuery) ([]*Chat, error) {
|
|||||||
URL.RawQuery = query.Encode()
|
URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
var resp []*Chat
|
var resp []*Chat
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
34
client.go
34
client.go
@ -3,7 +3,7 @@ package groupme
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@ -23,7 +23,8 @@ type Client struct {
|
|||||||
// NewClient creates a new GroupMe API Client
|
// NewClient creates a new GroupMe API Client
|
||||||
func NewClient(authToken string) *Client {
|
func NewClient(authToken string) *Client {
|
||||||
return &Client{
|
return &Client{
|
||||||
httpClient: new(http.Client),
|
// TODO: enable transport information passing in
|
||||||
|
httpClient: &http.Client{},
|
||||||
endpointBase: GroupMeAPIBase,
|
endpointBase: GroupMeAPIBase,
|
||||||
authorizationToken: authToken,
|
authorizationToken: authToken,
|
||||||
}
|
}
|
||||||
@ -59,24 +60,24 @@ 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
|
if req.Method == "POST" {
|
||||||
query := URL.Query()
|
req.Header.Set("Content-Type", "application/json")
|
||||||
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
|
||||||
}
|
}
|
||||||
|
defer getResp.Body.Close()
|
||||||
|
|
||||||
|
bytes, err := ioutil.ReadAll(getResp.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Check Status Code is 1XX or 2XX
|
// Check Status Code is 1XX or 2XX
|
||||||
if getResp.StatusCode/100 > 2 {
|
if getResp.StatusCode/100 > 2 {
|
||||||
return errors.New(getResp.Status)
|
return fmt.Errorf("%s: %s", getResp.Status, string(bytes))
|
||||||
}
|
|
||||||
|
|
||||||
bytes, err := ioutil.ReadAll(getResp.Body)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if i == nil {
|
if i == nil {
|
||||||
@ -95,3 +96,12 @@ func (c Client) do(req *http.Request, i interface{}) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Client) doWithAuthToken(req *http.Request, i interface{}) error {
|
||||||
|
URL := req.URL
|
||||||
|
query := URL.Query()
|
||||||
|
query.Set("token", c.authorizationToken)
|
||||||
|
URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
|
return c.do(req, i)
|
||||||
|
}
|
||||||
|
@ -30,6 +30,14 @@ func (s *ClientSuite) TestClient_Close() {
|
|||||||
s.Assert().NoError(s.client.Close())
|
s.Assert().NoError(s.client.Close())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *ClientSuite) TestClient_do_PostContentType() {
|
||||||
|
req, err := http.NewRequest("POST", "", nil)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
s.Assert().Error(s.client.do(req, struct{}{}))
|
||||||
|
s.Assert().EqualValues(req.Header.Get("Content-Type"), "application/json")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *ClientSuite) TestClient_do_DoError() {
|
func (s *ClientSuite) TestClient_do_DoError() {
|
||||||
req, err := http.NewRequest("", "", nil)
|
req, err := http.NewRequest("", "", nil)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package groupme
|
package groupme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
@ -83,7 +84,7 @@ func (c *Client) IndexDirectMessages(otherUserID ID, req *IndexDirectMessagesQue
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resp IndexDirectMessagesResponse
|
var resp IndexDirectMessagesResponse
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return IndexDirectMessagesResponse{}, err
|
return IndexDirectMessagesResponse{}, err
|
||||||
}
|
}
|
||||||
@ -121,22 +122,28 @@ Parameters:
|
|||||||
*/
|
*/
|
||||||
func (c *Client) CreateDirectMessage(m *Message) (*Message, error) {
|
func (c *Client) CreateDirectMessage(m *Message) (*Message, error) {
|
||||||
URL := fmt.Sprintf(c.endpointBase + createDirectMessageEndpoint)
|
URL := fmt.Sprintf(c.endpointBase + createDirectMessageEndpoint)
|
||||||
httpReq, err := http.NewRequest("POST", URL, nil)
|
|
||||||
|
m.SourceGUID = uuid.New().String()
|
||||||
|
var data = struct {
|
||||||
|
DirectMessage *Message `json:"direct_message,omitempty"`
|
||||||
|
}{
|
||||||
|
m,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
m.SourceGUID = uuid.New().String()
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
|
if err != nil {
|
||||||
data := url.Values{}
|
return nil, err
|
||||||
data.Set("direct_message", m.String())
|
}
|
||||||
|
|
||||||
httpReq.PostForm = data
|
|
||||||
|
|
||||||
var resp struct {
|
var resp struct {
|
||||||
*Message `json:"message"`
|
*Message `json:"message"`
|
||||||
}
|
}
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
20
examples/post_bot_message/main.go
Normal file
20
examples/post_bot_message/main.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/densestvoid/groupme"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This is not a real Bot ID. Please find yours by logging
|
||||||
|
// into the GroupMe development website: https://dev.groupme.com/bots
|
||||||
|
const botID = "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("")
|
||||||
|
fmt.Println(client.PostBotMessage(botID, "Your message here!", nil))
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
package groupme
|
package groupme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ func (c *Client) IndexGroups(req *GroupsQuery) ([]*Group, error) {
|
|||||||
URL.RawQuery = query.Encode()
|
URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
var resp []*Group
|
var resp []*Group
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -127,7 +128,7 @@ func (c *Client) FormerGroups() ([]*Group, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resp []*Group
|
var resp []*Group
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -154,7 +155,7 @@ func (c *Client) ShowGroup(groupID ID) (*Group, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resp Group
|
var resp Group
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -172,30 +173,20 @@ Create a new group
|
|||||||
Parameters: See GroupSettings
|
Parameters: See GroupSettings
|
||||||
*/
|
*/
|
||||||
func (c *Client) CreateGroup(gs GroupSettings) (*Group, error) {
|
func (c *Client) CreateGroup(gs GroupSettings) (*Group, error) {
|
||||||
httpReq, err := http.NewRequest("POST", c.endpointBase+createGroupEndpoint, nil)
|
URL := fmt.Sprintf(c.endpointBase + createGroupEndpoint)
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(&gs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
if gs.Name == "" {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("GroupsCreateRequest Name field is required")
|
return nil, err
|
||||||
}
|
}
|
||||||
data.Set("name", gs.Name)
|
|
||||||
|
|
||||||
if gs.Description != "" {
|
|
||||||
data.Set("description", gs.Description)
|
|
||||||
}
|
|
||||||
if gs.ImageURL != "" {
|
|
||||||
data.Set("image_url", gs.ImageURL)
|
|
||||||
}
|
|
||||||
if gs.Share {
|
|
||||||
data.Set("share", "true")
|
|
||||||
}
|
|
||||||
httpReq.PostForm = data
|
|
||||||
|
|
||||||
var resp Group
|
var resp Group
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -217,31 +208,18 @@ Parameters:
|
|||||||
func (c *Client) UpdateGroup(groupID ID, gs GroupSettings) (*Group, error) {
|
func (c *Client) UpdateGroup(groupID ID, gs GroupSettings) (*Group, error) {
|
||||||
URL := fmt.Sprintf(c.endpointBase+updateGroupEndpoint, groupID)
|
URL := fmt.Sprintf(c.endpointBase+updateGroupEndpoint, groupID)
|
||||||
|
|
||||||
httpReq, err := http.NewRequest("POST", URL, nil)
|
jsonBytes, err := json.Marshal(&gs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
if gs.Name != "" {
|
if err != nil {
|
||||||
data.Set("name", gs.Name)
|
return nil, err
|
||||||
}
|
}
|
||||||
if gs.Description != "" {
|
|
||||||
data.Set("description", gs.Description)
|
|
||||||
}
|
|
||||||
if gs.ImageURL != "" {
|
|
||||||
data.Set("image_url", gs.ImageURL)
|
|
||||||
}
|
|
||||||
if gs.OfficeMode {
|
|
||||||
data.Set("office_mode", "true")
|
|
||||||
}
|
|
||||||
if gs.Share {
|
|
||||||
data.Set("share", "true")
|
|
||||||
}
|
|
||||||
httpReq.PostForm = data
|
|
||||||
|
|
||||||
var resp Group
|
var resp Group
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -269,7 +247,7 @@ func (c *Client) DestroyGroup(groupID ID) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.do(httpReq, nil)
|
return c.doWithAuthToken(httpReq, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
///// Join /////
|
///// Join /////
|
||||||
@ -292,7 +270,7 @@ func (c *Client) JoinGroup(groupID ID, shareToken string) (*Group, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resp Group
|
var resp Group
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -311,17 +289,26 @@ Parameters:
|
|||||||
groupID - required, ID(string)
|
groupID - required, ID(string)
|
||||||
*/
|
*/
|
||||||
func (c *Client) RejoinGroup(groupID ID) (*Group, error) {
|
func (c *Client) RejoinGroup(groupID ID) (*Group, error) {
|
||||||
httpReq, err := http.NewRequest("POST", c.endpointBase+rejoinGroupEndpoint, nil)
|
URL := fmt.Sprintf(c.endpointBase + rejoinGroupEndpoint)
|
||||||
|
|
||||||
|
var data = struct {
|
||||||
|
GroupID ID `json:"group_id"`
|
||||||
|
}{
|
||||||
|
groupID,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
data.Set("group_id", string(groupID))
|
if err != nil {
|
||||||
httpReq.PostForm = data
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
var resp Group
|
var resp Group
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -344,20 +331,29 @@ the result of change owner action for the request
|
|||||||
Parameters: See ChangeOwnerRequest
|
Parameters: See ChangeOwnerRequest
|
||||||
*/
|
*/
|
||||||
func (c *Client) ChangeGroupOwner(reqs ChangeOwnerRequest) (ChangeOwnerResult, error) {
|
func (c *Client) ChangeGroupOwner(reqs ChangeOwnerRequest) (ChangeOwnerResult, error) {
|
||||||
httpReq, err := http.NewRequest("POST", c.endpointBase+changeGroupOwnerEndpoint, nil)
|
URL := fmt.Sprintf(c.endpointBase + changeGroupOwnerEndpoint)
|
||||||
|
|
||||||
|
var data = struct {
|
||||||
|
Requests []ChangeOwnerRequest `json:"requests"`
|
||||||
|
}{
|
||||||
|
[]ChangeOwnerRequest{reqs},
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ChangeOwnerResult{}, err
|
return ChangeOwnerResult{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
data.Set("requests", marshal([]ChangeOwnerRequest{reqs}))
|
if err != nil {
|
||||||
httpReq.PostForm = data
|
return ChangeOwnerResult{}, err
|
||||||
|
}
|
||||||
|
|
||||||
var resp struct {
|
var resp struct {
|
||||||
Results []ChangeOwnerResult `json:"results"`
|
Results []ChangeOwnerResult `json:"results"`
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ChangeOwnerResult{}, err
|
return ChangeOwnerResult{}, err
|
||||||
}
|
}
|
||||||
|
@ -56,14 +56,6 @@ func (s *GroupsAPISuite) TestGroupsCreate() {
|
|||||||
s.Assert().NotZero(group)
|
s.Assert().NotZero(group)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *GroupsAPISuite) TestGroupsCreate_EmptyName() {
|
|
||||||
group, err := s.client.CreateGroup(GroupSettings{
|
|
||||||
Name: "",
|
|
||||||
})
|
|
||||||
s.Require().Error(err)
|
|
||||||
s.Assert().Zero(group)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *GroupsAPISuite) TestGroupsUpdate() {
|
func (s *GroupsAPISuite) TestGroupsUpdate() {
|
||||||
group, err := s.client.UpdateGroup("1", GroupSettings{
|
group, err := s.client.UpdateGroup("1", GroupSettings{
|
||||||
"Test",
|
"Test",
|
||||||
|
158
json.go
158
json.go
@ -8,8 +8,8 @@ import (
|
|||||||
// Meta is the error type returned in the GroupMe response.
|
// Meta is the error type returned in the GroupMe response.
|
||||||
// Meant for clients that can't read HTTP status codes
|
// Meant for clients that can't read HTTP status codes
|
||||||
type Meta struct {
|
type Meta struct {
|
||||||
Code HTTPStatusCode `json:"code"`
|
Code HTTPStatusCode `json:"code,omitempty"`
|
||||||
Errors []string `json:"errors"`
|
Errors []string `json:"errors,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Error returns the code and the error list as a string.
|
// Error returns the code and the error list as a string.
|
||||||
@ -20,35 +20,35 @@ func (m Meta) Error() string {
|
|||||||
|
|
||||||
// Group is a GroupMe group, returned in JSON API responses
|
// Group is a GroupMe group, returned in JSON API responses
|
||||||
type Group struct {
|
type Group struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
// Type of group (private|public)
|
// Type of group (private|public)
|
||||||
Type string `json:"type"`
|
Type string `json:"type,omitempty"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description,omitempty"`
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
CreatorUserID ID `json:"creator_user_id"`
|
CreatorUserID ID `json:"creator_user_id,omitempty"`
|
||||||
CreatedAt Timestamp `json:"created_at"`
|
CreatedAt Timestamp `json:"created_at,omitempty"`
|
||||||
UpdatedAt Timestamp `json:"updated_at"`
|
UpdatedAt Timestamp `json:"updated_at,omitempty"`
|
||||||
Members []*Member `json:"members"`
|
Members []*Member `json:"members,omitempty"`
|
||||||
ShareURL string `json:"share_url"`
|
ShareURL string `json:"share_url,omitempty"`
|
||||||
Messages GroupMessages `json:"messages"`
|
Messages GroupMessages `json:"messages,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupMessages is a Group field, only returned in Group JSON API responses
|
// GroupMessages is a Group field, only returned in Group JSON API responses
|
||||||
type GroupMessages struct {
|
type GroupMessages struct {
|
||||||
Count uint `json:"count"`
|
Count uint `json:"count,omitempty"`
|
||||||
LastMessageID ID `json:"last_message_id"`
|
LastMessageID ID `json:"last_message_id,omitempty"`
|
||||||
LastMessageCreatedAt Timestamp `json:"last_message_created_at"`
|
LastMessageCreatedAt Timestamp `json:"last_message_created_at,omitempty"`
|
||||||
Preview MessagePreview `json:"preview"`
|
Preview MessagePreview `json:"preview,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessagePreview is a GroupMessages field, only returned in Group JSON API responses.
|
// MessagePreview is a GroupMessages field, only returned in Group JSON API responses.
|
||||||
// Abbreviated form of Message type
|
// Abbreviated form of Message type
|
||||||
type MessagePreview struct {
|
type MessagePreview struct {
|
||||||
Nickname string `json:"nickname"`
|
Nickname string `json:"nickname,omitempty"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text,omitempty"`
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
Attachments []*Attachment `json:"attachments"`
|
Attachments []*Attachment `json:"attachments,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetMemberByUserID gets the group member by their UserID,
|
// GetMemberByUserID gets the group member by their UserID,
|
||||||
@ -81,14 +81,16 @@ func (g Group) String() string {
|
|||||||
|
|
||||||
// Member is a GroupMe group member, returned in JSON API responses
|
// Member is a GroupMe group member, returned in JSON API responses
|
||||||
type Member struct {
|
type Member struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id,omitempty"`
|
||||||
UserID ID `json:"user_id"`
|
UserID ID `json:"user_id,omitempty"`
|
||||||
Nickname string `json:"nickname"`
|
Nickname string `json:"nickname,omitempty"`
|
||||||
Muted bool `json:"muted"`
|
Muted bool `json:"muted,omitempty"`
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
AutoKicked bool `json:"autokicked"`
|
AutoKicked bool `json:"autokicked,omitempty"`
|
||||||
AppInstalled bool `json:"app_installed"`
|
AppInstalled bool `json:"app_installed,omitempty"`
|
||||||
GUID string `json:"guid"`
|
GUID string `json:"guid,omitempty"`
|
||||||
|
PhoneNumber string `json:"phone_number,omitempty"` // Only used when searching for the member to add to a group.
|
||||||
|
Email string `json:"email,omitempty"` // Only used when searching for the member to add to a group.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Member) String() string {
|
func (m Member) String() string {
|
||||||
@ -97,25 +99,25 @@ func (m Member) String() string {
|
|||||||
|
|
||||||
// Message is a GroupMe group message, returned in JSON API responses
|
// Message is a GroupMe group message, returned in JSON API responses
|
||||||
type Message struct {
|
type Message struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id,omitempty"`
|
||||||
SourceGUID string `json:"source_guid"`
|
SourceGUID string `json:"source_guid,omitempty"`
|
||||||
CreatedAt Timestamp `json:"created_at"`
|
CreatedAt Timestamp `json:"created_at,omitempty"`
|
||||||
GroupID ID `json:"group_id"`
|
GroupID ID `json:"group_id,omitempty"`
|
||||||
UserID ID `json:"user_id"`
|
UserID ID `json:"user_id,omitempty"`
|
||||||
BotID ID `json:"bot_id"`
|
BotID ID `json:"bot_id,omitempty"`
|
||||||
SenderID ID `json:"sender_id"`
|
SenderID ID `json:"sender_id,omitempty"`
|
||||||
SenderType SenderType `json:"sender_type"`
|
SenderType SenderType `json:"sender_type,omitempty"`
|
||||||
System bool `json:"system"`
|
System bool `json:"system,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
RecipientID ID `json:"recipient_id"`
|
RecipientID ID `json:"recipient_id,omitempty"`
|
||||||
ConversationID ID `json:"conversation_id"`
|
ConversationID ID `json:"conversation_id,omitempty"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url,omitempty"`
|
||||||
// Maximum length of 1000 characters
|
// Maximum length of 1000 characters
|
||||||
Text string `json:"text"`
|
Text string `json:"text,omitempty"`
|
||||||
// Must be an image service URL (i.groupme.com)
|
// Must be an image service URL (i.groupme.com)
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
FavoritedBy []string `json:"favorited_by"`
|
FavoritedBy []string `json:"favorited_by,omitempty"`
|
||||||
Attachments []*Attachment `json:"attachments"`
|
Attachments []*Attachment `json:"attachments,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Message) String() string {
|
func (m Message) String() string {
|
||||||
@ -143,15 +145,15 @@ const (
|
|||||||
|
|
||||||
// Attachment is a GroupMe message attachment, returned in JSON API responses
|
// Attachment is a GroupMe message attachment, returned in JSON API responses
|
||||||
type Attachment struct {
|
type Attachment struct {
|
||||||
Type AttachmentType `json:"type"`
|
Type AttachmentType `json:"type,omitempty"`
|
||||||
Loci [][]int `json:"loci"`
|
Loci [][]int `json:"loci,omitempty"`
|
||||||
UserIDs []ID `json:"user_ids"`
|
UserIDs []ID `json:"user_ids,omitempty"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
Latitude string `json:"lat"`
|
Latitude string `json:"lat,omitempty"`
|
||||||
Longitude string `json:"lng"`
|
Longitude string `json:"lng,omitempty"`
|
||||||
Placeholder string `json:"placeholder"`
|
Placeholder string `json:"placeholder,omitempty"`
|
||||||
Charmap [][]int `json:"charmap"`
|
Charmap [][]int `json:"charmap,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Attachment) String() string {
|
func (a Attachment) String() string {
|
||||||
@ -160,15 +162,15 @@ func (a Attachment) String() string {
|
|||||||
|
|
||||||
// User is a GroupMe user, returned in JSON API responses
|
// User is a GroupMe user, returned in JSON API responses
|
||||||
type User struct {
|
type User struct {
|
||||||
ID ID `json:"id"`
|
ID ID `json:"id,omitempty"`
|
||||||
PhoneNumber PhoneNumber `json:"phone_number"`
|
PhoneNumber PhoneNumber `json:"phone_number,omitempty"`
|
||||||
ImageURL string `json:"image_url"`
|
ImageURL string `json:"image_url,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
CreatedAt Timestamp `json:"created_at"`
|
CreatedAt Timestamp `json:"created_at,omitempty"`
|
||||||
UpdatedAt Timestamp `json:"updated_at"`
|
UpdatedAt Timestamp `json:"updated_at,omitempty"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url,omitempty"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email,omitempty"`
|
||||||
SMS bool `json:"sms"`
|
SMS bool `json:"sms,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) String() string {
|
func (u User) String() string {
|
||||||
@ -178,11 +180,11 @@ func (u User) String() string {
|
|||||||
// Chat is a GroupMe direct message conversation between two users,
|
// Chat is a GroupMe direct message conversation between two users,
|
||||||
// returned in JSON API responses
|
// returned in JSON API responses
|
||||||
type Chat struct {
|
type Chat struct {
|
||||||
CreatedAt Timestamp `json:"created_at"`
|
CreatedAt Timestamp `json:"created_at,omitempty"`
|
||||||
UpdatedAt Timestamp `json:"updated_at"`
|
UpdatedAt Timestamp `json:"updated_at,omitempty"`
|
||||||
LastMessage *Message `json:"last_message"`
|
LastMessage *Message `json:"last_message,omitempty"`
|
||||||
MessagesCount int `json:"messages_count"`
|
MessagesCount int `json:"messages_count,omitempty"`
|
||||||
OtherUser User `json:"other_user"`
|
OtherUser User `json:"other_user,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Chat) String() string {
|
func (c Chat) String() string {
|
||||||
@ -190,12 +192,12 @@ func (c Chat) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Bot struct {
|
type Bot struct {
|
||||||
BotID ID `json:"bot_id"`
|
BotID ID `json:"bot_id,omitempty"`
|
||||||
GroupID ID `json:"group_id"`
|
GroupID ID `json:"group_id,omitempty"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name,omitempty"`
|
||||||
AvatarURL string `json:"avatar_url"`
|
AvatarURL string `json:"avatar_url,omitempty"`
|
||||||
CallbackURL string `json:"callback_url"`
|
CallbackURL string `json:"callback_url,omitempty"`
|
||||||
DMNotification bool `json:"dm_notification"`
|
DMNotification bool `json:"dm_notification,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Bot) String() string {
|
func (b Bot) String() string {
|
||||||
@ -203,9 +205,9 @@ func (b Bot) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Block struct {
|
type Block struct {
|
||||||
UserID ID `json:"user_id"`
|
UserID ID `json:"user_id,omitempty"`
|
||||||
BlockedUserID ID `json:"blocked_user_id"`
|
BlockedUserID ID `json:"blocked_user_id,omitempty"`
|
||||||
CreatedAT Timestamp `json:"created_at"`
|
CreatedAT Timestamp `json:"created_at,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b Block) String() string {
|
func (b Block) String() string {
|
||||||
|
@ -60,7 +60,7 @@ func (c *Client) IndexLeaderboard(groupID ID, p period) ([]*Message, error) {
|
|||||||
var resp struct {
|
var resp struct {
|
||||||
Messages []*Message `json:"messages"`
|
Messages []*Message `json:"messages"`
|
||||||
}
|
}
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ func (c *Client) MyLikesLeaderboard(groupID ID) ([]*Message, error) {
|
|||||||
var resp struct {
|
var resp struct {
|
||||||
Messages []*Message `json:"messages"`
|
Messages []*Message `json:"messages"`
|
||||||
}
|
}
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ func (c *Client) MyHitsLeaderboard(groupID ID) ([]*Message, error) {
|
|||||||
var resp struct {
|
var resp struct {
|
||||||
Messages []*Message `json:"messages"`
|
Messages []*Message `json:"messages"`
|
||||||
}
|
}
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ func (c *Client) CreateLike(conversationID, messageID ID) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.do(httpReq, nil)
|
return c.doWithAuthToken(httpReq, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy
|
// Destroy
|
||||||
@ -59,5 +59,5 @@ func (c *Client) DestroyLike(conversationID, messageID ID) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.do(httpReq, nil)
|
return c.doWithAuthToken(httpReq, nil)
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package groupme
|
package groupme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GroupMe documentation: https://dev.groupme.com/docs/v3#members
|
// GroupMe documentation: https://dev.groupme.com/docs/v3#members
|
||||||
@ -49,24 +49,27 @@ Parameters:
|
|||||||
func (c *Client) AddMembers(groupID ID, members ...*Member) (string, error) {
|
func (c *Client) AddMembers(groupID ID, members ...*Member) (string, error) {
|
||||||
URL := fmt.Sprintf(c.endpointBase+addMembersEndpoint, groupID)
|
URL := fmt.Sprintf(c.endpointBase+addMembersEndpoint, groupID)
|
||||||
|
|
||||||
httpReq, err := http.NewRequest("POST", URL, nil)
|
var data = struct {
|
||||||
|
Members []*Member `json:"members"`
|
||||||
|
}{
|
||||||
|
members,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
bytes, err := json.Marshal(members)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
data.Set("members", string(bytes))
|
|
||||||
httpReq.PostForm = data
|
|
||||||
|
|
||||||
var resp struct {
|
var resp struct {
|
||||||
ResultsID string `json:"result_id"`
|
ResultsID string `json:"results_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -104,7 +107,7 @@ func (c *Client) AddMembersResults(groupID ID, resultID string) ([]*Member, erro
|
|||||||
Members []*Member `json:"members"`
|
Members []*Member `json:"members"`
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -133,7 +136,7 @@ func (c *Client) RemoveMember(groupID, membershipID ID) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.do(httpReq, nil)
|
return c.doWithAuthToken(httpReq, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
///// Update /////
|
///// Update /////
|
||||||
@ -147,25 +150,28 @@ between 1 and 50 characters.
|
|||||||
func (c *Client) UpdateMember(groupID ID, nickname string) (*Member, error) {
|
func (c *Client) UpdateMember(groupID ID, nickname string) (*Member, error) {
|
||||||
URL := fmt.Sprintf(c.endpointBase+updateMemberEndpoint, groupID)
|
URL := fmt.Sprintf(c.endpointBase+updateMemberEndpoint, groupID)
|
||||||
|
|
||||||
httpReq, err := http.NewRequest("POST", URL, nil)
|
type Nickname struct {
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
type membership struct {
|
|
||||||
Nickname string `json:"nickname"`
|
Nickname string `json:"nickname"`
|
||||||
}
|
}
|
||||||
|
var data = struct {
|
||||||
|
Membership Nickname `json:"membership"`
|
||||||
|
}{
|
||||||
|
Nickname{nickname},
|
||||||
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
jsonBytes, err := json.Marshal(&data)
|
||||||
bytes, err := json.Marshal(membership{nickname})
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data.Add("membership", string(bytes))
|
|
||||||
|
|
||||||
var resp Member
|
var resp Member
|
||||||
|
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
package groupme
|
package groupme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
@ -110,7 +111,7 @@ func (c *Client) IndexMessages(groupID ID, req *IndexMessagesQuery) (IndexMessag
|
|||||||
URL.RawQuery = query.Encode()
|
URL.RawQuery = query.Encode()
|
||||||
|
|
||||||
var resp IndexMessagesResponse
|
var resp IndexMessagesResponse
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return IndexMessagesResponse{}, err
|
return IndexMessagesResponse{}, err
|
||||||
}
|
}
|
||||||
@ -150,22 +151,28 @@ Parameters:
|
|||||||
*/
|
*/
|
||||||
func (c *Client) CreateMessage(groupID ID, m *Message) (*Message, error) {
|
func (c *Client) CreateMessage(groupID ID, m *Message) (*Message, error) {
|
||||||
URL := fmt.Sprintf(c.endpointBase+createMessagesEndpoint, groupID)
|
URL := fmt.Sprintf(c.endpointBase+createMessagesEndpoint, groupID)
|
||||||
httpReq, err := http.NewRequest("POST", URL, nil)
|
|
||||||
|
m.SourceGUID = uuid.New().String()
|
||||||
|
var data = struct {
|
||||||
|
Message *Message `json:"message"`
|
||||||
|
}{
|
||||||
|
m,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
m.SourceGUID = uuid.New().String()
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
|
if err != nil {
|
||||||
data := url.Values{}
|
return nil, err
|
||||||
data.Set("message", m.String())
|
}
|
||||||
|
|
||||||
httpReq.PostForm = data
|
|
||||||
|
|
||||||
var resp struct {
|
var resp struct {
|
||||||
*Message `json:"message"`
|
*Message `json:"message"`
|
||||||
}
|
}
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package groupme
|
package groupme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GroupMe documentation: https://dev.groupme.com/docs/v3#sms_mode
|
// GroupMe documentation: https://dev.groupme.com/docs/v3#sms_mode
|
||||||
@ -36,21 +36,27 @@ Parameters:
|
|||||||
delivered to the device.
|
delivered to the device.
|
||||||
*/
|
*/
|
||||||
func (c *Client) CreateSMSMode(duration int, registrationID *ID) error {
|
func (c *Client) CreateSMSMode(duration int, registrationID *ID) error {
|
||||||
httpReq, err := http.NewRequest("POST", c.endpointBase+createSMSModeEndpoint, nil)
|
URL := fmt.Sprintf(c.endpointBase + createSMSModeEndpoint)
|
||||||
|
|
||||||
|
var data = struct {
|
||||||
|
Duration int `json:"duration"`
|
||||||
|
RegistrationID *ID `json:"registration_id,omitempty"`
|
||||||
|
}{
|
||||||
|
duration,
|
||||||
|
registrationID,
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonBytes, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
data.Add("duration", strconv.Itoa(duration))
|
if err != nil {
|
||||||
|
return err
|
||||||
if registrationID != nil {
|
|
||||||
data.Add("registration_id", registrationID.String())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
httpReq.PostForm = data
|
err = c.doWithAuthToken(httpReq, nil)
|
||||||
|
|
||||||
err = c.do(httpReq, nil)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -73,5 +79,5 @@ func (c *Client) DeleteSMSMode() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.do(httpReq, nil)
|
return c.doWithAuthToken(httpReq, nil)
|
||||||
}
|
}
|
||||||
|
30
users_api.go
30
users_api.go
@ -1,9 +1,10 @@
|
|||||||
package groupme
|
package groupme
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GroupMe documentation: https://dev.groupme.com/docs/v3#users
|
// GroupMe documentation: https://dev.groupme.com/docs/v3#users
|
||||||
@ -39,7 +40,7 @@ func (c *Client) MyUser() (*User, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resp User
|
var resp User
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -70,33 +71,18 @@ Parameters: See UserSettings
|
|||||||
func (c *Client) UpdateMyUser(us UserSettings) (*User, error) {
|
func (c *Client) UpdateMyUser(us UserSettings) (*User, error) {
|
||||||
URL := fmt.Sprintf(c.endpointBase + updateMyUserEndpoint)
|
URL := fmt.Sprintf(c.endpointBase + updateMyUserEndpoint)
|
||||||
|
|
||||||
httpReq, err := http.NewRequest("POST", URL, nil)
|
jsonBytes, err := json.Marshal(&us)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data := url.Values{}
|
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
|
||||||
|
if err != nil {
|
||||||
if us.AvatarURL != "" {
|
return nil, err
|
||||||
data.Add("avatar_url", us.AvatarURL)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if us.Name != "" {
|
|
||||||
data.Add("name", us.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if us.Email != "" {
|
|
||||||
data.Add("email", us.Email)
|
|
||||||
}
|
|
||||||
|
|
||||||
if us.ZipCode != "" {
|
|
||||||
data.Add("zip_code", us.ZipCode)
|
|
||||||
}
|
|
||||||
|
|
||||||
httpReq.PostForm = data
|
|
||||||
|
|
||||||
var resp User
|
var resp User
|
||||||
err = c.do(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user