3
3
package zones
4
4
5
5
import (
6
+ "context"
7
+ "errors"
8
+ "fmt"
9
+ "net/http"
10
+
11
+ "github.com/cloudflare/cloudflare-go/v4/internal/apijson"
12
+ "github.com/cloudflare/cloudflare-go/v4/internal/param"
13
+ "github.com/cloudflare/cloudflare-go/v4/internal/requestconfig"
6
14
"github.com/cloudflare/cloudflare-go/v4/option"
15
+ "github.com/cloudflare/cloudflare-go/v4/shared"
7
16
)
8
17
9
18
// SubscriptionService contains methods and other services that help with
@@ -24,3 +33,208 @@ func NewSubscriptionService(opts ...option.RequestOption) (r *SubscriptionServic
24
33
r .Options = opts
25
34
return
26
35
}
36
+
37
+ // Create a zone subscription, either plan or add-ons.
38
+ func (r * SubscriptionService ) New (ctx context.Context , params SubscriptionNewParams , opts ... option.RequestOption ) (res * shared.Subscription , err error ) {
39
+ var env SubscriptionNewResponseEnvelope
40
+ opts = append (r .Options [:], opts ... )
41
+ if params .ZoneID .Value == "" {
42
+ err = errors .New ("missing required zone_id parameter" )
43
+ return
44
+ }
45
+ path := fmt .Sprintf ("zones/%s/subscription" , params .ZoneID )
46
+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodPost , path , params , & env , opts ... )
47
+ if err != nil {
48
+ return
49
+ }
50
+ res = & env .Result
51
+ return
52
+ }
53
+
54
+ // Updates zone subscriptions, either plan or add-ons.
55
+ func (r * SubscriptionService ) Update (ctx context.Context , params SubscriptionUpdateParams , opts ... option.RequestOption ) (res * shared.Subscription , err error ) {
56
+ var env SubscriptionUpdateResponseEnvelope
57
+ opts = append (r .Options [:], opts ... )
58
+ if params .ZoneID .Value == "" {
59
+ err = errors .New ("missing required zone_id parameter" )
60
+ return
61
+ }
62
+ path := fmt .Sprintf ("zones/%s/subscription" , params .ZoneID )
63
+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodPut , path , params , & env , opts ... )
64
+ if err != nil {
65
+ return
66
+ }
67
+ res = & env .Result
68
+ return
69
+ }
70
+
71
+ // Lists zone subscription details.
72
+ func (r * SubscriptionService ) Get (ctx context.Context , query SubscriptionGetParams , opts ... option.RequestOption ) (res * shared.Subscription , err error ) {
73
+ var env SubscriptionGetResponseEnvelope
74
+ opts = append (r .Options [:], opts ... )
75
+ if query .ZoneID .Value == "" {
76
+ err = errors .New ("missing required zone_id parameter" )
77
+ return
78
+ }
79
+ path := fmt .Sprintf ("zones/%s/subscription" , query .ZoneID )
80
+ err = requestconfig .ExecuteNewRequest (ctx , http .MethodGet , path , nil , & env , opts ... )
81
+ if err != nil {
82
+ return
83
+ }
84
+ res = & env .Result
85
+ return
86
+ }
87
+
88
+ type SubscriptionNewParams struct {
89
+ // Subscription identifier tag.
90
+ ZoneID param.Field [string ] `path:"zone_id,required"`
91
+ Subscription shared.SubscriptionParam `json:"subscription,required"`
92
+ }
93
+
94
+ func (r SubscriptionNewParams ) MarshalJSON () (data []byte , err error ) {
95
+ return apijson .MarshalRoot (r .Subscription )
96
+ }
97
+
98
+ type SubscriptionNewResponseEnvelope struct {
99
+ Errors []shared.ResponseInfo `json:"errors,required"`
100
+ Messages []shared.ResponseInfo `json:"messages,required"`
101
+ Result shared.Subscription `json:"result,required"`
102
+ // Whether the API call was successful
103
+ Success SubscriptionNewResponseEnvelopeSuccess `json:"success,required"`
104
+ JSON subscriptionNewResponseEnvelopeJSON `json:"-"`
105
+ }
106
+
107
+ // subscriptionNewResponseEnvelopeJSON contains the JSON metadata for the struct
108
+ // [SubscriptionNewResponseEnvelope]
109
+ type subscriptionNewResponseEnvelopeJSON struct {
110
+ Errors apijson.Field
111
+ Messages apijson.Field
112
+ Result apijson.Field
113
+ Success apijson.Field
114
+ raw string
115
+ ExtraFields map [string ]apijson.Field
116
+ }
117
+
118
+ func (r * SubscriptionNewResponseEnvelope ) UnmarshalJSON (data []byte ) (err error ) {
119
+ return apijson .UnmarshalRoot (data , r )
120
+ }
121
+
122
+ func (r subscriptionNewResponseEnvelopeJSON ) RawJSON () string {
123
+ return r .raw
124
+ }
125
+
126
+ // Whether the API call was successful
127
+ type SubscriptionNewResponseEnvelopeSuccess bool
128
+
129
+ const (
130
+ SubscriptionNewResponseEnvelopeSuccessTrue SubscriptionNewResponseEnvelopeSuccess = true
131
+ )
132
+
133
+ func (r SubscriptionNewResponseEnvelopeSuccess ) IsKnown () bool {
134
+ switch r {
135
+ case SubscriptionNewResponseEnvelopeSuccessTrue :
136
+ return true
137
+ }
138
+ return false
139
+ }
140
+
141
+ type SubscriptionUpdateParams struct {
142
+ // Subscription identifier tag.
143
+ ZoneID param.Field [string ] `path:"zone_id,required"`
144
+ Subscription shared.SubscriptionParam `json:"subscription,required"`
145
+ }
146
+
147
+ func (r SubscriptionUpdateParams ) MarshalJSON () (data []byte , err error ) {
148
+ return apijson .MarshalRoot (r .Subscription )
149
+ }
150
+
151
+ type SubscriptionUpdateResponseEnvelope struct {
152
+ Errors []shared.ResponseInfo `json:"errors,required"`
153
+ Messages []shared.ResponseInfo `json:"messages,required"`
154
+ Result shared.Subscription `json:"result,required"`
155
+ // Whether the API call was successful
156
+ Success SubscriptionUpdateResponseEnvelopeSuccess `json:"success,required"`
157
+ JSON subscriptionUpdateResponseEnvelopeJSON `json:"-"`
158
+ }
159
+
160
+ // subscriptionUpdateResponseEnvelopeJSON contains the JSON metadata for the struct
161
+ // [SubscriptionUpdateResponseEnvelope]
162
+ type subscriptionUpdateResponseEnvelopeJSON struct {
163
+ Errors apijson.Field
164
+ Messages apijson.Field
165
+ Result apijson.Field
166
+ Success apijson.Field
167
+ raw string
168
+ ExtraFields map [string ]apijson.Field
169
+ }
170
+
171
+ func (r * SubscriptionUpdateResponseEnvelope ) UnmarshalJSON (data []byte ) (err error ) {
172
+ return apijson .UnmarshalRoot (data , r )
173
+ }
174
+
175
+ func (r subscriptionUpdateResponseEnvelopeJSON ) RawJSON () string {
176
+ return r .raw
177
+ }
178
+
179
+ // Whether the API call was successful
180
+ type SubscriptionUpdateResponseEnvelopeSuccess bool
181
+
182
+ const (
183
+ SubscriptionUpdateResponseEnvelopeSuccessTrue SubscriptionUpdateResponseEnvelopeSuccess = true
184
+ )
185
+
186
+ func (r SubscriptionUpdateResponseEnvelopeSuccess ) IsKnown () bool {
187
+ switch r {
188
+ case SubscriptionUpdateResponseEnvelopeSuccessTrue :
189
+ return true
190
+ }
191
+ return false
192
+ }
193
+
194
+ type SubscriptionGetParams struct {
195
+ // Subscription identifier tag.
196
+ ZoneID param.Field [string ] `path:"zone_id,required"`
197
+ }
198
+
199
+ type SubscriptionGetResponseEnvelope struct {
200
+ Errors []shared.ResponseInfo `json:"errors,required"`
201
+ Messages []shared.ResponseInfo `json:"messages,required"`
202
+ Result shared.Subscription `json:"result,required"`
203
+ // Whether the API call was successful
204
+ Success SubscriptionGetResponseEnvelopeSuccess `json:"success,required"`
205
+ JSON subscriptionGetResponseEnvelopeJSON `json:"-"`
206
+ }
207
+
208
+ // subscriptionGetResponseEnvelopeJSON contains the JSON metadata for the struct
209
+ // [SubscriptionGetResponseEnvelope]
210
+ type subscriptionGetResponseEnvelopeJSON struct {
211
+ Errors apijson.Field
212
+ Messages apijson.Field
213
+ Result apijson.Field
214
+ Success apijson.Field
215
+ raw string
216
+ ExtraFields map [string ]apijson.Field
217
+ }
218
+
219
+ func (r * SubscriptionGetResponseEnvelope ) UnmarshalJSON (data []byte ) (err error ) {
220
+ return apijson .UnmarshalRoot (data , r )
221
+ }
222
+
223
+ func (r subscriptionGetResponseEnvelopeJSON ) RawJSON () string {
224
+ return r .raw
225
+ }
226
+
227
+ // Whether the API call was successful
228
+ type SubscriptionGetResponseEnvelopeSuccess bool
229
+
230
+ const (
231
+ SubscriptionGetResponseEnvelopeSuccessTrue SubscriptionGetResponseEnvelopeSuccess = true
232
+ )
233
+
234
+ func (r SubscriptionGetResponseEnvelopeSuccess ) IsKnown () bool {
235
+ switch r {
236
+ case SubscriptionGetResponseEnvelopeSuccessTrue :
237
+ return true
238
+ }
239
+ return false
240
+ }
0 commit comments