-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
383 lines (344 loc) · 12.5 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
package chapi
import (
"encoding/json"
"github.com/jimsmart/chapi/ch"
)
// TODO(js) Look into decoding/unmarshalling streaming JSON ?
// Client provides higher-level API to access to the Companies House API,
// with all methods returning unmarshalled JSON structs.
//
// To work with this same API but with raw JSON bytes, see RESTClient.
type Client struct {
*RESTClient
}
// NewClient creats a new instance of Client.
//
// By default, it will use the API key provided by the APIKey package variable
// and the HTTPClient provided by the DefaultHTTPClient package variable.
func NewClient() *Client {
return &Client{RESTClient: &RESTClient{}}
}
// NewClientWithKey creats a new instance of Client, configured to use the given API key
// and the HTTPClient provided by the DefaultHTTPClient package variable.
func NewClientWithKey(apiKey string) *Client {
return &Client{
RESTClient: &RESTClient{
APIKey: apiKey,
},
}
}
// Search performs a query across all Companies House indexed information.
// To search against specific resource types,
// see SearchCompanies, SearchOfficers or SearchDisqualifiedOfficers.
//
// Where q is the term being searched for,
// limit is the number of search results to return 'per page',
// and offset is the index of the first item to return.
//
// Passing a value of -1 for limit or offset will cause the
// parameter to be ignored and not sent to the server.
//
// See https://developer.companieshouse.gov.uk/api/docs/search/search.html
func (c *Client) Search(q string, limit, offset int) (*ch.SearchResource, error) {
data, err := c.RESTClient.Search(q, limit, offset)
if err != nil {
return nil, err
}
var r ch.SearchResource
err = json.Unmarshal(data, &r)
return &r, err
}
// SearchCompanies performs a search of company information.
//
// Where q is the term being searched for,
// limit is the number of search results to return 'per page',
// and offset is the index of the first item to return.
//
// Passing a value of -1 for limit or offset will cause the
// parameter to be ignored and not sent to the server.
//
// See https://developer.companieshouse.gov.uk/api/docs/search/companies/companysearch.html
func (c *Client) SearchCompanies(q string, limit, offset int) (*ch.CompanySearchResource, error) {
data, err := c.RESTClient.SearchCompanies(q, limit, offset)
if err != nil {
return nil, err
}
var r ch.CompanySearchResource
err = json.Unmarshal(data, &r)
return &r, err
}
// SearchOfficers performs a search of officer information.
//
// Where q is the term being searched for,
// limit is the number of search results to return 'per page',
// and offset is the index of the first item to return.
//
// Passing a value of -1 for limit or offset will cause the
// parameter to be ignored and not sent to the server.
//
// See https://developer.companieshouse.gov.uk/api/docs/search/officers/officersearch.html
func (c *Client) SearchOfficers(q string, limit, offset int) (*ch.OfficerSearchResource, error) {
data, err := c.RESTClient.SearchOfficers(q, limit, offset)
if err != nil {
return nil, err
}
var r ch.OfficerSearchResource
err = json.Unmarshal(data, &r)
return &r, err
}
// SearchDisqualifiedOfficers performs a search of disqualified officer information.
//
// Where q is the term being searched for,
// limit is the number of search results to return 'per page',
// and offset is the index of the first item to return.
//
// Passing a value of -1 for limit or offset will cause the
// parameter to be ignored and not sent to the server.
//
// See https://developer.companieshouse.gov.uk/api/docs/search/disqualified-officers/disqualifiedofficersearch.html
func (c *Client) SearchDisqualifiedOfficers(q string, limit, offset int) (*ch.DisqualifiedOfficerSearchResource, error) {
data, err := c.RESTClient.SearchDisqualifiedOfficers(q, limit, offset)
if err != nil {
return nil, err
}
var r ch.DisqualifiedOfficerSearchResource
err = json.Unmarshal(data, &r)
return &r, err
}
// CompanyProfile gets the basic company information.
//
// See https://developer.companieshouse.gov.uk/api/docs/company/company_number/readCompanyProfile.html
func (c *Client) CompanyProfile(companyNumber string) (*ch.CompanyProfileResource, error) {
data, err := c.RESTClient.CompanyProfile(companyNumber)
if err != nil {
return nil, err
}
var r ch.CompanyProfileResource
err = json.Unmarshal(data, &r)
return &r, err
}
// CompanyRegisteredOfficeAddress gets the current address of a company.
//
// See https://developer.companieshouse.gov.uk/api/docs/company/company_number/registered-office-address/readRegisteredOfficeAddress.html
func (c *Client) CompanyRegisteredOfficeAddress(companyNumber string) (*ch.RegisteredOfficeAddressResource, error) {
data, err := c.RESTClient.CompanyRegisteredOfficeAddress(companyNumber)
if err != nil {
return nil, err
}
var r ch.RegisteredOfficeAddressResource
err = json.Unmarshal(data, &r)
return &r, err
}
// type CORegisterType string
// type COSortOrder string
// const (
// Directors CORegisterType = "directors"
// Secretaries CORegisterType = "secretaries"
// LLPMembers CORegisterType = "llp-members"
// AppointedOn COSortOrder = "appointed_on"
// AppointedOnDesc COSortOrder = "-appointed_on"
// ResignedOn COSortOrder = "resigned_on"
// ResignedOnDesc COSortOrder = "-resigned_on"
// Surname COSortOrder = "surname"
// SurnameDesc COSortOrder = "-surname"
// )
// register_type string (optional) "", "directors", "secretaries", "llp-members"
// register_view bool (optional) set to true if register_type != ""
// order_by string (optional) "", "appointed_on", "resigned_on", "surname" - can also have "-" prefix.
// TODO(js) Documentation.
// TODO actual string for LLP Members register_type is "llp_members" (2016-10-02)
// CompanyOfficers lists the company officers.
//
// See https://developer.companieshouse.gov.uk/api/docs/company/company_number/officers/officerList.html
func (c *Client) CompanyOfficers(companyNumber, registerType, sortOrder string, limit, offset int) (*ch.OfficerListResource, error) {
data, err := c.RESTClient.CompanyOfficers(companyNumber, registerType, sortOrder, limit, offset)
if err != nil {
return nil, err
}
var r ch.OfficerListResource
err = json.Unmarshal(data, &r)
return &r, err
}
// CompanyFilingHistory gets the filing history of the company.
//
// See https://developer.companieshouse.gov.uk/api/docs/company/company_number/filing-history/getFilingHistoryList.html
func (c *Client) CompanyFilingHistory(companyNumber, categoryFilter string, limit, offset int) (*ch.FilingHistoryListResource, error) {
data, err := c.RESTClient.CompanyFilingHistory(companyNumber, categoryFilter, limit, offset)
if err != nil {
return nil, err
}
var r ch.FilingHistoryListResource
err = json.Unmarshal(data, &r)
return &r, err
}
// CompanyFilingHistoryTransaction gets a single item from the filing history of the company.
//
// See https://developer.companieshouse.gov.uk/api/docs/company/company_number/filing-history/transaction_id/getFilingHistoryItem.html
func (c *Client) CompanyFilingHistoryTransaction(companyNumber, transactionID string) (*ch.FilingHistoryItemResource, error) {
data, err := c.RESTClient.CompanyFilingHistoryTransaction(companyNumber, transactionID)
if err != nil {
return nil, err
}
var r ch.FilingHistoryItemResource
err = json.Unmarshal(data, &r)
return &r, err
}
// CompanyInsolvency gets company insolvency information.
//
// See https://developer.companieshouse.gov.uk/api/docs/company/company_number/insolvency/readCompanyInsolvency.html
func (c *Client) CompanyInsolvency(companyNumber string) (*ch.CompanyInsolvencyResource, error) {
data, err := c.RESTClient.CompanyInsolvency(companyNumber)
if err != nil {
return nil, err
}
var r ch.CompanyInsolvencyResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) CompanyCharges(companyNumber string, limit, offset int) (*ch.ChargeListResource, error) {
data, err := c.RESTClient.CompanyCharges(companyNumber, limit, offset)
if err != nil {
return nil, err
}
var r ch.ChargeListResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) CompanyCharge(companyNumber, chargeID string) (*ch.ChargeDetailsResource, error) {
data, err := c.RESTClient.CompanyCharge(companyNumber, chargeID)
if err != nil {
return nil, err
}
var r ch.ChargeDetailsResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) OfficerAppointments(officerID string, limit, offset int) (*ch.AppointmentListResource, error) {
data, err := c.RESTClient.OfficerAppointments(officerID, limit, offset)
if err != nil {
return nil, err
}
var r ch.AppointmentListResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) OfficerNaturalDisqualifications(officerID string) (*ch.NaturalDisqualificationResource, error) {
data, err := c.RESTClient.OfficerNaturalDisqualifications(officerID)
if err != nil {
return nil, err
}
var r ch.NaturalDisqualificationResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) OfficerCorporateDisqualifications(officerID string) (*ch.CorporateDisqualificationResource, error) {
data, err := c.RESTClient.OfficerCorporateDisqualifications(officerID)
if err != nil {
return nil, err
}
var r ch.CorporateDisqualificationResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) CompanyUKEstablishments(companyNumber string) (*ch.CompanyUKEstablishmentsResource, error) {
data, err := c.RESTClient.CompanyUKEstablishments(companyNumber)
if err != nil {
return nil, err
}
var r ch.CompanyUKEstablishmentsResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) PSCs(companyNumber string, registerView bool, limit, offset int) (*ch.PSCListResource, error) {
data, err := c.RESTClient.PSCs(companyNumber, registerView, limit, offset)
if err != nil {
return nil, err
}
var r ch.PSCListResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) PSCIndividual(companyNumber, pscID string) (*ch.PSCIndividualResource, error) {
data, err := c.RESTClient.PSCIndividual(companyNumber, pscID)
if err != nil {
return nil, err
}
var r ch.PSCIndividualResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) PSCCorporateEntity(companyNumber, pscID string) (*ch.PSCCorporateEntityResource, error) {
data, err := c.RESTClient.PSCCorporateEntity(companyNumber, pscID)
if err != nil {
return nil, err
}
var r ch.PSCCorporateEntityResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) PSCLegalPerson(companyNumber, pscID string) (*ch.PSCLegalPersonResource, error) {
data, err := c.RESTClient.PSCLegalPerson(companyNumber, pscID)
if err != nil {
return nil, err
}
var r ch.PSCLegalPersonResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) PSCStatements(companyNumber string, registerView bool, limit, offset int) (*ch.PSCStatementListResource, error) {
data, err := c.RESTClient.PSCStatements(companyNumber, registerView, limit, offset)
if err != nil {
return nil, err
}
var r ch.PSCStatementListResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) PSCStatement(companyNumber, statementID string) (*ch.PSCStatementResource, error) {
data, err := c.RESTClient.PSCStatement(companyNumber, statementID)
if err != nil {
return nil, err
}
var r ch.PSCStatementResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) PSCSuperSecure(companyNumber, superSecureID string) (*ch.PSCSuperSecureResource, error) {
data, err := c.RESTClient.PSCSuperSecure(companyNumber, superSecureID)
if err != nil {
return nil, err
}
var r ch.PSCSuperSecureResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) CompanyRegisters(companyNumber string) (*ch.CompanyRegisterResource, error) {
data, err := c.RESTClient.CompanyRegisters(companyNumber)
if err != nil {
return nil, err
}
var r ch.CompanyRegisterResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) CompanyExemptions(companyNumber string) (*ch.CompanyExemptionsResource, error) {
data, err := c.RESTClient.CompanyExemptions(companyNumber)
if err != nil {
return nil, err
}
var r ch.CompanyExemptionsResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) DocumentMetadata(documentID string) (*ch.DocumentMetadataResource, error) {
data, err := c.RESTClient.DocumentMetadata(documentID)
if err != nil {
return nil, err
}
var r ch.DocumentMetadataResource
err = json.Unmarshal(data, &r)
return &r, err
}
func (c *Client) DocumentContent(documentID string) ([]byte, error) {
return c.RESTClient.DocumentContent(documentID)
}