-
Notifications
You must be signed in to change notification settings - Fork 76
/
authorized_apps.go
65 lines (50 loc) · 1.52 KB
/
authorized_apps.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
package gochimp3
import "fmt"
const (
authorized_apps_path = "/authorized-apps"
single_authorized_app_path = authorized_apps_path + "/%s"
)
type ListOfAuthorizedApps struct {
baseList `json:""`
Apps []AuthorizedApp `json:""`
}
type AuthorizedAppRequest struct {
ClientID string `json:"client_id"`
ClientSecret string `json:"client_secret"`
}
type AuthorizedApp struct {
ID int `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Users []string `json:"users "`
withLinks
}
type AuthorizedAppCreateResponse struct {
AccessToken string `json:"access_token"`
ViewerToken string `json:"viewer_token"`
}
func (api *API) GetAuthorizedApps(params *ExtendedQueryParams) (*ListOfAuthorizedApps, error) {
response := new(ListOfAuthorizedApps)
err := api.Request("GET", authorized_apps_path, params, nil, response)
if err != nil {
return nil, err
}
return response, nil
}
func (api *API) CreateAuthorizedApp(body *AuthorizedAppRequest) (*AuthorizedAppCreateResponse, error) {
response := new(AuthorizedAppCreateResponse)
err := api.Request("GET", authorized_apps_path, nil, body, response)
if err != nil {
return nil, err
}
return response, nil
}
func (api *API) GetAuthroizedApp(id string, params *BasicQueryParams) (*AuthorizedApp, error) {
response := new(AuthorizedApp)
endpoint := fmt.Sprintf(single_authorized_app_path, id)
err := api.Request("GET", endpoint, params, nil, response)
if err != nil {
return nil, err
}
return response, nil
}