companies-house-rest 0.6.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -5
- data/companies-house-rest.gemspec +3 -2
- data/lib/companies_house/client.rb +52 -21
- data/lib/companies_house/request.rb +1 -3
- data/lib/companies_house/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1eada87d8dfd0ac776c7bdfde3309c6390d68aeaf417d64e6a3c91bb9f5925ee
|
4
|
+
data.tar.gz: bcf2e4a7f1373445f5901442172f470bf79c07bf73e2ed9102dfbecc42dae0da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be7c1e511e804253ca000b2f2a2850b80a891251dc83ebade648956eb7ca6e7589fa8ffb4cdaed29fc4b3bee3f8300b2afc6d829540b21980e51a3677ff472b0
|
7
|
+
data.tar.gz: af7dca756e367a4da419977f5f402a3ec3c5acfa5c77f26cb44eafa7c5ae90fce14d08276db66a12ab02ee48d630ae3229cb9eb0f117d40b32b350abc1a392ea
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# CompaniesHouse::Client
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![GH Actions](https://github.com/gocardless/companies-house-rest/actions/workflows/main.yml/badge.svg)](https://github.com/gocardless/companies-house-rest/actions)
|
4
4
|
|
5
5
|
This Gem implements an API client for the Companies House REST API. It can be
|
6
6
|
used to look up information about companies registered in the United Kingdom.
|
@@ -13,6 +13,7 @@ see the gem [companies-house-gateway](https://github.com/gocardless/companies-ho
|
|
13
13
|
(Monthly subscription [fees](http://xmlgw.companieshouse.gov.uk/CHDpriceList.shtml), and other fees, may apply.)
|
14
14
|
|
15
15
|
Quick start:
|
16
|
+
|
16
17
|
* Register an account via the `Sign In / Register` link
|
17
18
|
[on the CompaniesHouse Developers website](https://developer.companieshouse.gov.uk/api/docs/)
|
18
19
|
* Register an API key at [Your Applications](https://developer.companieshouse.gov.uk/developer/applications)
|
@@ -20,8 +21,8 @@ Quick start:
|
|
20
21
|
|
21
22
|
``` shell
|
22
23
|
export COMPANIES_HOUSE_API_KEY=YOUR_API_KEY_HERE
|
23
|
-
|
24
24
|
```
|
25
|
+
|
25
26
|
* Install `companies-house-rest` through [RubyGems](https://rubygems.org/gems/companies-house-rest)
|
26
27
|
* Create and use a client:
|
27
28
|
|
@@ -31,8 +32,8 @@ client = CompaniesHouse::Client.new(api_key: ENV['COMPANIES_HOUSE_API_KEY'])
|
|
31
32
|
profile = client.company('07495895')
|
32
33
|
```
|
33
34
|
|
34
|
-
|
35
35
|
## Overview
|
36
|
+
|
36
37
|
This gem is meant to provide a simple synchronous API to look up company profile
|
37
38
|
information and company officers. The data returned is parsed JSON.
|
38
39
|
|
@@ -76,6 +77,7 @@ hash are:
|
|
76
77
|
| `:instrumentation` | Optional. Instruments the request/response (see Instrumentation for details) |
|
77
78
|
|
78
79
|
## Instrumentation
|
80
|
+
|
79
81
|
By default, no instrumentation is being applied.
|
80
82
|
If you are using Rails or the `ActiveSupport` gem, instrumentation will happen automatically via ![ActiveSupport::Notifications](https://api.rubyonrails.org/classes/ActiveSupport/Notifications.html)
|
81
83
|
|
@@ -93,11 +95,13 @@ The endpoints currently implemented by the gem are:
|
|
93
95
|
| `.company_search(query, items_per_page: nil, start_index: nil)` | `GET /search/companies` | Retrieves a list of companies that match the given query. |
|
94
96
|
|
95
97
|
### .company
|
98
|
+
|
96
99
|
This method implements the [readCompanyProfile](https://developer.companieshouse.gov.uk/api/docs/company/company_number/readCompanyProfile.html)
|
97
100
|
API and returns the full [companyProfile](https://developer.companieshouse.gov.uk/api/docs/company/company_number/companyProfile-resource.html)
|
98
101
|
resource.
|
99
102
|
|
100
103
|
### .officers
|
104
|
+
|
101
105
|
This method implements the [officersList](https://developer.companieshouse.gov.uk/api/docs/company/company_number/officers/officerList.html)
|
102
106
|
API. It will make one or more requests against this API, as necessary, to obtain
|
103
107
|
the full list of company officers. It returns only the values under the `items`
|
@@ -106,23 +110,28 @@ key from the
|
|
106
110
|
resource(s) which it reads.
|
107
111
|
|
108
112
|
### .company_search
|
113
|
+
|
109
114
|
This method implements the [searchCompanies](https://developer.companieshouse.gov.uk/api/docs/search/companies/companysearch.html)
|
110
115
|
API and returns the list of [companySearch](https://developer.companieshouse.gov.uk/api/docs/search-overview/CompanySearch-resource.html)
|
111
116
|
resources that match the given query. The `items_per_page` and `start_index` parameters are optional.
|
112
117
|
|
113
118
|
### .filing_history_list
|
119
|
+
|
114
120
|
This method implements the [filingHistoryList](https://developer.companieshouse.gov.uk/api/docs/company/company_number/filing-history/getFilingHistoryList.html) API and returns the full [filingHistoryList](https://developer.companieshouse.gov.uk/api/docs/company/company_number/filing-history/filingHistoryList-resource.html) resource.
|
115
121
|
|
116
122
|
### .filing_history_item
|
123
|
+
|
117
124
|
This method implements the [filingHistoryItem](https://developer.companieshouse.gov.uk/api/docs/company/company_number/filing-history/transaction_id/getFilingHistoryItem.html) API and returns the full
|
118
125
|
[filingHistoryItem](https://developer.companieshouse.gov.uk/api/docs/company/company_number/filing-history/filingHistoryItem-resource.html) resource.
|
119
126
|
|
120
127
|
### Other API Methods
|
128
|
+
|
121
129
|
While there are other resources exposed by the
|
122
130
|
[Companies House API](https://developer.companieshouse.gov.uk/api/docs/index.html),
|
123
131
|
this gem does not implement access to these resources at this time.
|
124
132
|
|
125
133
|
## Error Handling
|
134
|
+
|
126
135
|
If a request to the Companies House API encounters an HTTP status other than
|
127
136
|
`200 OK`, it will raise an instance of `CompaniesHouse::APIError` instead of
|
128
137
|
returning response data. The error will have the following fields:
|
@@ -132,7 +141,6 @@ returning response data. The error will have the following fields:
|
|
132
141
|
| `response` | The Net::HTTP response object from the failed API call. |
|
133
142
|
| `status` | A string containing the response status code. |
|
134
143
|
|
135
|
-
|
136
144
|
Certain API responses will raise an instance of a more specific subclass of
|
137
145
|
`CompaniesHouse::APIError`:
|
138
146
|
|
@@ -158,7 +166,6 @@ To get started:
|
|
158
166
|
bundle install --path vendor
|
159
167
|
```
|
160
168
|
|
161
|
-
|
162
169
|
To run all tests and Rubocop:
|
163
170
|
|
164
171
|
```shell
|
@@ -20,15 +20,16 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.bindir = "exe"
|
21
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
22
|
spec.require_paths = ["lib"]
|
23
|
-
spec.required_ruby_version = ">=
|
23
|
+
spec.required_ruby_version = ">= 3.0.2"
|
24
24
|
|
25
25
|
spec.add_runtime_dependency "dry-struct", "~> 1"
|
26
26
|
|
27
27
|
spec.add_development_dependency "activesupport", ">= 4.2", "< 7"
|
28
|
-
spec.add_development_dependency "gc_ruboconfig", "~>
|
28
|
+
spec.add_development_dependency "gc_ruboconfig", "~> 3.6"
|
29
29
|
spec.add_development_dependency "rake", "~> 13.0"
|
30
30
|
spec.add_development_dependency "rspec", "~> 3.5"
|
31
31
|
spec.add_development_dependency "rspec_junit_formatter", "~> 0.4.1"
|
32
32
|
spec.add_development_dependency "timecop", "~> 0.8"
|
33
33
|
spec.add_development_dependency "webmock", "~> 3.0"
|
34
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
34
35
|
end
|
@@ -24,14 +24,27 @@ module CompaniesHouse
|
|
24
24
|
@read_timeout = config[:read_timeout] || 60
|
25
25
|
@instrumentation = configure_instrumentation(config[:instrumentation])
|
26
26
|
raise ArgumentError, "HTTP is not supported" if @endpoint.scheme != "https"
|
27
|
+
|
28
|
+
# Clear stale thread-local connection object if necessary - its lifetime should
|
29
|
+
# match the lifetime of the client object
|
30
|
+
Thread.current[:companies_house_client_connection] = nil
|
27
31
|
end
|
28
32
|
|
29
33
|
def end_connection
|
30
|
-
|
34
|
+
return if Thread.current[:companies_house_client_connection].nil?
|
35
|
+
return unless Thread.current[:companies_house_client_connection].started?
|
36
|
+
|
37
|
+
Thread.current[:companies_house_client_connection].finish
|
38
|
+
Thread.current[:companies_house_client_connection] = nil
|
31
39
|
end
|
32
40
|
|
33
41
|
def company(id)
|
34
|
-
request(
|
42
|
+
request(
|
43
|
+
resource: :company,
|
44
|
+
path: "company/#{id}",
|
45
|
+
params: {},
|
46
|
+
resource_id: id,
|
47
|
+
)
|
35
48
|
end
|
36
49
|
|
37
50
|
def officers(id)
|
@@ -47,39 +60,53 @@ module CompaniesHouse
|
|
47
60
|
)
|
48
61
|
end
|
49
62
|
|
63
|
+
def persons_with_significant_control_statements(id, register_view: false)
|
64
|
+
get_all_pages(
|
65
|
+
:persons_with_significant_control_statements,
|
66
|
+
"company/#{id}/persons-with-significant-control-statements",
|
67
|
+
id,
|
68
|
+
register_view: register_view,
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
50
72
|
def filing_history_list(id)
|
51
73
|
get_all_pages(:filing_history_list, "company/#{id}/filing-history", id)
|
52
74
|
end
|
53
75
|
|
54
76
|
def filing_history_item(id, transaction_id)
|
55
77
|
request(
|
56
|
-
:filing_history_item,
|
57
|
-
"company/#{id}/filing-history/#{transaction_id}",
|
78
|
+
resource: :filing_history_item,
|
79
|
+
path: "company/#{id}/filing-history/#{transaction_id}",
|
58
80
|
)
|
59
81
|
end
|
60
82
|
|
61
83
|
def company_search(query, items_per_page: nil, start_index: nil)
|
62
84
|
request(
|
63
|
-
:company_search,
|
64
|
-
"search/companies",
|
65
|
-
|
85
|
+
resource: :company_search,
|
86
|
+
path: "search/companies",
|
87
|
+
params: {
|
88
|
+
q: query, items_per_page: items_per_page, start_index: start_index
|
89
|
+
}.compact,
|
66
90
|
)
|
67
91
|
end
|
68
92
|
|
69
93
|
def connection
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
94
|
+
Thread.current[:companies_house_client_connection] ||=
|
95
|
+
Net::HTTP.new(endpoint.host, endpoint.port).tap do |conn|
|
96
|
+
conn.use_ssl = true
|
97
|
+
conn.open_timeout = @open_timeout
|
98
|
+
conn.read_timeout = @read_timeout
|
99
|
+
end
|
75
100
|
end
|
76
101
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
102
|
+
private
|
103
|
+
|
104
|
+
def request(resource:,
|
105
|
+
path:,
|
106
|
+
params: {},
|
107
|
+
transaction_id: make_transaction_id,
|
108
|
+
resource_id: nil,
|
109
|
+
headers: {})
|
83
110
|
Request.new(
|
84
111
|
connection: connection,
|
85
112
|
api_key: @api_key,
|
@@ -94,8 +121,6 @@ module CompaniesHouse
|
|
94
121
|
).execute
|
95
122
|
end
|
96
123
|
|
97
|
-
private
|
98
|
-
|
99
124
|
# Fetch and combine all pages of a paginated API call
|
100
125
|
def get_all_pages(resource, path, id, query = {})
|
101
126
|
items = []
|
@@ -103,7 +128,13 @@ module CompaniesHouse
|
|
103
128
|
xid = make_transaction_id
|
104
129
|
|
105
130
|
loop do
|
106
|
-
page = request(
|
131
|
+
page = request(
|
132
|
+
resource: resource,
|
133
|
+
path: path,
|
134
|
+
params: query.merge(start_index: offset),
|
135
|
+
transaction_id: xid,
|
136
|
+
resource_id: id,
|
137
|
+
)
|
107
138
|
new_items = page["items"]
|
108
139
|
total = page["total_results"] || new_items.count
|
109
140
|
|
@@ -83,12 +83,11 @@ module CompaniesHouse
|
|
83
83
|
)
|
84
84
|
end
|
85
85
|
|
86
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
87
86
|
def parse(response, resource_type, resource_id)
|
88
87
|
case response.code
|
89
88
|
when "200"
|
90
89
|
JSON[response.body]
|
91
|
-
when "302" then {
|
90
|
+
when "302" then { location: response["location"] }
|
92
91
|
when "401"
|
93
92
|
raise CompaniesHouse::AuthenticationError, response
|
94
93
|
when "404"
|
@@ -101,6 +100,5 @@ module CompaniesHouse
|
|
101
100
|
raise CompaniesHouse::APIError.new("Unknown API response", response)
|
102
101
|
end
|
103
102
|
end
|
104
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
105
103
|
end
|
106
104
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: companies-house-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GoCardless Engineering
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-struct
|
@@ -50,14 +50,14 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
53
|
+
version: '3.6'
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
60
|
+
version: '3.6'
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rake
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,7 +154,8 @@ files:
|
|
154
154
|
homepage: https://github.com/gocardless/companies-house-rest
|
155
155
|
licenses:
|
156
156
|
- MIT
|
157
|
-
metadata:
|
157
|
+
metadata:
|
158
|
+
rubygems_mfa_required: 'true'
|
158
159
|
post_install_message:
|
159
160
|
rdoc_options: []
|
160
161
|
require_paths:
|
@@ -163,14 +164,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
163
164
|
requirements:
|
164
165
|
- - ">="
|
165
166
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
167
|
+
version: 3.0.2
|
167
168
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
169
|
requirements:
|
169
170
|
- - ">="
|
170
171
|
- !ruby/object:Gem::Version
|
171
172
|
version: '0'
|
172
173
|
requirements: []
|
173
|
-
rubygems_version: 3.
|
174
|
+
rubygems_version: 3.3.7
|
174
175
|
signing_key:
|
175
176
|
specification_version: 4
|
176
177
|
summary: Look up UK company registration information
|