Skip to content

Commit 35fef37

Browse files
author
Brandyn A. White
committed
Added weariverse and fixed up gist handling
Signed-off-by: Brandyn A. White <[email protected]>
1 parent 4317720 commit 35fef37

File tree

4 files changed

+61
-5
lines changed

4 files changed

+61
-5
lines changed

github.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ func githubConvertFiles(filesRaw map[interface{}]interface{}) map[string]map[str
7272
for k0, v0 := range filesRaw {
7373
fileRaw := v0.(map[interface{}]interface{})
7474
file := map[string]string{}
75-
for k1, v1 := range fileRaw {
76-
file[k1.(string)] = string(v1.([]uint8))
75+
if fileRaw["content"] != nil {
76+
file["content"] = string(fileRaw["content"].([]uint8))
77+
}
78+
if fileRaw["filename"] != nil {
79+
file["filename"] = string(fileRaw["filename"].([]uint8))
7780
}
7881
files[k0.(string)] = file
7982
}
@@ -144,10 +147,10 @@ func githubCheckDescription(gist map[string]interface{}) bool {
144147
func GithubGetGist(userId string, gistId string) (interface{}, error) {
145148
values := url.Values{}
146149
accessToken, err := getUserAttribute(userId, "oauth_token_gh")
147-
if err != nil {
148-
return "error:oauth", err
150+
// NOTE(brandyn): We allow the user to not have an oauth token for getting gists
151+
if err == nil {
152+
values.Set("access_token", accessToken)
149153
}
150-
values.Set("access_token", accessToken)
151154
response, err := http.Get("https://api.github.com/gists/" + gistId + "?" + values.Encode())
152155
if err != nil {
153156
return "error:github", err

store.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ func deleteUserKey(userId string, name string) error {
145145
return err
146146
}
147147

148+
func getUserSortedSet(userId string, name string) ([]string, error) {
149+
c, err := getRedisConnection()
150+
if err != nil {
151+
return nil, err
152+
}
153+
return redis.Strings(c.Do("ZRANGE", userId+":"+name, "0", "-1"))
154+
}
155+
148156
func setUserMap(userId string, name string, key string, data string) error {
149157
c, err := getRedisConnection()
150158
if err != nil {

weariverse.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"github.com/wearscript/wearscript-go/wearscript"
6+
)
7+
8+
9+
func WeariverseGistHandle(cm *wearscript.ConnectionManager, userId string, request []interface{}) {
10+
action := request[1].(string)
11+
channelResult := request[2].(string)
12+
fmt.Println("gist action: " + action + " result: " + channelResult)
13+
var dataJS interface{}
14+
var err error
15+
if action == "list" {
16+
dataJS, err = WeariverseGetGists(userId)
17+
} else {
18+
dataJS = "error:action"
19+
}
20+
if err != nil {
21+
fmt.Println(err)
22+
}
23+
cm.Publish(channelResult, dataJS)
24+
}
25+
26+
func WeariverseGetGists(userId string) (interface{}, error) {
27+
//[]string{"9732959", "9423246"}
28+
gists, err := getUserSortedSet("weariverse", "gists")
29+
if err != nil {
30+
return nil, err
31+
}
32+
out := []interface{}{}
33+
for _, value := range gists {
34+
data, err := GithubGetGist(userId, value)
35+
if err != nil {
36+
fmt.Println("weariverse: couldn't get gist")
37+
continue
38+
}
39+
out = append(out, data)
40+
}
41+
return out, nil
42+
}

websockets.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ func WSHandler(ws *websocket.Conn) {
5454
Managers[userId].Subscribe("gist", func(channel string, dataRaw []byte, data []interface{}) {
5555
GithubGistHandle(Managers[userId], userId, data)
5656
})
57+
Managers[userId].Subscribe("weariverse", func(channel string, dataRaw []byte, data []interface{}) {
58+
WeariverseGistHandle(Managers[userId], userId, data)
59+
})
5760
}
5861
cm := Managers[userId]
5962
conn, err := cm.NewConnection(ws) // con

0 commit comments

Comments
 (0)