1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 )
23
24
25
26
27
28 type ApplicationsService struct {
29 client *Client
30 }
31
32
33 type Application struct {
34 ID int `json:"id"`
35 ApplicationID string `json:"application_id"`
36 ApplicationName string `json:"application_name"`
37 Secret string `json:"secret"`
38 CallbackURL string `json:"callback_url"`
39 Confidential bool `json:"confidential"`
40 }
41
42
43
44
45
46 type CreateApplicationOptions struct {
47 Name *string `url:"name,omitempty" json:"name,omitempty"`
48 RedirectURI *string `url:"redirect_uri,omitempty" json:"redirect_uri,omitempty"`
49 Scopes *string `url:"scopes,omitempty" json:"scopes,omitempty"`
50 Confidential *bool `url:"confidential,omitempty" json:"confidential,omitempty"`
51 }
52
53
54
55
56 func (s *ApplicationsService) CreateApplication(opt *CreateApplicationOptions, options ...RequestOptionFunc) (*Application, *Response, error) {
57 req, err := s.client.NewRequest(http.MethodPost, "applications", opt, options)
58 if err != nil {
59 return nil, nil, err
60 }
61
62 a := new(Application)
63 resp, err := s.client.Do(req, a)
64 if err != nil {
65 return nil, resp, err
66 }
67
68 return a, resp, nil
69 }
70
71
72
73 type ListApplicationsOptions ListOptions
74
75
76
77
78 func (s *ApplicationsService) ListApplications(opt *ListApplicationsOptions, options ...RequestOptionFunc) ([]*Application, *Response, error) {
79 req, err := s.client.NewRequest(http.MethodGet, "applications", opt, options)
80 if err != nil {
81 return nil, nil, err
82 }
83
84 var as []*Application
85 resp, err := s.client.Do(req, &as)
86 if err != nil {
87 return nil, resp, err
88 }
89
90 return as, resp, nil
91 }
92
93
94
95
96
97 func (s *ApplicationsService) DeleteApplication(application int, options ...RequestOptionFunc) (*Response, error) {
98 u := fmt.Sprintf("applications/%d", application)
99
100 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
101 if err != nil {
102 return nil, err
103 }
104
105 return s.client.Do(req, nil)
106 }
107
View as plain text