companies-house-rest 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acbe329349686658408d7b6d6cc2ba267b6a685f01238a56d00a465853f2862b
4
- data.tar.gz: 55ad4bcb56c3895963785a1bb173c7095ad5443b9819bb562280d2df67bcb68d
3
+ metadata.gz: 1eada87d8dfd0ac776c7bdfde3309c6390d68aeaf417d64e6a3c91bb9f5925ee
4
+ data.tar.gz: bcf2e4a7f1373445f5901442172f470bf79c07bf73e2ed9102dfbecc42dae0da
5
5
  SHA512:
6
- metadata.gz: a5df96312aae7d77a847b33ad67b916fcfc3ef2ea67c8c333523322389adb79baed76033847c64a4aff29ab30c5b0bc1896ea8b40b6f72365c06fade8ff3ff57
7
- data.tar.gz: 05ab11572766fdc6d61fa9d32ed9088297fc3dd399853343a9ad1767ede56ad94ef04f024a92269bbd3fa0641193de24bc05c5b712c02cb11ea2ad85ee292475
6
+ metadata.gz: be7c1e511e804253ca000b2f2a2850b80a891251dc83ebade648956eb7ca6e7589fa8ffb4cdaed29fc4b3bee3f8300b2afc6d829540b21980e51a3677ff472b0
7
+ data.tar.gz: af7dca756e367a4da419977f5f402a3ec3c5acfa5c77f26cb44eafa7c5ae90fce14d08276db66a12ab02ee48d630ae3229cb9eb0f117d40b32b350abc1a392ea
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # CompaniesHouse::Client
2
2
 
