diff options
Diffstat (limited to 'vendor/github.com')
-rw-r--r-- | vendor/github.com/42wim/go-gitter/LICENSE (renamed from vendor/github.com/sromku/go-gitter/LICENSE) | 0 | ||||
-rw-r--r-- | vendor/github.com/42wim/go-gitter/faye.go (renamed from vendor/github.com/sromku/go-gitter/faye.go) | 0 | ||||
-rw-r--r-- | vendor/github.com/42wim/go-gitter/gitter.go (renamed from vendor/github.com/sromku/go-gitter/gitter.go) | 69 | ||||
-rw-r--r-- | vendor/github.com/42wim/go-gitter/model.go (renamed from vendor/github.com/sromku/go-gitter/model.go) | 0 | ||||
-rw-r--r-- | vendor/github.com/42wim/go-gitter/stream.go (renamed from vendor/github.com/sromku/go-gitter/stream.go) | 0 | ||||
-rw-r--r-- | vendor/github.com/42wim/go-gitter/test_utils.go (renamed from vendor/github.com/sromku/go-gitter/test_utils.go) | 0 |
6 files changed, 64 insertions, 5 deletions
diff --git a/vendor/github.com/sromku/go-gitter/LICENSE b/vendor/github.com/42wim/go-gitter/LICENSE index 8dada3ed..8dada3ed 100644 --- a/vendor/github.com/sromku/go-gitter/LICENSE +++ b/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 index dcd3e210..dcd3e210 100644 --- a/vendor/github.com/sromku/go-gitter/faye.go +++ b/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 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 index 7a3d0729..7a3d0729 100644 --- a/vendor/github.com/sromku/go-gitter/model.go +++ b/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 index 1c26ebeb..1c26ebeb 100644 --- a/vendor/github.com/sromku/go-gitter/stream.go +++ b/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 index 6703da2e..6703da2e 100644 --- a/vendor/github.com/sromku/go-gitter/test_utils.go +++ b/vendor/github.com/42wim/go-gitter/test_utils.go |