Class: CompaniesHouse::Search
- Defined in:
- lib/companies_house/search.rb
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize ⇒ Search
constructor
request = CompaniesHouse::Search.new.
-
#search_companies(q = "captured sparks", items_per_page = "50", start_index = "0") ⇒ Object
search_companies developer.companieshouse.gov.uk/api/docs/search/companies/companysearch.html response = request.search_companies(query_string,items_per_page,start_index) query_string is a string to be searched for items_per_page is a string setting how many items to return per page start_index is a string representing the index of the first result item to return response.companies_count returns the number of companies found for the given query string response.companies returns an array of OpenStruct objects representing the company information found for the given query string.
Constructor Details
#initialize ⇒ Search
request = CompaniesHouse::Search.new
7 8 9 |
# File 'lib/companies_house/search.rb', line 7 def initialize super end |
Instance Method Details
#search_companies(q = "captured sparks", items_per_page = "50", start_index = "0") ⇒ Object
search_companies developer.companieshouse.gov.uk/api/docs/search/companies/companysearch.html response = request.search_companies(query_string,items_per_page,start_index) query_string is a string to be searched for items_per_page is a string setting how many items to return per page start_index is a string representing the index of the first result item to return response.companies_count returns the number of companies found for the given query string response.companies returns an array of OpenStruct objects representing the company information found for the given query string
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/companies_house/search.rb', line 20 def search_companies(q="captured sparks",items_per_page="50",start_index="0") # GET /search/companies query_string = "?q=#{q}&items_per_page=#{items_per_page}" unless start_index.nil? query_string << "&start_index=#{start_index}" end url = "search/companies#{query_string}" response = @@conn.get(url) result = JSON.parse(response.body, object_class: OpenStruct) return OpenStruct.new({companies_count: result.items.count, companies: result.items}) end |