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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 459ca3719258db949f31567bc66d0e69b1a7f2d156651cdd37601e9f6215aa6d
4
- data.tar.gz: 350813f829c850f146e9a3c490eaf7fb6fe6f890298314e9011617c6f80736c4
3
+ metadata.gz: 15368ba8f4030e66bbd7a356116063606bbe8ae0c3a58172fe27bcad307ea327
4
+ data.tar.gz: 30026ddb39dcbc297f3a41c13cdf54e36113341cd97a013a2b857f9b4f10769b
5
5
  SHA512:
6
- metadata.gz: 8ad3bf8ab66493eb57810a175282d220186dfd1e11c9b47fac103270bbfcb9f0d84fd8f1d2b38b81bb37a08bf92cdd3f1bda4eb32fadba367e466184fe2be201
7
- data.tar.gz: 1036d35e98f785ceb40479ca5b0096c161cc5fe2e6c6a477674fb7271dda2c827822a882cef8dd66ab119f4baa40a88d94f1d18f17fe12cd3fc1bc5e7cbf631a
6
+ metadata.gz: e6297b90251e9fba7eae29c2f571324c5e87c8c425810664433dc15e88fd6871fa21468703396fd7b6f6c42bcae54cead9fc5b5ccf36f352d3074f6d1980f05d
7
+ data.tar.gz: 177853a604528af01f3cb04ca8426d2a0911f5d17a04f98db70704890e0958eb22809cb15a0b6c799fa3133d5107c70d9a39e94fea355b2c4ee11e98a31dae7f
@@ -4,7 +4,7 @@ require 'faraday'
4
4
  require 'faraday_middleware'
5
5
  require 'companies_house_hub/configuration'
6
6
  require 'companies_house_hub/base_model'
7
-
7
+ require 'companies_house_hub/errors'
8
8
  require 'companies_house_hub/models/company'
9
9
 
10
10
  module CompaniesHouseHub
@@ -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)
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CompaniesHouseHub
4
+ class APIKeyError < StandardError
5
+ end
6
+
7
+ class GenericError < StandardError
8
+ end
9
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
-
4
+ # 02200605
5
5
  module CompaniesHouseHub
6
6
  class FilingHistoryFormatter
7
7
  def initialize(filing_history)
@@ -22,7 +22,16 @@ module CompaniesHouseHub
22
22
 
23
23
  result = get(SEARCH_PATH, options)
24
24
 
25
- result.body[:items].map { |company_json| new(company_json) }
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 unless result.success?
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].map { |filing_json| new(filing_json) }
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 = {})
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CompaniesHouseHub
4
- VERSION = '0.0.16'
4
+ VERSION = '0.1.0'
5
5
  end
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.16
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-04-30 00:00:00.000000000 Z
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