diff options
author | Wim <wim@42.be> | 2016-09-04 20:03:07 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2016-09-04 20:04:43 +0200 |
commit | 12389d602eecf4adab0e394da19b2b808cb489b1 (patch) | |
tree | 80d6d8c00ed31fdcd60540d7c65afa6e7d2d83d6 /vendor/github.com/mrexodia/wray/response.go | |
parent | 44144587a0314b7e2c719d279116ac86b657657e (diff) | |
download | matterbridge-msglm-12389d602eecf4adab0e394da19b2b808cb489b1.tar.gz matterbridge-msglm-12389d602eecf4adab0e394da19b2b808cb489b1.tar.bz2 matterbridge-msglm-12389d602eecf4adab0e394da19b2b808cb489b1.zip |
Add Gitter support
Diffstat (limited to 'vendor/github.com/mrexodia/wray/response.go')
-rw-r--r-- | vendor/github.com/mrexodia/wray/response.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/github.com/mrexodia/wray/response.go b/vendor/github.com/mrexodia/wray/response.go new file mode 100644 index 00000000..e9815c3f --- /dev/null +++ b/vendor/github.com/mrexodia/wray/response.go @@ -0,0 +1,61 @@ +package wray + +type Response struct { + id string + channel string + successful bool + clientId string + supportedConnectionTypes []string + messages []Message + error error +} + +type Message struct { + Channel string + Id string + Data map[string]interface{} +} + +func newResponse(data []interface{}) Response { + headerData := data[0].(map[string]interface{}) + messagesData := data[1.:] + messages := parseMessages(messagesData) + var id string + if headerData["id"] != nil { + id = headerData["id"].(string) + } + supportedConnectionTypes := []string{} + if headerData["supportedConnectionTypes"] != nil { + d := headerData["supportedConnectionTypes"].([]interface{}) + for _, sct := range(d) { + supportedConnectionTypes = append(supportedConnectionTypes, sct.(string)) + } + } + var clientId string + if headerData["clientId"] != nil { + clientId = headerData["clientId"].(string) + } + return Response{id: id, + clientId: clientId, + channel: headerData["channel"].(string), + successful: headerData["successful"].(bool), + messages: messages, + supportedConnectionTypes: supportedConnectionTypes} +} + +func parseMessages(data []interface{}) []Message { + messages := []Message{} + for _, messageData := range(data) { + m := messageData.(map[string]interface{}) + var id string + if m["id"] != nil { + id = m["id"].(string) + } + message := Message{Channel: m["channel"].(string), + Id: id, + Data: m["data"].(map[string]interface{})} + messages = append(messages, message) + } + return messages +} + |