diff options
Diffstat (limited to 'vendor')
-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) | 79 | ||||
-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) | 9 | ||||
-rw-r--r-- | vendor/github.com/42wim/go-gitter/test_utils.go (renamed from vendor/github.com/sromku/go-gitter/test_utils.go) | 0 | ||||
-rw-r--r-- | vendor/manifest | 16 |
7 files changed, 75 insertions, 29 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 375e6e35..af082881 100644 --- a/vendor/github.com/sromku/go-gitter/gitter.go +++ b/vendor/github.com/42wim/go-gitter/gitter.go @@ -192,7 +192,7 @@ func (gitter *Gitter) SendMessage(roomID, text string) error { message := Message{Text: text} body, _ := json.Marshal(message) - err := gitter.post(gitter.config.apiBaseURL+"rooms/"+roomID+"/chatMessages", body) + _, err := gitter.post(gitter.config.apiBaseURL+"rooms/"+roomID+"/chatMessages", body) if err != nil { gitter.log(err) return err @@ -202,31 +202,37 @@ func (gitter *Gitter) SendMessage(roomID, text string) error { } // JoinRoom joins a room -func (gitter *Gitter) JoinRoom(uri string) (*Room, error) { +func (gitter *Gitter) JoinRoom(roomID, userID string) (*Room, error) { - message := Room{URI: uri} + message := Room{ID: roomID} body, _ := json.Marshal(message) - err := gitter.post(apiBaseURL+"rooms", body) + response, err := gitter.post(gitter.config.apiBaseURL+"user/"+userID+"/rooms", body) + if err != nil { gitter.log(err) return nil, err } - rooms, err := gitter.GetRooms() + var room Room + err = json.Unmarshal(response, &room) if err != nil { gitter.log(err) return nil, err } - for _, room := range rooms { - if room.URI == uri { - return &room, nil - } + return &room, nil +} + +// LeaveRoom removes a user from the room +func (gitter *Gitter) LeaveRoom(roomID, userID string) error { + + _, err := gitter.delete(gitter.config.apiBaseURL + "rooms/" + roomID + "/users/" + userID) + if err != nil { + gitter.log(err) + return err } - err = APIError{What: fmt.Sprintf("Joined room (%v) not found in list of rooms", uri)} - gitter.log(err) - return nil, err + return nil } // SetDebug traces errors if it's set to true. @@ -319,11 +325,11 @@ func (gitter *Gitter) get(url string) ([]byte, error) { return body, nil } -func (gitter *Gitter) post(url string, body []byte) error { +func (gitter *Gitter) post(url string, body []byte) ([]byte, error) { r, err := http.NewRequest("POST", url, bytes.NewBuffer(body)) if err != nil { gitter.log(err) - return err + return nil, err } r.Header.Set("Content-Type", "application/json") @@ -333,17 +339,56 @@ func (gitter *Gitter) post(url string, body []byte) error { resp, err := gitter.config.client.Do(r) if err != nil { gitter.log(err) - return 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 err + return nil, err } - return nil + 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 { + 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) log(a interface{}) { 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 5f1cd78f..4a5a3c68 100644 --- a/vendor/github.com/sromku/go-gitter/stream.go +++ b/vendor/github.com/42wim/go-gitter/stream.go @@ -57,6 +57,11 @@ Loop: //"The JSON stream returns messages as JSON objects that are delimited by carriage return (\r)" <- Not true crap it's (\n) only reader = bufio.NewReader(resp.Body) line, err := reader.ReadBytes('\n') + if err != nil { + gitter.log("ReadBytes error: " + err.Error()) + stream.connect() + continue + } //Check if the line only consists of whitespace onlyWhitespace := true @@ -77,10 +82,6 @@ Loop: } else if stream.isClosed() { gitter.log("Stream closed") continue - } else if err != nil { - gitter.log("ReadBytes error: " + err.Error()) - stream.connect() - continue } // unmarshal the streamed data 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 diff --git a/vendor/manifest b/vendor/manifest index 705c463d..fc904fad 100644 --- a/vendor/manifest +++ b/vendor/manifest @@ -2,6 +2,14 @@ "version": 0, "dependencies": [ { + "importpath": "github.com/42wim/go-gitter", + "repository": "https://github.com/42wim/go-gitter", + "vcs": "git", + "revision": "ae777f740326ef6b4d910496022649859232ff38", + "branch": "fixloop", + "notests": true + }, + { "importpath": "github.com/42wim/matterbridge-plus/bridge", "repository": "https://github.com/42wim/matterbridge-plus", "vcs": "git", @@ -159,14 +167,6 @@ "notests": true }, { - "importpath": "github.com/sromku/go-gitter", - "repository": "https://github.com/sromku/go-gitter", - "vcs": "git", - "revision": "932bf9af423ac2da1544cb73540b3b08b1bdb181", - "branch": "master", - "notests": true - }, - { "importpath": "github.com/thoj/go-ircevent", "repository": "https://github.com/thoj/go-ircevent", "vcs": "git", |