From f900b99dace164587f0bbcdef3471b1cdea3e138 Mon Sep 17 00:00:00 2001
From: densestvoid <densestvoid@gmail.com>
Date: Mon, 24 Aug 2020 22:44:28 -0400
Subject: [PATCH] Changed POST API content-type to application/json

Fixed AddMember response parsing
added bot post message example
---
 client.go                         |  4 ++++
 client_test.go                    |  8 ++++++++
 examples/post_bot_message/main.go | 20 ++++++++++++++++++++
 members_api.go                    |  2 +-
 4 files changed, 33 insertions(+), 1 deletion(-)
 create mode 100644 examples/post_bot_message/main.go

diff --git a/client.go b/client.go
index 65ffff8..4cac25d 100644
--- a/client.go
+++ b/client.go
@@ -60,6 +60,10 @@ func (r response) UnmarshalJSON(bs []byte) 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)
 	if err != nil {
 		return err
diff --git a/client_test.go b/client_test.go
index 277559b..2186239 100644
--- a/client_test.go
+++ b/client_test.go
@@ -30,6 +30,14 @@ func (s *ClientSuite) TestClient_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() {
 	req, err := http.NewRequest("", "", nil)
 	s.Require().NoError(err)
diff --git a/examples/post_bot_message/main.go b/examples/post_bot_message/main.go
new file mode 100644
index 0000000..9f13d1d
--- /dev/null
+++ b/examples/post_bot_message/main.go
@@ -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))
+}
diff --git a/members_api.go b/members_api.go
index eabf909..4ec156e 100644
--- a/members_api.go
+++ b/members_api.go
@@ -66,7 +66,7 @@ func (c *Client) AddMembers(groupID ID, members ...*Member) (string, error) {
 	}
 
 	var resp struct {
-		ResultsID string `json:"result_id"`
+		ResultsID string `json:"results_id"`
 	}
 
 	err = c.doWithAuthToken(httpReq, &resp)