Class: ChJsonApi::Company
- Inherits:
-
Object
- Object
- ChJsonApi::Company
- Defined in:
- lib/chjsonapi/company.rb
Overview
Subclass of CHJsonApi that handles requests about the Company
Class Method Summary collapse
- .filing_item(param_hash) ⇒ Object
- .filing_list(param_hash) ⇒ Object
- .officers(param_hash) ⇒ Object
- .profile(param_hash) ⇒ Object
- .registered_office(param_hash) ⇒ Object
- .validate_param_hash(param_hash, required, optional = []) ⇒ Object
Class Method Details
.filing_item(param_hash) ⇒ Object
21 22 23 24 |
# File 'lib/chjsonapi/company.rb', line 21 def self.filing_item(param_hash) req, _ = validate_param_hash param_hash, [:company_number, :transaction_id] ChJsonApi.api_call("company/#{req[:company_number]}/filing-history/#{req[:transaction_id]}", nil) end |
.filing_list(param_hash) ⇒ Object
26 27 28 29 |
# File 'lib/chjsonapi/company.rb', line 26 def self.filing_list(param_hash) req, opt = validate_param_hash param_hash, [:company_number], [:items_per_page,:start_index,:category] ChJsonApi.api_call("company/#{req[:company_number]}/filing-history", opt) end |
.officers(param_hash) ⇒ Object
16 17 18 19 |
# File 'lib/chjsonapi/company.rb', line 16 def self.officers(param_hash) req, opt = validate_param_hash param_hash, [:company_number], [:items_per_page,:start_index,:order_by] ChJsonApi.api_call("company/#{req[:company_number]}/officers", opt) end |
.profile(param_hash) ⇒ Object
6 7 8 9 |
# File 'lib/chjsonapi/company.rb', line 6 def self.profile(param_hash) req, _ = validate_param_hash param_hash, [:company_number] ChJsonApi.api_call("company/#{req[:company_number]}", nil) end |
.registered_office(param_hash) ⇒ Object
11 12 13 14 |
# File 'lib/chjsonapi/company.rb', line 11 def self.registered_office(param_hash) req, _ = validate_param_hash param_hash, [:company_number] ChJsonApi.api_call("company/#{req[:company_number]}/registered-office-address", nil) end |
.validate_param_hash(param_hash, required, optional = []) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/chjsonapi/company.rb', line 33 def self.validate_param_hash(param_hash, required, optional=[]) if param_hash.kind_of? Hash required_fields = {} optional_fields = [] param_hash.each do |key, value| valid_value = value.to_s.scan(/[^0-9a-zA-Z_\-=,]/).empty? if (required.include? key) && valid_value required_fields[key] = value required.delete key elsif (optional.include? key) && valid_value optional_fields << "#{key}=#{value}" optional.delete key end end raise "Required fields not provided: #{required.to_s}" unless required.empty? [required_fields, optional_fields] end end |