2
0
mirror of https://github.com/42wim/matterbridge synced 2024-11-17 03:26:07 +00:00
matterbridge/vendor/github.com/42wim/go-gitter
2018-08-06 21:47:05 +02:00
..
.gitignore Use mod vendor for vendored directory (backwards compatible) 2018-08-06 21:47:05 +02:00
faye.go Use github.com/42wim/go-gitter for now 2017-08-28 23:07:11 +02:00
gitter.go Use github.com/42wim/go-gitter for now 2017-08-28 23:07:11 +02:00
LICENSE Use github.com/42wim/go-gitter for now 2017-08-28 23:07:11 +02:00
model.go Use github.com/42wim/go-gitter for now 2017-08-28 23:07:11 +02:00
README.md Use mod vendor for vendored directory (backwards compatible) 2018-08-06 21:47:05 +02:00
stream.go Use github.com/42wim/go-gitter for now 2017-08-28 23:07:11 +02:00
test_utils.go Use github.com/42wim/go-gitter for now 2017-08-28 23:07:11 +02:00

gitter

Gitter API in Go https://developer.gitter.im

Install

go get github.com/sromku/go-gitter

Initialize
api := gitter.New("YOUR_ACCESS_TOKEN")
Users
  • Get current user

    user, err := api.GetUser()
    
Rooms
  • Get all rooms

    rooms, err := api.GetRooms()
    
  • Get room by id

    room, err := api.GetRoom("roomID")
    
  • Get rooms of some user

    rooms, err := api.GetRooms("userID")
    
  • Join room

    room, err := api.JoinRoom("roomID", "userID")
    
  • Leave room

    room, err := api.LeaveRoom("roomID", "userID")
    
  • Get room id

    id, err := api.GetRoomId("room/uri")
    
  • Search gitter rooms

    rooms, err := api.SearchRooms("search/string")
    
Messages
  • Get messages of room

    messages, err := api.GetMessages("roomID", nil)
    
  • Get one message

    message, err := api.GetMessage("roomID", "messageID")
    
  • Send message

    err := api.SendMessage("roomID", "free chat text")
    
Stream

Create stream to the room and start listening to incoming messages

stream := api.Stream(room.Id)
go api.Listen(stream)

for {
    event := <-stream.Event
    switch ev := event.Data.(type) {
    case *gitter.MessageReceived:
        fmt.Println(ev.Message.From.Username + ": " + ev.Message.Text)
    case *gitter.GitterConnectionClosed:
        // connection was closed
    }
}

Close stream connection

stream.Close()
Faye (Experimental)
faye := api.Faye(room.ID)
go faye.Listen()

for {
    event := <-faye.Event
    switch ev := event.Data.(type) {
    case *gitter.MessageReceived:
        fmt.Println(ev.Message.From.Username + ": " + ev.Message.Text)
    case *gitter.GitterConnectionClosed: //this one is never called in Faye
        // connection was closed
    }
}
Debug

You can print the internal errors by enabling debug to true

api.SetDebug(true, nil)

You can also define your own io.Writer in case you want to persist the logs somewhere. For example keeping the errors on file

logFile, err := os.Create("gitter.log")
api.SetDebug(true, logFile)
App Engine

Initialize app engine client and continue as usual

c := appengine.NewContext(r)
client := urlfetch.Client(c)

api := gitter.New("YOUR_ACCESS_TOKEN")
api.SetClient(client)

Documentation