Changed POST API content-type to application/json
Fixed AddMember response parsing added bot post message example
This commit is contained in:
parent
d8cdcf4ef2
commit
f900b99dac
@ -60,6 +60,10 @@ 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 {
|
||||||
|
if req.Method == "POST" {
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
}
|
||||||
|
|
||||||
getResp, err := c.httpClient.Do(req)
|
getResp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -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)
|
||||||
|
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))
|
||||||
|
}
|
@ -66,7 +66,7 @@ func (c *Client) AddMembers(groupID ID, members ...*Member) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var resp struct {
|
var resp struct {
|
||||||
ResultsID string `json:"result_id"`
|
ResultsID string `json:"results_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.doWithAuthToken(httpReq, &resp)
|
err = c.doWithAuthToken(httpReq, &resp)
|
||||||
|
Loading…
Reference in New Issue
Block a user