From e59d338d4e43ed8cad3227186d0c341a44abedf6 Mon Sep 17 00:00:00 2001 From: Wim Date: Mon, 28 Aug 2017 22:59:52 +0200 Subject: [PATCH] Use github.com/42wim/go-gitter for now --- .../{sromku => 42wim}/go-gitter/LICENSE | 0 .../{sromku => 42wim}/go-gitter/faye.go | 0 .../{sromku => 42wim}/go-gitter/gitter.go | 69 +++++++++++++++++-- .../{sromku => 42wim}/go-gitter/model.go | 0 .../{sromku => 42wim}/go-gitter/stream.go | 0 .../{sromku => 42wim}/go-gitter/test_utils.go | 0 vendor/manifest | 16 ++--- 7 files changed, 72 insertions(+), 13 deletions(-) rename vendor/github.com/{sromku => 42wim}/go-gitter/LICENSE (100%) rename vendor/github.com/{sromku => 42wim}/go-gitter/faye.go (100%) rename vendor/github.com/{sromku => 42wim}/go-gitter/gitter.go (86%) rename vendor/github.com/{sromku => 42wim}/go-gitter/model.go (100%) rename vendor/github.com/{sromku => 42wim}/go-gitter/stream.go (100%) rename vendor/github.com/{sromku => 42wim}/go-gitter/test_utils.go (100%) diff --git a/vendor/github.com/sromku/go-gitter/LICENSE b/vendor/github.com/42wim/go-gitter/LICENSE similarity index 100% rename from vendor/github.com/sromku/go-gitter/LICENSE rename to vendor/github.com/42wim/go-gitter/LICENSE diff --git a/vendor/github.com/sromku/go-gitter/faye.go b/vendor/github.com/42wim/go-gitter/faye.go similarity index 100% rename from vendor/github.com/sromku/go-gitter/faye.go rename to vendor/github.com/42wim/go-gitter/faye.go diff --git a/vendor/github.com/sromku/go-gitter/gitter.go b/vendor/github.com/42wim/go-gitter/gitter.go similarity index 86% rename from vendor/github.com/sromku/go-gitter/gitter.go rename to vendor/github.com/42wim/go-gitter/gitter.go index 0eff42a8..77b011bf 100644 --- a/vendor/github.com/sromku/go-gitter/gitter.go +++ b/vendor/github.com/42wim/go-gitter/gitter.go @@ -205,17 +205,43 @@ func (gitter *Gitter) GetMessage(roomID, messageID string) (*Message, error) { } // SendMessage sends a message to a room -func (gitter *Gitter) SendMessage(roomID, text string) error { +func (gitter *Gitter) SendMessage(roomID, text string) (*Message, error) { message := Message{Text: text} body, _ := json.Marshal(message) - _, err := gitter.post(gitter.config.apiBaseURL+"rooms/"+roomID+"/chatMessages", body) + response, err := gitter.post(gitter.config.apiBaseURL+"rooms/"+roomID+"/chatMessages", body) if err != nil { gitter.log(err) - return err + return nil, err } - return nil + err = json.Unmarshal(response, &message) + if err != nil { + gitter.log(err) + return nil, err + } + + return &message, nil +} + +// UpdateMessage updates a message in a room +func (gitter *Gitter) UpdateMessage(roomID, msgID, text string) (*Message, error) { + + message := Message{Text: text} + body, _ := json.Marshal(message) + response, err := gitter.put(gitter.config.apiBaseURL+"rooms/"+roomID+"/chatMessages/"+msgID, body) + if err != nil { + gitter.log(err) + return nil, err + } + + err = json.Unmarshal(response, &message) + if err != nil { + gitter.log(err) + return nil, err + } + + return &message, nil } // JoinRoom joins a room @@ -265,7 +291,7 @@ func (gitter *Gitter) SearchRooms(room string) ([]Room, error) { Results []Room `json:"results"` } - response, err := gitter.get(gitter.config.apiBaseURL + "rooms?q=" + room ) + response, err := gitter.get(gitter.config.apiBaseURL + "rooms?q=" + room) if err != nil { gitter.log(err) @@ -414,6 +440,39 @@ func (gitter *Gitter) post(url string, body []byte) ([]byte, error) { return result, nil } +func (gitter *Gitter) put(url string, body []byte) ([]byte, error) { + r, err := http.NewRequest("PUT", url, bytes.NewBuffer(body)) + if err != nil { + gitter.log(err) + return nil, err + } + + r.Header.Set("Content-Type", "application/json") + r.Header.Set("Accept", "application/json") + r.Header.Set("Authorization", "Bearer "+gitter.config.token) + + resp, err := gitter.config.client.Do(r) + if err != nil { + gitter.log(err) + return nil, err + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + err = APIError{What: fmt.Sprintf("Status code: %v", resp.StatusCode)} + gitter.log(err) + return nil, err + } + + result, err := ioutil.ReadAll(resp.Body) + if err != nil { + gitter.log(err) + return nil, err + } + + return result, nil +} + func (gitter *Gitter) delete(url string) ([]byte, error) { r, err := http.NewRequest("delete", url, nil) if err != nil { diff --git a/vendor/github.com/sromku/go-gitter/model.go b/vendor/github.com/42wim/go-gitter/model.go similarity index 100% rename from vendor/github.com/sromku/go-gitter/model.go rename to vendor/github.com/42wim/go-gitter/model.go diff --git a/vendor/github.com/sromku/go-gitter/stream.go b/vendor/github.com/42wim/go-gitter/stream.go similarity index 100% rename from vendor/github.com/sromku/go-gitter/stream.go rename to vendor/github.com/42wim/go-gitter/stream.go diff --git a/vendor/github.com/sromku/go-gitter/test_utils.go b/vendor/github.com/42wim/go-gitter/test_utils.go similarity index 100% rename from vendor/github.com/sromku/go-gitter/test_utils.go rename to vendor/github.com/42wim/go-gitter/test_utils.go diff --git a/vendor/manifest b/vendor/manifest index 7636c486..2bf08c2b 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -1,6 +1,14 @@ { "version": 0, "dependencies": [ + { + "importpath": "github.com/42wim/go-gitter", + "repository": "https://github.com/42wim/go-gitter", + "vcs": "git", + "revision": "017310c2d5575ae5b3c9d2caef2989d5912bb4b1", + "branch": "sendmessage", + "notests": true + }, { "importpath": "github.com/42wim/go-ircevent", "repository": "https://github.com/42wim/go-ircevent", @@ -473,14 +481,6 @@ "branch": "master", "notests": true }, - { - "importpath": "github.com/sromku/go-gitter", - "repository": "https://github.com/sromku/go-gitter", - "vcs": "git", - "revision": "16aadfbb65c6641501ea8eebb6bcf23b9011912b", - "branch": "master", - "notests": true - }, { "importpath": "github.com/stretchr/testify/assert", "repository": "https://github.com/stretchr/testify",