-
Notifications
You must be signed in to change notification settings - Fork 4
/
users_api.go
92 lines (71 loc) · 1.8 KB
/
users_api.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
package groupme
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
)
// GroupMe documentation: https://dev.groupme.com/docs/v3#users
/*//////// Endpoints ////////*/
const (
// Used to build other endpoints
usersEndpointRoot = "/users"
// Actual Endpoints
myUserEndpoint = usersEndpointRoot + "/me" // GET
updateMyUserEndpoint = usersEndpointRoot + "/update" // POST
)
/*//////// API Requests ////////*/
// Me
/*
MyUser -
Loads a specific group.
Parameters:
groupID - required, string
*/
func (c *Client) MyUser(ctx context.Context) (*User, error) {
URL := fmt.Sprintf(c.apiEndpointBase + myUserEndpoint)
httpReq, err := http.NewRequest("GET", URL, nil)
if err != nil {
return nil, err
}
var resp User
err = c.doWithAuthToken(ctx, httpReq, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}
// UserSettings are the settings for a GroupMe user
type UserSettings struct {
// URL to valid JPG/PNG/GIF image. URL will be converted into
// an image service link (https://i.groupme.com/....)
AvatarURL string `json:"avatar_url"`
// Name must be of the form FirstName LastName
Name string `json:"name"`
// Email address. Must be in [email protected] form
Email string `json:"email"`
ZipCode string `json:"zip_code"`
}
/*
UpdateMyUser -
# Update attributes about your own account
Parameters: See UserSettings
*/
func (c *Client) UpdateMyUser(ctx context.Context, us UserSettings) (*User, error) {
URL := fmt.Sprintf(c.apiEndpointBase + updateMyUserEndpoint)
jsonBytes, err := json.Marshal(&us)
if err != nil {
return nil, err
}
httpReq, err := http.NewRequest("POST", URL, bytes.NewBuffer(jsonBytes))
if err != nil {
return nil, err
}
var resp User
err = c.doWithAuthToken(ctx, httpReq, &resp)
if err != nil {
return nil, err
}
return &resp, nil
}