Skip to content
tylercunnion edited this page Feb 7, 2012 · 1 revision

The Crunchbase API provides a search function. When performing a search, the API returns 10 results at a time. The Search class loads results on demand, so when getting a search result at an index which has not been loaded yet, another HTTP request is made which loads the corresponding page of results and stores them.

To perform a search, use:

s = Crunchbase::Search.find("query")

You access the search results as if the Search object were an array:

s[0]
s.each {|result| puts result.name}

In addition, Search implements Enumerable. Note that it does not fully replicate Array, for example, s[0..4] or s[3, 5] is not yet implemented. If you need to interact with a traditional Array, you can use to_ary. This method will retrieve every result before returning the array

For any given search result, you can get the full object by using the entity method:

obj = s[0].entity

It's probably best to make sure you have the object you want before retrieving it; e.g., this is extremely slow for any non-trivial number of results:

results = s.map {|result| result.entity}
Clone this wiki locally