-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabra.go
executable file
·180 lines (152 loc) · 4.29 KB
/
fabra.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
// Code generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.
package fabra
import (
"github.com/fabra-io/go-sdk/pkg/models/shared"
"github.com/fabra-io/go-sdk/pkg/utils"
"net/http"
"time"
)
// ServerList contains the list of servers available to the SDK
var ServerList = []string{
"https://api.fabra.io",
}
// HTTPClient provides an interface for suplying the SDK with a custom HTTP client
type HTTPClient interface {
Do(req *http.Request) (*http.Response, error)
}
// String provides a helper function to return a pointer to a string
func String(s string) *string { return &s }
// Bool provides a helper function to return a pointer to a bool
func Bool(b bool) *bool { return &b }
// Int provides a helper function to return a pointer to an int
func Int(i int) *int { return &i }
// Int64 provides a helper function to return a pointer to an int64
func Int64(i int64) *int64 { return &i }
// Float32 provides a helper function to return a pointer to a float32
func Float32(f float32) *float32 { return &f }
// Float64 provides a helper function to return a pointer to a float64
func Float64(f float64) *float64 { return &f }
type Fabra struct {
// Connection - Operations on connections
Connection *connection
// Destination - Operations on destinations
Destination *destination
// LinkToken - Operations on link tokens
LinkToken *linkToken
// Object - Operations on objects
Object *object
// Source - Operations on sources
Source *source
// Sync - Operations on syncs
Sync *sync
// Non-idiomatic field names below are to namespace fields from the fields names above to avoid name conflicts
_defaultClient HTTPClient
_securityClient HTTPClient
_security *shared.Security
_serverURL string
_language string
_sdkVersion string
_genVersion string
}
type SDKOption func(*Fabra)
// WithServerURL allows the overriding of the default server URL
func WithServerURL(serverURL string) SDKOption {
return func(sdk *Fabra) {
sdk._serverURL = serverURL
}
}
// WithTemplatedServerURL allows the overriding of the default server URL with a templated URL populated with the provided parameters
func WithTemplatedServerURL(serverURL string, params map[string]string) SDKOption {
return func(sdk *Fabra) {
if params != nil {
serverURL = utils.ReplaceParameters(serverURL, params)
}
sdk._serverURL = serverURL
}
}
// WithClient allows the overriding of the default HTTP client used by the SDK
func WithClient(client HTTPClient) SDKOption {
return func(sdk *Fabra) {
sdk._defaultClient = client
}
}
// WithSecurity configures the SDK to use the provided security details
func WithSecurity(security shared.Security) SDKOption {
return func(sdk *Fabra) {
sdk._security = &security
}
}
// New creates a new instance of the SDK with the provided options
func New(opts ...SDKOption) *Fabra {
sdk := &Fabra{
_language: "go",
_sdkVersion: "0.6.0",
_genVersion: "2.26.0",
}
for _, opt := range opts {
opt(sdk)
}
// Use WithClient to override the default client if you would like to customize the timeout
if sdk._defaultClient == nil {
sdk._defaultClient = &http.Client{Timeout: 60 * time.Second}
}
if sdk._securityClient == nil {
if sdk._security != nil {
sdk._securityClient = utils.ConfigureSecurityClient(sdk._defaultClient, sdk._security)
} else {
sdk._securityClient = sdk._defaultClient
}
}
if sdk._serverURL == "" {
sdk._serverURL = ServerList[0]
}
sdk.Connection = newConnection(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.Destination = newDestination(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.LinkToken = newLinkToken(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.Object = newObject(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.Source = newSource(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
sdk.Sync = newSync(
sdk._defaultClient,
sdk._securityClient,
sdk._serverURL,
sdk._language,
sdk._sdkVersion,
sdk._genVersion,
)
return sdk
}