Class: Jigsaw::CompanySearch
- Inherits:
-
Object
- Object
- Jigsaw::CompanySearch
- Defined in:
- lib/jigsaw/company_search.rb
Instance Attribute Summary collapse
-
#active_contacts ⇒ Object
Returns the value of attribute active_contacts.
-
#address ⇒ Object
Returns the value of attribute address.
-
#city ⇒ Object
Returns the value of attribute city.
-
#company_id ⇒ Object
Returns the value of attribute company_id.
-
#country ⇒ Object
Returns the value of attribute country.
-
#graveyarded ⇒ Object
Returns the value of attribute graveyarded.
-
#name ⇒ Object
Returns the value of attribute name.
-
#state ⇒ Object
Returns the value of attribute state.
-
#zip ⇒ Object
Returns the value of attribute zip.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(json_object) ⇒ CompanySearch
constructor
A new instance of CompanySearch.
Constructor Details
#initialize(json_object) ⇒ CompanySearch
Returns a new instance of CompanySearch.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/jigsaw/company_search.rb', line 9 def initialize(json_object) @company_id = json_object['companyId'] @name = json_object['name'] @address = json_object['address'] @city = json_object['city'] @state = json_object['state'] @zip = json_object['zip'] @country = json_object['country'] @active_contacts = json_object['activeContacts'] @graveyarded = json_object['graveyarded'] end |
Instance Attribute Details
#active_contacts ⇒ Object
Returns the value of attribute active_contacts.
7 8 9 |
# File 'lib/jigsaw/company_search.rb', line 7 def active_contacts @active_contacts end |
#address ⇒ Object
Returns the value of attribute address.
7 8 9 |
# File 'lib/jigsaw/company_search.rb', line 7 def address @address end |
#city ⇒ Object
Returns the value of attribute city.
7 8 9 |
# File 'lib/jigsaw/company_search.rb', line 7 def city @city end |
#company_id ⇒ Object
Returns the value of attribute company_id.
7 8 9 |
# File 'lib/jigsaw/company_search.rb', line 7 def company_id @company_id end |
#country ⇒ Object
Returns the value of attribute country.
7 8 9 |
# File 'lib/jigsaw/company_search.rb', line 7 def country @country end |
#graveyarded ⇒ Object
Returns the value of attribute graveyarded.
7 8 9 |
# File 'lib/jigsaw/company_search.rb', line 7 def graveyarded @graveyarded end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/jigsaw/company_search.rb', line 7 def name @name end |
#state ⇒ Object
Returns the value of attribute state.
7 8 9 |
# File 'lib/jigsaw/company_search.rb', line 7 def state @state end |
#zip ⇒ Object
Returns the value of attribute zip.
7 8 9 |
# File 'lib/jigsaw/company_search.rb', line 7 def zip @zip end |
Class Method Details
.list(api_key, options, fetch_all = false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/jigsaw/company_search.rb', line 22 def self.list(api_key, , fetch_all=false) [:token] = api_key [:page_size] = [:page_size] || 50 # 50 is the default. [:offset] = [:offset] || 0 # 0 is the default. # Camelize options = {} .each do |key, value| [key.to_s.camelize(:lower)] = value end # Send one or more requests depending on the number of results, the # page size and the value of fetch_all companies = [] total_hits = nil fetched_hits = 0 offset = [:offset] begin response = Request.search_company() total_hits = response['totalHits'] fetched_hits += response['companies'].size companies << response['companies'].map do |result| self.new(result) end #Calculate the next offset. offset += [:page_size] [:offset] = offset end while fetch_all && (total_hits > offset) # Return the hits info and the list of companies [total_hits, fetched_hits, companies.flatten] end |