Sha256: 7891758d80172189b29762974e468d2af25874778ed6cf5f40898949fec80576

Contents?: true

Size: 1.22 KB

Versions: 14

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

require 'companies_house_hub/filing_history_formatter'

module CompaniesHouseHub
  class FilingHistory < BaseModel
    DOCUMENT_URL = 'https://beta.companieshouse.gov.uk'
    FIND_PATH = '/company/:company_number/filing-history'
    DEFAULT_PER_PAGE = 100

    attr_reader :description, :action_date, :date, :type, :barcode, :links, :description_values

    def self.all(options = {})
      options[:items_per_page] ||= DEFAULT_PER_PAGE

      number = options.delete(:company_number)

      result = get(format_url(FIND_PATH, company_number: number), options)

      result.body[:items].map { |filing_json| new(filing_json) }
    end

    def initialize(json = {})
      @description = json.dig(:description)
      @action_date = json.dig(:action_date)
      @date = json.dig(:date)
      @type = json.dig(:type)
      @barcode = json.dig(:barcode)
      @links = json.dig(:links)
      @description_values = json.dig(:description_values)
    end

    def formatted_name
      FilingHistoryFormatter.new(self).formatted
    end

    def url(format = 'pdf')
      file_path = @links[:self]

      document_path = "#{file_path}/document?format=#{format}"

      URI.join(DOCUMENT_URL, document_path).to_s
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
companies_house_hub-0.0.16 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.15 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.14 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.13 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.12 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.11 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.10 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.9 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.8 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.7 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.6 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.5 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.4 lib/companies_house_hub/models/filing_history.rb
companies_house_hub-0.0.3 lib/companies_house_hub/models/filing_history.rb