-
Notifications
You must be signed in to change notification settings - Fork 3
/
auth.go
76 lines (64 loc) · 1.98 KB
/
auth.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
package lytics
import (
"time"
)
var (
// Ensure we can write out as a table
_ TableWriter = (*Auth)(nil)
)
const (
authEndpoint = "auth/:id"
authListEndpoint = "auth"
)
// Auth is the authorization token (apikey, user-token, oauth-token, jwt-key) to provide
// Lytics access to a 3rd party resource. These are ENCRYPTED and never available to be
// re-read through the api after creation.
type Auth struct {
Id string `json:"id"`
Aid int `json:"aid"`
Name string `json:"name"`
AccountId string `json:"account_id"`
ProviderId string `json:"provider_id"`
ProviderName string `json:"provider_name"`
UserId string `json:"user_id"`
Created time.Time `json:"created"`
Updated time.Time `json:"updated"`
}
func (m *Auth) Headers() []interface{} {
return []interface{}{
"ID", "account_id", "name", "provider", "provider_id", "user_id", "created", "updated",
}
}
func (m *Auth) Row() []interface{} {
return []interface{}{
m.Id, m.AccountId, m.Name, m.ProviderName, m.ProviderId, m.UserId, m.Created.Format(time.RFC3339), m.Updated.Format(time.RFC3339),
}
}
// GetAuths returns a list of all available auths for an account
// https://learn.lytics.com/documentation/developer/api-docs/auth#auth
func (l *Client) GetAuths() ([]*Auth, error) {
res := ApiResp{}
data := []*Auth{}
// make the request
err := l.Get(authListEndpoint, nil, nil, &res, &data)
if err != nil {
return data, err
}
return data, nil
}
// GetAuth returns a single auth based on id
// https://learn.lytics.com/documentation/developer/api-docs/auth#auth-retrieve-a-single-auth-get
func (l *Client) GetAuth(id string) (Auth, error) {
res := ApiResp{}
data := Auth{}
// make the request
err := l.Get(parseLyticsURL(authEndpoint, map[string]string{"id": id}), nil, nil, &res, &data)
if err != nil {
return data, err
}
return data, nil
}
// Other Available Endpoints
// * POST create auth
// * PUT update auth
// * DELETE remove auth