forked from tw1nk/gochimp3
/
authorized_apps.go
69 lines (54 loc) 路 1.63 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
66
67
68
69
package gochimp3
import (
"context"
"fmt"
"net/http"
)
const (
authorizedAppsPath = "/authorized-apps"
singleAuthorizedAppPath = authorizedAppsPath + "/%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(ctx context.Context, params *ExtendedQueryParams) (*ListOfAuthorizedApps, error) {
response := new(ListOfAuthorizedApps)
err := api.Request(ctx, http.MethodGet, authorizedAppsPath, params, nil, response)
if err != nil {
return nil, err
}
return response, nil
}
func (api *API) CreateAuthorizedApp(ctx context.Context, body *AuthorizedAppRequest) (*AuthorizedAppCreateResponse, error) {
response := new(AuthorizedAppCreateResponse)
err := api.Request(ctx, http.MethodGet, authorizedAppsPath, nil, body, response)
if err != nil {
return nil, err
}
return response, nil
}
func (api *API) GetAuthorizedApp(ctx context.Context, id string, params *BasicQueryParams) (*AuthorizedApp, error) {
response := new(AuthorizedApp)
endpoint := fmt.Sprintf(singleAuthorizedAppPath, id)
err := api.Request(ctx, http.MethodGet, endpoint, params, nil, response)
if err != nil {
return nil, err
}
return response, nil
}