companies-house-rest 0.4.5 → 0.6.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 +7 -0
- data/companies-house-rest.gemspec +3 -3
- data/lib/companies_house/client.rb +31 -18
- data/lib/companies_house/instrumentation/active_support.rb +1 -1
- data/lib/companies_house/request.rb +24 -17
- data/lib/companies_house/version.rb +1 -1
- metadata +23 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52bdd785678f5c27983569bd6392900dc4f26f939e1f228ed6c955b1146d32ff
|
4
|
+
data.tar.gz: ad9d77152c5c44548c2c43f5f398be1aa3fd85d3eef8947917667fd16164fc72
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b38b76b8e985cbd5dd9e2e0da8812a504d88bcb0c26a84276a923778fda5fb3cce6b2401afd49b0cfa58ab1e15d17aa82d5636362fd6e5b6ff1d1bd5fa4524b9
|
7
|
+
data.tar.gz: c1cf8db5f63af5ced3d1bf9809730d7a833b3453bb7f7bf7231654c00d71efda8bf1cacd1333def031b1239047eca14bbf5d553c8e35167688aedbb9f0cf9f19
|
data/README.md
CHANGED
@@ -110,6 +110,13 @@ This method implements the [searchCompanies](https://developer.companieshouse.go
|
|
110
110
|
API and returns the list of [companySearch](https://developer.companieshouse.gov.uk/api/docs/search-overview/CompanySearch-resource.html)
|
111
111
|
resources that match the given query. The `items_per_page` and `start_index` parameters are optional.
|
112
112
|
|
113
|
+
### .filing_history_list
|
114
|
+
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
|
+
|
116
|
+
### .filing_history_item
|
117
|
+
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
|
+
[filingHistoryItem](https://developer.companieshouse.gov.uk/api/docs/company/company_number/filing-history/filingHistoryItem-resource.html) resource.
|
119
|
+
|
113
120
|
### Other API Methods
|
114
121
|
While there are other resources exposed by the
|
115
122
|
[Companies House API](https://developer.companieshouse.gov.uk/api/docs/index.html),
|
@@ -22,11 +22,11 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
spec.required_ruby_version = ">= 2.5.5"
|
24
24
|
|
25
|
-
spec.add_runtime_dependency "
|
26
|
-
spec.add_runtime_dependency "virtus", "~> 1.0", ">= 1.0.5"
|
25
|
+
spec.add_runtime_dependency "dry-struct", "~> 1"
|
27
26
|
|
27
|
+
spec.add_development_dependency "activesupport", ">= 4.2", "< 7"
|
28
28
|
spec.add_development_dependency "gc_ruboconfig", "~> 2.4"
|
29
|
-
spec.add_development_dependency "rake", "~>
|
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"
|
@@ -47,6 +47,17 @@ module CompaniesHouse
|
|
47
47
|
)
|
48
48
|
end
|
49
49
|
|
50
|
+
def filing_history_list(id)
|
51
|
+
get_all_pages(:filing_history_list, "company/#{id}/filing-history", id)
|
52
|
+
end
|
53
|
+
|
54
|
+
def filing_history_item(id, transaction_id)
|
55
|
+
request(
|
56
|
+
:filing_history_item,
|
57
|
+
"company/#{id}/filing-history/#{transaction_id}",
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
50
61
|
def company_search(query, items_per_page: nil, start_index: nil)
|
51
62
|
request(
|
52
63
|
:company_search,
|
@@ -63,6 +74,26 @@ module CompaniesHouse
|
|
63
74
|
end
|
64
75
|
end
|
65
76
|
|
77
|
+
def request(resource,
|
78
|
+
path,
|
79
|
+
params = {},
|
80
|
+
transaction_id = make_transaction_id,
|
81
|
+
resource_id = nil,
|
82
|
+
headers = {})
|
83
|
+
Request.new(
|
84
|
+
connection: connection,
|
85
|
+
api_key: @api_key,
|
86
|
+
endpoint: @endpoint,
|
87
|
+
path: path,
|
88
|
+
query: params,
|
89
|
+
resource_type: resource,
|
90
|
+
resource_id: resource_id,
|
91
|
+
transaction_id: transaction_id,
|
92
|
+
instrumentation: instrumentation,
|
93
|
+
headers: headers,
|
94
|
+
).execute
|
95
|
+
end
|
96
|
+
|
66
97
|
private
|
67
98
|
|
68
99
|
# Fetch and combine all pages of a paginated API call
|
@@ -89,24 +120,6 @@ module CompaniesHouse
|
|
89
120
|
SecureRandom.hex(10)
|
90
121
|
end
|
91
122
|
|
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
123
|
def configure_instrumentation(instrumentation)
|
111
124
|
return instrumentation unless instrumentation.nil?
|
112
125
|
|
@@ -7,31 +7,32 @@ require "companies_house/rate_limit_error"
|
|
7
7
|
require "companies_house/timeout_error"
|
8
8
|
require "companies_house/bad_gateway_error"
|
9
9
|
|
10
|
-
require "
|
10
|
+
require "net/http"
|
11
11
|
require "uri"
|
12
12
|
require "json"
|
13
|
+
require "dry-struct"
|
13
14
|
|
14
15
|
module CompaniesHouse
|
15
16
|
# This class manages individual requests.
|
16
17
|
# Users of the CompaniesHouse gem should not instantiate this class
|
17
18
|
# and should instead use CompaniesHouse::Client.
|
18
|
-
class Request
|
19
|
-
include Virtus.model
|
19
|
+
class Request < Dry::Struct
|
20
20
|
# API-level attributes
|
21
|
-
attribute :connection, Net::HTTP
|
22
|
-
attribute :api_key, String
|
23
|
-
attribute :endpoint, URI
|
21
|
+
attribute :connection, Dry.Types.Instance(Net::HTTP)
|
22
|
+
attribute :api_key, Dry.Types::String
|
23
|
+
attribute :endpoint, Dry.Types.Instance(URI)
|
24
24
|
|
25
25
|
# Physical request attributes
|
26
|
-
attribute :path, String
|
27
|
-
attribute :query, Hash
|
26
|
+
attribute :path, Dry.Types::String
|
27
|
+
attribute :query, Dry.Types::Hash
|
28
|
+
attribute :headers, Dry.Types::Hash
|
28
29
|
|
29
30
|
# Logical request attributes
|
30
|
-
attribute :resource_type, Symbol
|
31
|
-
attribute :resource_id,
|
31
|
+
attribute :resource_type, Dry.Types::Symbol
|
32
|
+
attribute :resource_id, Dry.Types.Nominal(Integer)
|
32
33
|
|
33
|
-
attribute :transaction_id, String
|
34
|
-
attribute :instrumentation
|
34
|
+
attribute :transaction_id, Dry.Types::String
|
35
|
+
attribute :instrumentation, Dry.Types.Interface(:publish)
|
35
36
|
|
36
37
|
def initialize(args)
|
37
38
|
super(args)
|
@@ -48,11 +49,7 @@ module CompaniesHouse
|
|
48
49
|
|
49
50
|
def execute
|
50
51
|
@started = Time.now.utc
|
51
|
-
|
52
|
-
req = Net::HTTP::Get.new(@uri)
|
53
|
-
req.basic_auth @api_key, ""
|
54
|
-
|
55
|
-
response = connection.request req
|
52
|
+
response = request_resource(@uri)
|
56
53
|
@notification_payload[:status] = response.code
|
57
54
|
|
58
55
|
begin
|
@@ -69,6 +66,13 @@ module CompaniesHouse
|
|
69
66
|
|
70
67
|
private
|
71
68
|
|
69
|
+
def request_resource(uri)
|
70
|
+
req = Net::HTTP::Get.new(uri)
|
71
|
+
req.basic_auth api_key, ""
|
72
|
+
|
73
|
+
connection.request req
|
74
|
+
end
|
75
|
+
|
72
76
|
def publish_notification
|
73
77
|
instrumentation.publish(
|
74
78
|
"companies_house.#{resource_type}",
|
@@ -79,10 +83,12 @@ module CompaniesHouse
|
|
79
83
|
)
|
80
84
|
end
|
81
85
|
|
86
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
82
87
|
def parse(response, resource_type, resource_id)
|
83
88
|
case response.code
|
84
89
|
when "200"
|
85
90
|
JSON[response.body]
|
91
|
+
when "302" then { 'location': response["location"] }
|
86
92
|
when "401"
|
87
93
|
raise CompaniesHouse::AuthenticationError, response
|
88
94
|
when "404"
|
@@ -95,5 +101,6 @@ module CompaniesHouse
|
|
95
101
|
raise CompaniesHouse::APIError.new("Unknown API response", response)
|
96
102
|
end
|
97
103
|
end
|
104
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
98
105
|
end
|
99
106
|
end
|
metadata
CHANGED
@@ -1,55 +1,49 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: companies-house-rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.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:
|
11
|
+
date: 2020-06-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: dry-struct
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '4.2'
|
20
|
-
- - "<"
|
17
|
+
- - "~>"
|
21
18
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
19
|
+
version: '1'
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: '4.2'
|
30
|
-
- - "<"
|
24
|
+
- - "~>"
|
31
25
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
26
|
+
version: '1'
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
|
-
name:
|
28
|
+
name: activesupport
|
35
29
|
requirement: !ruby/object:Gem::Requirement
|
36
30
|
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '1.0'
|
40
31
|
- - ">="
|
41
32
|
- !ruby/object:Gem::Version
|
42
|
-
version:
|
43
|
-
|
33
|
+
version: '4.2'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '7'
|
37
|
+
type: :development
|
44
38
|
prerelease: false
|
45
39
|
version_requirements: !ruby/object:Gem::Requirement
|
46
40
|
requirements:
|
47
|
-
- - "~>"
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: '1.0'
|
50
41
|
- - ">="
|
51
42
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
43
|
+
version: '4.2'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '7'
|
53
47
|
- !ruby/object:Gem::Dependency
|
54
48
|
name: gc_ruboconfig
|
55
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -70,14 +64,14 @@ dependencies:
|
|
70
64
|
requirements:
|
71
65
|
- - "~>"
|
72
66
|
- !ruby/object:Gem::Version
|
73
|
-
version: '
|
67
|
+
version: '13.0'
|
74
68
|
type: :development
|
75
69
|
prerelease: false
|
76
70
|
version_requirements: !ruby/object:Gem::Requirement
|
77
71
|
requirements:
|
78
72
|
- - "~>"
|
79
73
|
- !ruby/object:Gem::Version
|
80
|
-
version: '
|
74
|
+
version: '13.0'
|
81
75
|
- !ruby/object:Gem::Dependency
|
82
76
|
name: rspec
|
83
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,7 +155,7 @@ homepage: https://github.com/gocardless/companies-house-rest
|
|
161
155
|
licenses:
|
162
156
|
- MIT
|
163
157
|
metadata: {}
|
164
|
-
post_install_message:
|
158
|
+
post_install_message:
|
165
159
|
rdoc_options: []
|
166
160
|
require_paths:
|
167
161
|
- lib
|
@@ -176,8 +170,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
170
|
- !ruby/object:Gem::Version
|
177
171
|
version: '0'
|
178
172
|
requirements: []
|
179
|
-
rubygems_version: 3.
|
180
|
-
signing_key:
|
173
|
+
rubygems_version: 3.1.3
|
174
|
+
signing_key:
|
181
175
|
specification_version: 4
|
182
176
|
summary: Look up UK company registration information
|
183
177
|
test_files: []
|