-
Notifications
You must be signed in to change notification settings - Fork 29
/
AdhocChallengeInvitation.go
63 lines (50 loc) · 1.71 KB
/
AdhocChallengeInvitation.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
package connect
import (
"fmt"
)
// AdhocChallengeInvitation is a ad-hoc challenge invitation.
type AdhocChallengeInvitation struct {
AdhocChallenge `json:",inline"`
UUID string `json:"adHocChallengeUuid"`
InviteID int `json:"adHocChallengeInviteId"`
InvitorName string `json:"invitorName"`
InvitorID int `json:"invitorId"`
InvitorDisplayName string `json:"invitorDisplayName"`
InviteeID int `json:"inviteeId"`
UserImageURL string `json:"userImageUrl"`
}
// AdhocChallengeInvites list Ad-Hoc challenges awaiting response.
func (c *Client) AdhocChallengeInvites() ([]AdhocChallengeInvitation, error) {
URL := "https://connect.garmin.com/modern/proxy/adhocchallenge-service/adHocChallenge/invite"
if !c.authenticated() {
return nil, ErrNotAuthenticated
}
challenges := make([]AdhocChallengeInvitation, 0, 10)
err := c.getJSON(URL, &challenges)
if err != nil {
return nil, err
}
// Make sure the embedded UUID matches in case the user uses the embedded
// AdhocChallenge for something.
for i := range challenges {
challenges[i].AdhocChallenge.UUID = challenges[i].UUID
}
return challenges, nil
}
// AdhocChallengeInvitationRespond will respond to a ad-hoc challenge. If
// accept is false, the challenge will be declined.
func (c *Client) AdhocChallengeInvitationRespond(inviteID int, accept bool) error {
scope := "decline"
if accept {
scope = "accept"
}
URL := fmt.Sprintf("https://connect.garmin.com/modern/proxy/adhocchallenge-service/adHocChallenge/invite/%d/%s", inviteID, scope)
payload := struct {
InviteID int `json:"inviteId"`
Scope string `json:"scope"`
}{
inviteID,
scope,
}
return c.write("PUT", URL, payload, 0)
}