forked from elimisteve/go.tent
/
sample-client.go
58 lines (48 loc) · 1.43 KB
/
sample-client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Steve Phillips / elimisteve
// 2012.09.26
package main
import (
"fmt"
"github.com/elimisteve/fun"
"github.com/elimisteve/go.tent/tent"
"log"
)
const (
USERNAME = ""
TENT_SERVER = USERNAME + ".tent.is"
CURRENT_AUTH_DETAILS = ``
)
func main() {
if USERNAME == "" || CURRENT_AUTH_DETAILS == "" {
log.Fatalf("Set USERNAME and CURRENT_AUTH_DETAILS in this file")
}
// Construct a client
client, err := tent.NewClientWithAuthStr(TENT_SERVER, CURRENT_AUTH_DETAILS)
//
// Post new status update to TENT_SERVER
//
fun.MaybeFatalAt("tent.PostStatus", err)
status := "This message posted with go.tent's sample client "
status += "https://github.com/elimisteve/go.tent"
responsePost, err := client.PostStatus(status)
fun.MaybeFatalAt("tent.PostStatus", err)
fmt.Printf("Post from %s: \n%+v\n\n", TENT_SERVER, responsePost)
//
// Get entities that the user follows
//
followings, err := client.GetFollowings()
fun.MaybeFatalAt("client.GetFollowings", err)
fmt.Printf("\n\n%d users %s is following:\n\n", len(followings), TENT_SERVER)
// Loop over tent.Following vars
for _, f := range followings[:] {
fmt.Printf("%#v\n\n", f)
}
//
// TODO
//
// // Tent profile discovery
// err := client.Discover("http://tent-user.example.org")
// fun.MaybeFatalAt("client.Discover", err)
// err = client.Following().Create("http://another-tent.example.com")
// fun.MaybeFatalAt("client.Following().Create", err)
}