forked from pusher/pusher-http-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response_parsing.go
115 lines (89 loc) · 2.6 KB
/
response_parsing.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package pusher
import (
"encoding/json"
)
// Channel represents the information about a channel from the Pusher API.
type Channel struct {
Name string
Occupied bool `json:"occupied,omitempty"`
UserCount int `json:"user_count,omitempty"`
SubscriptionCount int `json:"subscription_count,omitempty"`
}
// ChannelsList represents a list of channels received by the Pusher API.
type ChannelsList struct {
Channels map[string]ChannelListItem `json:"channels"`
}
// ChannelListItem represents an item within ChannelsList
type ChannelListItem struct {
UserCount int `json:"user_count"`
}
type TriggerChannelsList struct {
Channels map[string]TriggerChannelListItem `json:"channels"`
}
type TriggerChannelListItem struct {
UserCount *int `json:"user_count,omitempty"`
SubscriptionCount *int `json:"subscription_count,omitempty"`
}
type TriggerBatchChannelsList struct {
Batch []TriggerBatchChannelListItem `json:"batch"`
}
type TriggerBatchChannelListItem struct {
UserCount *int `json:"user_count,omitempty"`
SubscriptionCount *int `json:"subscription_count,omitempty"`
}
// Users represents a list of users in a presence-channel
type Users struct {
List []User `json:"users"`
}
// User represents a user and contains their ID.
type User struct {
ID string `json:"id"`
}
/*
MemberData represents what to assign to a channel member, consisting of a
`UserID` and any custom `UserInfo`.
*/
type MemberData struct {
UserID string `json:"user_id"`
UserInfo map[string]string `json:"user_info,omitempty"`
}
func unmarshalledTriggerChannelsList(response []byte) (*TriggerChannelsList, error) {
channels := &TriggerChannelsList{}
err := json.Unmarshal(response, channels)
if err != nil {
return nil, err
}
return channels, nil
}
func unmarshalledTriggerBatchChannelsList(response []byte) (*TriggerBatchChannelsList, error) {
channels := &TriggerBatchChannelsList{}
err := json.Unmarshal(response, channels)
if err != nil {
return nil, err
}
return channels, nil
}
func unmarshalledChannelsList(response []byte) (*ChannelsList, error) {
channels := &ChannelsList{}
err := json.Unmarshal(response, channels)
if err != nil {
return nil, err
}
return channels, nil
}
func unmarshalledChannel(response []byte, name string) (*Channel, error) {
channel := &Channel{Name: name}
err := json.Unmarshal(response, channel)
if err != nil {
return nil, err
}
return channel, nil
}
func unmarshalledChannelUsers(response []byte) (*Users, error) {
users := &Users{}
err := json.Unmarshal(response, users)
if err != nil {
return nil, err
}
return users, nil
}