-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
397 lines (348 loc) · 17.9 KB
/
client.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
/*
Package advancedbilling
This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
*/
package advancedbilling
import (
"context"
"fmt"
"github.com/apimatic/go-core-runtime/https"
"github.com/apimatic/go-core-runtime/utilities"
"net/http"
)
// Client is an interface representing the main client for accessing configuration and controllers.
type ClientInterface interface {
Configuration() Configuration
CloneWithConfiguration(options ...ConfigurationOptions) ClientInterface
APIExportsController() *APIExportsController
AdvanceInvoiceController() *AdvanceInvoiceController
BillingPortalController() *BillingPortalController
CouponsController() *CouponsController
ComponentsController() *ComponentsController
ComponentPricePointsController() *ComponentPricePointsController
CustomersController() *CustomersController
CustomFieldsController() *CustomFieldsController
EventsController() *EventsController
EventsBasedBillingSegmentsController() *EventsBasedBillingSegmentsController
InsightsController() *InsightsController
InvoicesController() *InvoicesController
OffersController() *OffersController
PaymentProfilesController() *PaymentProfilesController
ProductFamiliesController() *ProductFamiliesController
ProductsController() *ProductsController
ProductPricePointsController() *ProductPricePointsController
ProformaInvoicesController() *ProformaInvoicesController
ReasonCodesController() *ReasonCodesController
ReferralCodesController() *ReferralCodesController
SalesCommissionsController() *SalesCommissionsController
SitesController() *SitesController
SubscriptionsController() *SubscriptionsController
SubscriptionComponentsController() *SubscriptionComponentsController
SubscriptionGroupsController() *SubscriptionGroupsController
SubscriptionGroupInvoiceAccountController() *SubscriptionGroupInvoiceAccountController
SubscriptionGroupStatusController() *SubscriptionGroupStatusController
SubscriptionInvoiceAccountController() *SubscriptionInvoiceAccountController
SubscriptionNotesController() *SubscriptionNotesController
SubscriptionProductsController() *SubscriptionProductsController
SubscriptionStatusController() *SubscriptionStatusController
WebhooksController() *WebhooksController
UserAgent() *string
}
// client is an implementation of the Client interface.
type client struct {
callBuilderFactory https.CallBuilderFactory
configuration Configuration
userAgent string
apiExportsController APIExportsController
advanceInvoiceController AdvanceInvoiceController
billingPortalController BillingPortalController
couponsController CouponsController
componentsController ComponentsController
componentPricePointsController ComponentPricePointsController
customersController CustomersController
customFieldsController CustomFieldsController
eventsController EventsController
eventsBasedBillingSegmentsController EventsBasedBillingSegmentsController
insightsController InsightsController
invoicesController InvoicesController
offersController OffersController
paymentProfilesController PaymentProfilesController
productFamiliesController ProductFamiliesController
productsController ProductsController
productPricePointsController ProductPricePointsController
proformaInvoicesController ProformaInvoicesController
reasonCodesController ReasonCodesController
referralCodesController ReferralCodesController
salesCommissionsController SalesCommissionsController
sitesController SitesController
subscriptionsController SubscriptionsController
subscriptionComponentsController SubscriptionComponentsController
subscriptionGroupsController SubscriptionGroupsController
subscriptionGroupInvoiceAccountController SubscriptionGroupInvoiceAccountController
subscriptionGroupStatusController SubscriptionGroupStatusController
subscriptionInvoiceAccountController SubscriptionInvoiceAccountController
subscriptionNotesController SubscriptionNotesController
subscriptionProductsController SubscriptionProductsController
subscriptionStatusController SubscriptionStatusController
webhooksController WebhooksController
}
// NewClient is the constructor for creating a new client instance.
// It takes a Configuration object as a parameter and returns the Client interface.
func NewClient(configuration Configuration) ClientInterface {
client := &client{
configuration: configuration,
}
client.userAgent = utilities.UpdateUserAgent("AB SDK Go:0.4.2 on OS {os-info}")
client.callBuilderFactory = callBuilderHandler(
func(server string) string {
if server == "" {
server = "default"
}
return getBaseUri(Server(server), client.configuration)
},
createAuthenticationFromConfig(configuration),
https.NewHttpClient(configuration.HttpConfiguration()),
configuration.httpConfiguration.RetryConfiguration(),
https.Csv,
withUserAgent(client.userAgent),
withGlobalErrors(),
)
baseController := NewBaseController(client)
client.apiExportsController = *NewAPIExportsController(*baseController)
client.advanceInvoiceController = *NewAdvanceInvoiceController(*baseController)
client.billingPortalController = *NewBillingPortalController(*baseController)
client.couponsController = *NewCouponsController(*baseController)
client.componentsController = *NewComponentsController(*baseController)
client.componentPricePointsController = *NewComponentPricePointsController(*baseController)
client.customersController = *NewCustomersController(*baseController)
client.customFieldsController = *NewCustomFieldsController(*baseController)
client.eventsController = *NewEventsController(*baseController)
client.eventsBasedBillingSegmentsController = *NewEventsBasedBillingSegmentsController(*baseController)
client.insightsController = *NewInsightsController(*baseController)
client.invoicesController = *NewInvoicesController(*baseController)
client.offersController = *NewOffersController(*baseController)
client.paymentProfilesController = *NewPaymentProfilesController(*baseController)
client.productFamiliesController = *NewProductFamiliesController(*baseController)
client.productsController = *NewProductsController(*baseController)
client.productPricePointsController = *NewProductPricePointsController(*baseController)
client.proformaInvoicesController = *NewProformaInvoicesController(*baseController)
client.reasonCodesController = *NewReasonCodesController(*baseController)
client.referralCodesController = *NewReferralCodesController(*baseController)
client.salesCommissionsController = *NewSalesCommissionsController(*baseController)
client.sitesController = *NewSitesController(*baseController)
client.subscriptionsController = *NewSubscriptionsController(*baseController)
client.subscriptionComponentsController = *NewSubscriptionComponentsController(*baseController)
client.subscriptionGroupsController = *NewSubscriptionGroupsController(*baseController)
client.subscriptionGroupInvoiceAccountController = *NewSubscriptionGroupInvoiceAccountController(*baseController)
client.subscriptionGroupStatusController = *NewSubscriptionGroupStatusController(*baseController)
client.subscriptionInvoiceAccountController = *NewSubscriptionInvoiceAccountController(*baseController)
client.subscriptionNotesController = *NewSubscriptionNotesController(*baseController)
client.subscriptionProductsController = *NewSubscriptionProductsController(*baseController)
client.subscriptionStatusController = *NewSubscriptionStatusController(*baseController)
client.webhooksController = *NewWebhooksController(*baseController)
return client
}
// Configuration returns the configuration instance of the client.
func (c *client) Configuration() Configuration {
return c.configuration
}
// CloneWithConfiguration returns a new copy with the provided options of the configuration instance of the client.
func (c *client) CloneWithConfiguration(options ...ConfigurationOptions) ClientInterface {
return NewClient(c.configuration.cloneWithOptions(options...))
}
// APIExportsController returns the apiExportsController instance of the client.
func (c *client) APIExportsController() *APIExportsController {
return &c.apiExportsController
}
// AdvanceInvoiceController returns the advanceInvoiceController instance of the client.
func (c *client) AdvanceInvoiceController() *AdvanceInvoiceController {
return &c.advanceInvoiceController
}
// BillingPortalController returns the billingPortalController instance of the client.
func (c *client) BillingPortalController() *BillingPortalController {
return &c.billingPortalController
}
// CouponsController returns the couponsController instance of the client.
func (c *client) CouponsController() *CouponsController {
return &c.couponsController
}
// ComponentsController returns the componentsController instance of the client.
func (c *client) ComponentsController() *ComponentsController {
return &c.componentsController
}
// ComponentPricePointsController returns the componentPricePointsController instance of the client.
func (c *client) ComponentPricePointsController() *ComponentPricePointsController {
return &c.componentPricePointsController
}
// CustomersController returns the customersController instance of the client.
func (c *client) CustomersController() *CustomersController {
return &c.customersController
}
// CustomFieldsController returns the customFieldsController instance of the client.
func (c *client) CustomFieldsController() *CustomFieldsController {
return &c.customFieldsController
}
// EventsController returns the eventsController instance of the client.
func (c *client) EventsController() *EventsController {
return &c.eventsController
}
// EventsBasedBillingSegmentsController returns the eventsBasedBillingSegmentsController instance of the client.
func (c *client) EventsBasedBillingSegmentsController() *EventsBasedBillingSegmentsController {
return &c.eventsBasedBillingSegmentsController
}
// InsightsController returns the insightsController instance of the client.
func (c *client) InsightsController() *InsightsController {
return &c.insightsController
}
// InvoicesController returns the invoicesController instance of the client.
func (c *client) InvoicesController() *InvoicesController {
return &c.invoicesController
}
// OffersController returns the offersController instance of the client.
func (c *client) OffersController() *OffersController {
return &c.offersController
}
// PaymentProfilesController returns the paymentProfilesController instance of the client.
func (c *client) PaymentProfilesController() *PaymentProfilesController {
return &c.paymentProfilesController
}
// ProductFamiliesController returns the productFamiliesController instance of the client.
func (c *client) ProductFamiliesController() *ProductFamiliesController {
return &c.productFamiliesController
}
// ProductsController returns the productsController instance of the client.
func (c *client) ProductsController() *ProductsController {
return &c.productsController
}
// ProductPricePointsController returns the productPricePointsController instance of the client.
func (c *client) ProductPricePointsController() *ProductPricePointsController {
return &c.productPricePointsController
}
// ProformaInvoicesController returns the proformaInvoicesController instance of the client.
func (c *client) ProformaInvoicesController() *ProformaInvoicesController {
return &c.proformaInvoicesController
}
// ReasonCodesController returns the reasonCodesController instance of the client.
func (c *client) ReasonCodesController() *ReasonCodesController {
return &c.reasonCodesController
}
// ReferralCodesController returns the referralCodesController instance of the client.
func (c *client) ReferralCodesController() *ReferralCodesController {
return &c.referralCodesController
}
// SalesCommissionsController returns the salesCommissionsController instance of the client.
func (c *client) SalesCommissionsController() *SalesCommissionsController {
return &c.salesCommissionsController
}
// SitesController returns the sitesController instance of the client.
func (c *client) SitesController() *SitesController {
return &c.sitesController
}
// SubscriptionsController returns the subscriptionsController instance of the client.
func (c *client) SubscriptionsController() *SubscriptionsController {
return &c.subscriptionsController
}
// SubscriptionComponentsController returns the subscriptionComponentsController instance of the client.
func (c *client) SubscriptionComponentsController() *SubscriptionComponentsController {
return &c.subscriptionComponentsController
}
// SubscriptionGroupsController returns the subscriptionGroupsController instance of the client.
func (c *client) SubscriptionGroupsController() *SubscriptionGroupsController {
return &c.subscriptionGroupsController
}
// SubscriptionGroupInvoiceAccountController returns the subscriptionGroupInvoiceAccountController instance of the client.
func (c *client) SubscriptionGroupInvoiceAccountController() *SubscriptionGroupInvoiceAccountController {
return &c.subscriptionGroupInvoiceAccountController
}
// SubscriptionGroupStatusController returns the subscriptionGroupStatusController instance of the client.
func (c *client) SubscriptionGroupStatusController() *SubscriptionGroupStatusController {
return &c.subscriptionGroupStatusController
}
// SubscriptionInvoiceAccountController returns the subscriptionInvoiceAccountController instance of the client.
func (c *client) SubscriptionInvoiceAccountController() *SubscriptionInvoiceAccountController {
return &c.subscriptionInvoiceAccountController
}
// SubscriptionNotesController returns the subscriptionNotesController instance of the client.
func (c *client) SubscriptionNotesController() *SubscriptionNotesController {
return &c.subscriptionNotesController
}
// SubscriptionProductsController returns the subscriptionProductsController instance of the client.
func (c *client) SubscriptionProductsController() *SubscriptionProductsController {
return &c.subscriptionProductsController
}
// SubscriptionStatusController returns the subscriptionStatusController instance of the client.
func (c *client) SubscriptionStatusController() *SubscriptionStatusController {
return &c.subscriptionStatusController
}
// WebhooksController returns the webhooksController instance of the client.
func (c *client) WebhooksController() *WebhooksController {
return &c.webhooksController
}
// UserAgent returns the userAgent instance of the client.
func (c *client) UserAgent() *string {
return &c.userAgent
}
// GetCallBuilder returns the CallBuilderFactory used by the client.
func (c *client) GetCallBuilder() https.CallBuilderFactory {
return c.callBuilderFactory
}
// getBaseUri returns the base URI based on the server and configuration.
func getBaseUri(
server Server,
configuration Configuration) string {
if configuration.Environment() == Environment(PRODUCTION) {
if server == Server(ENUMDEFAULT) {
return fmt.Sprintf("https://%v.%v", configuration.Subdomain(), configuration.Domain())
}
}
if configuration.Environment() == Environment(ENVIRONMENT2) {
if server == Server(ENUMDEFAULT) {
return "https://events.chargify.com"
}
}
return "TODO: Select a valid server."
}
// clientOptions is a function type representing options for the client.
type clientOptions func(cb https.CallBuilder)
// callBuilderHandler creates the call builder factory with various options.
func callBuilderHandler(
baseUrlProvider func(server string) string,
auth map[string]https.AuthInterface,
httpClient https.HttpClient,
retryConfig RetryConfiguration,
arraySerializationOption https.ArraySerializationOption,
opts ...clientOptions) https.CallBuilderFactory {
callBuilderFactory := https.CreateCallBuilderFactory(baseUrlProvider, auth, httpClient, retryConfig, arraySerializationOption)
return tap(callBuilderFactory, opts...)
}
// tap is a utility function to apply client options to the call builder factory.
func tap(
callBuilderFactory https.CallBuilderFactory,
opts ...clientOptions) https.CallBuilderFactory {
return func(ctx context.Context, httpMethod, path string) https.CallBuilder {
callBuilder := callBuilderFactory(ctx, httpMethod, path)
for _, opt := range opts {
opt(callBuilder)
}
return callBuilder
}
}
// withUserAgent is an option to add a user agent header to the HTTP request.
func withUserAgent(userAgent string) clientOptions {
f := func(request *http.Request) *http.Request {
request.Header.Set("user-agent", userAgent)
return request
}
return func(cb https.CallBuilder) {
cb.InterceptRequest(f)
}
}
// withGlobalErrors will add all globally defined errors to callBuilder.
func withGlobalErrors() clientOptions {
return func(cb https.CallBuilder) {
cb.AppendErrors(map[string]https.ErrorBuilder[error]{
"404": {TemplatedMessage: "Not Found:'{$response.body}'"},
"0": {TemplatedMessage: "HTTP Response Not OK. Status code: {$statusCode}. Response: '{$response.body}'."},
})
}
}