-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.go
50 lines (41 loc) · 1.45 KB
/
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
package pixela
// A Client manages communication with the Pixela User API.
type Client struct {
UserName string
Token string
}
// NewClient return a new Client instance.
func NewClient(userName, token string) *Client {
return &Client{UserName: userName, Token: token}
}
// CreateUser creates a new Pixela user.
func (c *Client) CreateUser(agreeTermsOfService, notMinor bool, thanksCode string) (*Result, error) {
return c.user().Create(agreeTermsOfService, notMinor, thanksCode)
}
func (c *Client) user() *user {
return &user{UserName: c.UserName, Token: c.Token}
}
// UpdateUser updates the authentication token for the specified user.
func (c *Client) UpdateUser(newToken, thanksCode string) (*Result, error) {
result, err := c.user().Update(newToken, thanksCode)
if err == nil && result.IsSuccess {
c.Token = newToken
}
return result, err
}
// DeleteUser deletes the specified registered user.
func (c *Client) DeleteUser() (*Result, error) {
return c.user().Delete()
}
// Graph returns a new Pixela graph API client.
func (c *Client) Graph(graphID string) *Graph {
return &Graph{UserName: c.UserName, Token: c.Token, GraphID: graphID}
}
// Pixel returns a new Pixela pixel API client.
func (c *Client) Pixel(graphID string) *Pixel {
return &Pixel{UserName: c.UserName, Token: c.Token, GraphID: graphID}
}
// Webhook returns a new Pixela webhook API client.
func (c *Client) Webhook() *Webhook {
return &Webhook{UserName: c.UserName, Token: c.Token}
}