Class: DefraRuby::CompaniesHouse::API
- Inherits:
-
Object
- Object
- DefraRuby::CompaniesHouse::API
- Defined in:
- lib/defra_ruby/companies_house/api.rb
Overview
The API class is responsible for making requests to the Companies House API. It handles the construction of request URLs, headers, and payload, and also deals with any errors that occur during the API request.
Instance Attribute Summary collapse
-
#company_number ⇒ Object
Returns the value of attribute company_number.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#company_number ⇒ Object
Returns the value of attribute company_number.
48 49 50 |
# File 'lib/defra_ruby/companies_house/api.rb', line 48 def company_number @company_number end |
Class Method Details
.run(company_number:) ⇒ Object
50 51 52 |
# File 'lib/defra_ruby/companies_house/api.rb', line 50 def self.run(company_number:) new.run(company_number:) end |
Instance Method Details
#run(company_number:) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/defra_ruby/companies_house/api.rb', line 54 def run(company_number:) @company_number = format_company_number(company_number) validate_company_number companies_house_details rescue InvalidCompanyNumberError # just re-raise - this is to prevent the StandardError rescue logging it again raise rescue RestClient::Exceptions::Timeout => e log_error(e) raise DefraRuby::CompaniesHouse::ApiTimeoutError rescue RestClient::ResourceNotFound, RestClient::NotFound => e log_error(e) raise DefraRuby::CompaniesHouse::CompanyNotFoundError, company_number rescue StandardError => e log_error(e) raise e end |