.. | ||
.gitignore | ||
faye.go | ||
gitter.go | ||
LICENSE | ||
model.go | ||
README.md | ||
stream.go | ||
test_utils.go |
gitter
Gitter API in Go https://developer.gitter.im
Install
go get github.com/sromku/go-gitter
Initialize
:= gitter.New("YOUR_ACCESS_TOKEN") api
Users
Get current user
, err := api.GetUser() user
Rooms
Get all rooms
Go rooms, err := api.GetRooms()
Get room by id
Go room, err := api.GetRoom("roomID")
Get rooms of some user
Go rooms, err := api.GetRooms("userID")
Join room
Go room, err := api.JoinRoom("roomID", "userID")
Leave room
Go room, err := api.LeaveRoom("roomID", "userID")
Get room id
Go id, err := api.GetRoomId("room/uri")
Search gitter rooms
Go rooms, err := api.SearchRooms("search/string")
##### MessagesGet messages of room
Go messages, err := api.GetMessages("roomID", nil)
Get one message
Go message, err := api.GetMessage("roomID", "messageID")
Send message
Go err := api.SendMessage("roomID", "free chat text")
Stream
Create stream to the room and start listening to incoming messages
:= api.Stream(room.Id)
stream go api.Listen(stream)
for {
:= <-stream.Event
event switch ev := event.Data.(type) {
case *gitter.MessageReceived:
.Println(ev.Message.From.Username + ": " + ev.Message.Text)
fmtcase *gitter.GitterConnectionClosed:
// connection was closed
}
}
Close stream connection
.Close() stream
Faye (Experimental)
:= api.Faye(room.ID)
faye go faye.Listen()
for {
:= <-faye.Event
event switch ev := event.Data.(type) {
case *gitter.MessageReceived:
.Println(ev.Message.From.Username + ": " + ev.Message.Text)
fmtcase *gitter.GitterConnectionClosed: //this one is never called in Faye
// connection was closed
}
}
Debug
You can print the internal errors by enabling debug to true
.SetDebug(true, nil) api
You can also define your own io.Writer
in case you want
to persist the logs somewhere. For example keeping the errors on
file
, err := os.Create("gitter.log")
logFile.SetDebug(true, logFile) api
App Engine
Initialize app engine client and continue as usual
:= appengine.NewContext(r)
c := urlfetch.Client(c)
client
:= gitter.New("YOUR_ACCESS_TOKEN")
api .SetClient(client) api