5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-12-24 03:25:40 +00:00

Use github.com/42wim/go-gitter for now

This commit is contained in:
Wim 2017-08-28 22:59:52 +02:00
parent 7a86044f7a
commit e59d338d4e
7 changed files with 72 additions and 13 deletions

View File

@ -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 {

16
vendor/manifest vendored
View File

@ -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",