-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.go
204 lines (175 loc) · 7.21 KB
/
account.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
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package finchgo
import (
"context"
"net/http"
"github.com/Finch-API/finch-api-go/internal/apijson"
"github.com/Finch-API/finch-api-go/internal/requestconfig"
"github.com/Finch-API/finch-api-go/option"
"github.com/Finch-API/finch-api-go/shared"
)
// AccountService contains methods and other services that help with interacting
// with the Finch API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewAccountService] method instead.
type AccountService struct {
Options []option.RequestOption
}
// NewAccountService generates a new service that applies the given options to each
// request. These options are applied after the parent client's options (if there
// is one), and before any request-specific options.
func NewAccountService(opts ...option.RequestOption) (r *AccountService) {
r = &AccountService{}
r.Options = opts
return
}
// Disconnect one or more `access_token`s from your application.
func (r *AccountService) Disconnect(ctx context.Context, opts ...option.RequestOption) (res *DisconnectResponse, err error) {
opts = append(r.Options[:], opts...)
path := "disconnect"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, nil, &res, opts...)
return
}
// Read account information associated with an `access_token`
func (r *AccountService) Introspect(ctx context.Context, opts ...option.RequestOption) (res *Introspection, err error) {
opts = append(r.Options[:], opts...)
path := "introspect"
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &res, opts...)
return
}
type DisconnectResponse struct {
// If the request is successful, Finch will return “success” (HTTP 200 status).
Status string `json:"status,required"`
JSON disconnectResponseJSON `json:"-"`
}
// disconnectResponseJSON contains the JSON metadata for the struct
// [DisconnectResponse]
type disconnectResponseJSON struct {
Status apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *DisconnectResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r disconnectResponseJSON) RawJSON() string {
return r.raw
}
type Introspection struct {
// The Finch uuid of the account used to connect this company.
AccountID string `json:"account_id,required"`
AuthenticationMethods []IntrospectionAuthenticationMethod `json:"authentication_methods,required"`
// The client id of the application associated with the `access_token`.
ClientID string `json:"client_id,required"`
// The type of application associated with a token.
ClientType IntrospectionClientType `json:"client_type,required"`
// The Finch uuid of the company associated with the `access_token`.
CompanyID string `json:"company_id,required"`
// The type of the connection associated with the token.
//
// - `provider` - connection to an external provider
// - `finch` - finch-generated data.
ConnectionType IntrospectionConnectionType `json:"connection_type,required"`
// Whether the connection associated with the `access_token` uses the Assisted
// Connect Flow. (`true` if using Assisted Connect, `false` if connection is
// automated)
Manual bool `json:"manual,required"`
// The payroll provider associated with the `access_token`.
PayrollProviderID string `json:"payroll_provider_id,required"`
// An array of the authorized products associated with the `access_token`.
Products []string `json:"products,required"`
// The account username used for login associated with the `access_token`.
Username string `json:"username,required"`
JSON introspectionJSON `json:"-"`
}
// introspectionJSON contains the JSON metadata for the struct [Introspection]
type introspectionJSON struct {
AccountID apijson.Field
AuthenticationMethods apijson.Field
ClientID apijson.Field
ClientType apijson.Field
CompanyID apijson.Field
ConnectionType apijson.Field
Manual apijson.Field
PayrollProviderID apijson.Field
Products apijson.Field
Username apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *Introspection) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r introspectionJSON) RawJSON() string {
return r.raw
}
type IntrospectionAuthenticationMethod struct {
ConnectionStatus IntrospectionAuthenticationMethodsConnectionStatus `json:"connection_status"`
Type string `json:"type"`
JSON introspectionAuthenticationMethodJSON `json:"-"`
}
// introspectionAuthenticationMethodJSON contains the JSON metadata for the struct
// [IntrospectionAuthenticationMethod]
type introspectionAuthenticationMethodJSON struct {
ConnectionStatus apijson.Field
Type apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *IntrospectionAuthenticationMethod) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r introspectionAuthenticationMethodJSON) RawJSON() string {
return r.raw
}
type IntrospectionAuthenticationMethodsConnectionStatus struct {
Message string `json:"message"`
Status shared.ConnectionStatusType `json:"status"`
JSON introspectionAuthenticationMethodsConnectionStatusJSON `json:"-"`
}
// introspectionAuthenticationMethodsConnectionStatusJSON contains the JSON
// metadata for the struct [IntrospectionAuthenticationMethodsConnectionStatus]
type introspectionAuthenticationMethodsConnectionStatusJSON struct {
Message apijson.Field
Status apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *IntrospectionAuthenticationMethodsConnectionStatus) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r introspectionAuthenticationMethodsConnectionStatusJSON) RawJSON() string {
return r.raw
}
// The type of application associated with a token.
type IntrospectionClientType string
const (
IntrospectionClientTypeProduction IntrospectionClientType = "production"
IntrospectionClientTypeDevelopment IntrospectionClientType = "development"
IntrospectionClientTypeSandbox IntrospectionClientType = "sandbox"
)
func (r IntrospectionClientType) IsKnown() bool {
switch r {
case IntrospectionClientTypeProduction, IntrospectionClientTypeDevelopment, IntrospectionClientTypeSandbox:
return true
}
return false
}
// The type of the connection associated with the token.
//
// - `provider` - connection to an external provider
// - `finch` - finch-generated data.
type IntrospectionConnectionType string
const (
IntrospectionConnectionTypeProvider IntrospectionConnectionType = "provider"
IntrospectionConnectionTypeFinch IntrospectionConnectionType = "finch"
)
func (r IntrospectionConnectionType) IsKnown() bool {
switch r {
case IntrospectionConnectionTypeProvider, IntrospectionConnectionTypeFinch:
return true
}
return false
}