3
- [![CircleCI](https://circleci.com/gh/gocardless/companies-house-rest.svg?style=svg)](https://circleci.com/gh/gocardless/companies-house-rest)
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,16 +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
 
118
+ ### .filing_history_list
119
+
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.
121
+
122
+ ### .filing_history_item
123
+
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
125
+ [filingHistoryItem](https://developer.companieshouse.gov.uk/api/docs/company/company_number/filing-history/filingHistoryItem-resource.html) resource.
126
+
113
127
  ### Other API Methods
128
+
114
129
  While there are other resources exposed by the
115
130
  [Companies House API](https://developer.companieshouse.gov.uk/api/docs/index.html),
116
131
  this gem does not implement access to these resources at this time.
117
132
 
118
133
  ## Error Handling
134
+
119
135
  If a request to the Companies House API encounters an HTTP status other than
120
136
  `200 OK`, it will raise an instance of `CompaniesHouse::APIError` instead of
121
137
  returning response data. The error will have the following fields:
@@ -125,7 +141,6 @@ returning response data. The error will have the following fields:
125
141
  | `response` | The Net::HTTP response object from the failed API call. |
126
142
  | `status` | A string containing the response status code. |
127
143
 
128
-
129
144
  Certain API responses will raise an instance of a more specific subclass of
130
145
  `CompaniesHouse::APIError`:
131
146
 
@@ -151,7 +166,6 @@ To get started:
151
166
  bundle install --path vendor
152
167
  ```
153
168
 
154
-
155
169
  To run all tests and Rubocop:
156
170
 
157
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 = ">= 2.5.5"
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", "~> 2.4"
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
- @connection.finish if @connection&.started?
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(:company, "company/#{id}", {}, make_transaction_id, id)
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,24 +60,67 @@ 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
+
72
+ def filing_history_list(id)
73
+ get_all_pages(:filing_history_list, "company/#{id}/filing-history", id)
74
+ end
75
+
76
+ def filing_history_item(id, transaction_id)
77
+ request(
78
+ resource: :filing_history_item,
79
+ path: "company/#{id}/filing-history/#{transaction_id}",
80
+ )
81
+ end
82
+
50
83
  def company_search(query, items_per_page: nil, start_index: nil)
51
84
  request(
52
- :company_search,
53
- "search/companies",
54
- { q: query, items_per_page: items_per_page, start_index: start_index }.compact,
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,
55
90
  )
56
91
  end
57
92
 
58
93
  def connection
59
- @connection ||= Net::HTTP.new(endpoint.host, endpoint.port).tap do |conn|
60
- conn.use_ssl = true
61
- conn.open_timeout = @open_timeout
62
- conn.read_timeout = @read_timeout
63
- end
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
64
100
  end
65
101
 
66
102
  private
67
103
 
104
+ def request(resource:,
105
+ path:,
106
+ params: {},
107
+ transaction_id: make_transaction_id,
108
+ resource_id: nil,
109
+ headers: {})
110
+ Request.new(
111
+ connection: connection,
112
+ api_key: @api_key,
113
+ endpoint: @endpoint,
114
+ path: path,
115
+ query: params,
116
+ resource_type: resource,
117
+ resource_id: resource_id,
118
+ transaction_id: transaction_id,
119
+ instrumentation: instrumentation,
120
+ headers: headers,
121
+ ).execute
122
+ end
123
+
68
124
  # Fetch and combine all pages of a paginated API call
69
125
  def get_all_pages(resource, path, id, query = {})
70
126
  items = []
@@ -72,7 +128,13 @@ module CompaniesHouse
72
128
  xid = make_transaction_id
73
129
 
74
130
  loop do
75
- page = request(resource, path, query.merge(start_index: offset), xid, id)
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
+ )
76
138
  new_items = page["items"]
77
139
  total = page["total_results"] || new_items.count
78
140
 
@@ -89,24 +151,6 @@ module CompaniesHouse
89
151
  SecureRandom.hex(10)
90
152
  end
91
153
 
92
- def request(resource,
93
- path,
94
- params = {},
95
- transaction_id = make_transaction_id,
96
- resource_id = nil)
97
- Request.new(
98
- connection: connection,
99
- api_key: @api_key,
100
- endpoint: @endpoint,
101
- path: path,
102
- query: params,
103
- resource_type: resource,
104
- resource_id: resource_id,
105
- transaction_id: transaction_id,
106
- instrumentation: instrumentation,
107
- ).execute
108
- end
109
-
110
154
  def configure_instrumentation(instrumentation)
111
155
  return instrumentation unless instrumentation.nil?
112
156
 
@@ -25,6 +25,7 @@ module CompaniesHouse
25
25
  # Physical request attributes
26
26
  attribute :path, Dry.Types::String
27
27
  attribute :query, Dry.Types::Hash
28
+ attribute :headers, Dry.Types::Hash
28
29
 
29
30
  # Logical request attributes
30
31
  attribute :resource_type, Dry.Types::Symbol
@@ -86,6 +87,7 @@ module CompaniesHouse
86
87
  case response.code
87
88
  when "200"
88
89
  JSON[response.body]
90
+ when "302" then { location: response["location"] }
89
91
  when "401"
90
92
  raise CompaniesHouse::AuthenticationError, response
91
93
  when "404"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CompaniesHouse
4
- VERSION = "0.5.0"
4
+ VERSION = "1.0.0"
5
5
  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.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GoCardless Engineering
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-04 00:00:00.000000000 Z
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: '2.4'
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: '2.4'
60
+ version: '3.6'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rake
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -154,8 +154,9 @@ files:
154
154
  homepage: https://github.com/gocardless/companies-house-rest
155
155
  licenses:
156
156
  - MIT
157
- metadata: {}
158
- post_install_message:
157
+ metadata:
158
+ rubygems_mfa_required: 'true'
159
+ post_install_message:
159
160
  rdoc_options: []
160
161
  require_paths:
161
162
  - lib
@@ -163,15 +164,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
164
  requirements:
164
165
  - - ">="
165
166
  - !ruby/object:Gem::Version
166
- version: 2.5.5
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.0.6
174
- signing_key:
174
+ rubygems_version: 3.3.7
175
+ signing_key:
175
176
  specification_version: 4
176
177
  summary: Look up UK company registration information
177
178
  test_files: []