Repository navigation
Expand file tree
/
Copy pathblocks_api.go
More file actions
115 lines (94 loc) · 2.79 KB
/
Copy pathblocks_api.go
File metadata and controls
115 lines (94 loc) · 2.79 KB
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 groupme defines a client capable of executing API commands for the GroupMe chat service
package groupme
import (
"context"
"net/http"
)
// GroupMe documentation: https://dev.groupme.com/docs/v3#blocks
/*//////// Endpoints ////////*/
const (
// Used to build other endpoints
blocksEndpointRoot = "/blocks"
// Actual Endpoints
indexBlocksEndpoint = blocksEndpointRoot // GET
blockBetweenEndpoint = blocksEndpointRoot + "/between" // GET
createBlockEndpoint = blocksEndpointRoot // POST
unblockEndpoint = blocksEndpointRoot // DELETE
)
/*//////// API Requests ////////*/
// IndexBlock - A list of contacts you have blocked. These people cannot DM you
func (c *Client) IndexBlock(ctx context.Context, userID string) ([]*Block, error) {
httpReq, err := http.NewRequest("GET", c.endpointBase+indexBlocksEndpoint, nil)
if err != nil {
return nil, err
}
URL := httpReq.URL
query := URL.Query()
query.Set("user", userID)
URL.RawQuery = query.Encode()
var resp struct {
Blocks []*Block `json:"blocks"`
}
err = c.doWithAuthToken(ctx, httpReq, &resp)
if err != nil {
return nil, err
}
return resp.Blocks, nil
}
// BlockBetween - Asks if a block exists between you and another user id
func (c *Client) BlockBetween(ctx context.Context, userID, otherUserID string) (bool, error) {
httpReq, err := http.NewRequest("GET", c.endpointBase+blockBetweenEndpoint, nil)
if err != nil {
return false, err
}
URL := httpReq.URL
query := URL.Query()
query.Set("user", userID)
query.Set("otherUser", otherUserID)
URL.RawQuery = query.Encode()
var resp struct {
Between bool `json:"between"`
}
err = c.doWithAuthToken(ctx, httpReq, &resp)
if err != nil {
return false, err
}
return resp.Between, nil
}
// CreateBlock - Creates a block between you and the contact
func (c *Client) CreateBlock(ctx context.Context, userID, otherUserID string) (*Block, error) {
httpReq, err := http.NewRequest("POST", c.endpointBase+createBlockEndpoint, nil)
if err != nil {
return nil, err
}
URL := httpReq.URL
query := URL.Query()
query.Set("user", userID)
query.Set("otherUser", otherUserID)
URL.RawQuery = query.Encode()
var resp struct {
Block *Block `json:"block"`
}
err = c.doWithAuthToken(ctx, httpReq, &resp)
if err != nil {
return nil, err
}
return resp.Block, nil
}
// Unblock - Removes block between you and other user
func (c *Client) Unblock(ctx context.Context, userID, otherUserID string) error {
httpReq, err := http.NewRequest("DELETE", c.endpointBase+unblockEndpoint, nil)
if err != nil {
return err
}
URL := httpReq.URL
query := URL.Query()
query.Set("user", userID)
query.Set("otherUser", otherUserID)
URL.RawQuery = query.Encode()
err = c.doWithAuthToken(ctx, httpReq, nil)
if err != nil {
return err
}
return nil
}