companies_house_hub 0.0.16 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/companies_house_hub.rb +1 -1
- data/lib/companies_house_hub/base_model.rb +7 -1
- data/lib/companies_house_hub/errors.rb +9 -0
- data/lib/companies_house_hub/filing_history_formatter.rb +1 -1
- data/lib/companies_house_hub/models/company.rb +11 -2
- data/lib/companies_house_hub/models/filing_history.rb +14 -1
- data/lib/companies_house_hub/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15368ba8f4030e66bbd7a356116063606bbe8ae0c3a58172fe27bcad307ea327
|
4
|
+
data.tar.gz: 30026ddb39dcbc297f3a41c13cdf54e36113341cd97a013a2b857f9b4f10769b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6297b90251e9fba7eae29c2f571324c5e87c8c425810664433dc15e88fd6871fa21468703396fd7b6f6c42bcae54cead9fc5b5ccf36f352d3074f6d1980f05d
|
7
|
+
data.tar.gz: 177853a604528af01f3cb04ca8426d2a0911f5d17a04f98db70704890e0958eb22809cb15a0b6c799fa3133d5107c70d9a39e94fea355b2c4ee11e98a31dae7f
|
data/lib/companies_house_hub.rb
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'companies_house_hub/errors'
|
4
|
+
|
3
5
|
module CompaniesHouseHub
|
4
6
|
class BaseModel
|
5
7
|
def self.get(path, params)
|
6
|
-
CompaniesHouseHub.connection.get(path, params)
|
8
|
+
result = CompaniesHouseHub.connection.get(path, params)
|
9
|
+
|
10
|
+
raise APIKeyError, result.body[:error] if result.status == 401
|
11
|
+
|
12
|
+
result
|
7
13
|
end
|
8
14
|
|
9
15
|
def get(path, params)
|
@@ -22,7 +22,16 @@ module CompaniesHouseHub
|
|
22
22
|
|
23
23
|
result = get(SEARCH_PATH, options)
|
24
24
|
|
25
|
-
|
25
|
+
return [] unless result.success?
|
26
|
+
|
27
|
+
# Get all items and create a new company. If the company has no number we need to ignore it.
|
28
|
+
companies = result.body[:items].map do |company_json|
|
29
|
+
next unless company_json.dig(:company_number)
|
30
|
+
|
31
|
+
new(company_json)
|
32
|
+
end
|
33
|
+
|
34
|
+
companies.compact
|
26
35
|
end
|
27
36
|
|
28
37
|
def self.find(company_number, params = {})
|
@@ -30,7 +39,7 @@ module CompaniesHouseHub
|
|
30
39
|
|
31
40
|
result = get(url, params)
|
32
41
|
|
33
|
-
return
|
42
|
+
return if result.status == 404
|
34
43
|
|
35
44
|
new(result.body)
|
36
45
|
end
|
@@ -7,9 +7,12 @@ module CompaniesHouseHub
|
|
7
7
|
DOCUMENT_URL = 'https://beta.companieshouse.gov.uk'
|
8
8
|
FIND_PATH = '/company/:company_number/filing-history'
|
9
9
|
DEFAULT_PER_PAGE = 100
|
10
|
+
LEGACY_DOC_DESCRIPTION = 'legacy'
|
10
11
|
|
11
12
|
attr_reader :description, :action_date, :date, :type, :barcode, :links, :description_values
|
12
13
|
|
14
|
+
alias name description
|
15
|
+
|
13
16
|
def self.all(options = {})
|
14
17
|
options[:items_per_page] ||= DEFAULT_PER_PAGE
|
15
18
|
|
@@ -17,7 +20,17 @@ module CompaniesHouseHub
|
|
17
20
|
|
18
21
|
result = get(format_url(FIND_PATH, company_number: number), options)
|
19
22
|
|
20
|
-
result.body[:items].
|
23
|
+
return [] unless result.body[:items].any?
|
24
|
+
|
25
|
+
# Get all items and create a new history. If the description is 'legacy' then we can safely
|
26
|
+
# ignore that document.
|
27
|
+
filing_histories = result.body[:items].map do |filing_json|
|
28
|
+
next if filing_json.dig(:description) == LEGACY_DOC_DESCRIPTION
|
29
|
+
|
30
|
+
new(filing_json)
|
31
|
+
end
|
32
|
+
|
33
|
+
filing_histories.compact
|
21
34
|
end
|
22
35
|
|
23
36
|
def initialize(json = {})
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: companies_house_hub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ricardo Otero
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -198,6 +198,7 @@ files:
|
|
198
198
|
- lib/companies_house_hub.rb
|
199
199
|
- lib/companies_house_hub/base_model.rb
|
200
200
|
- lib/companies_house_hub/configuration.rb
|
201
|
+
- lib/companies_house_hub/errors.rb
|
201
202
|
- lib/companies_house_hub/filing_history_formatter.rb
|
202
203
|
- lib/companies_house_hub/models/address.rb
|
203
204
|
- lib/companies_house_hub/models/company.rb
|