-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclient_test.go
76 lines (63 loc) · 1.66 KB
/
client_test.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package vkapi
import (
"log"
"net/http"
"net/url"
)
func ExampleNewClientFromToken() {
client, _ := NewClientFromToken("<access_token>")
if err := client.InitLongPoll(0, 2); err != nil {
log.Panic(err)
}
client.Log(true)
updates, _, err := client.GetLPUpdatesChan(100, LPConfig{25, LPModeAttachments})
if err != nil {
log.Panic(err)
}
for update := range updates {
if update.Message == nil {
continue
}
log.Printf("%s", update.Message.String())
if update.IsNewMessage() && update.Message.Text == "/start" {
client.SendMessage(NewMessage(NewDstFromUserID(update.Message.FromID), "Hello!"))
}
}
}
func ExampleNewClientFromAPIClient() {
apiClient := NewApiClient()
apiClient.SetHTTPClient(http.DefaultClient)
apiClient.SetAccessToken("<access token>")
client, _ := NewClientFromAPIClient(apiClient)
if err := client.InitMyProfile(); err != nil {
log.Panic(err.Error())
}
log.Printf("My name is %s", client.VKUser.Me.FirstName)
}
func ExampleNewClientFromApplication() {
client, err := NewClientFromApplication(Application{
Username: "<username>",
Password: "<password>",
GrantType: "password",
ClientID: "<client_id>",
ClientSecret: "<client_secret>",
})
if err != nil {
log.Panic(err)
}
if err := client.InitMyProfile(); err != nil {
log.Panic(err.Error())
}
log.Printf("My name is %s", client.VKUser.Me.FirstName)
}
func ExampleClient_Do() {
client, _ := NewClientFromToken("<access token>")
values := url.Values{}
values.Set("user_id", "1")
values.Set("count", "10")
res, err := client.Do(NewRequest("groups.get", "", values))
if err != nil {
panic(err.Error())
}
println(res.Response.String())
}