Class: Jigsaw::CompanyBasic

Inherits:
Object
  • Object
show all
Defined in:
lib/jigsaw/company_basic.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_object) ⇒ CompanyBasic

Returns a new instance of CompanyBasic.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jigsaw/company_basic.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_contactsObject

Returns the value of attribute active_contacts.



7
8
9
# File 'lib/jigsaw/company_basic.rb', line 7

def active_contacts
  @active_contacts
end

#addressObject

Returns the value of attribute address.



7
8
9
# File 'lib/jigsaw/company_basic.rb', line 7

def address
  @address
end

#cityObject

Returns the value of attribute city.



7
8
9
# File 'lib/jigsaw/company_basic.rb', line 7

def city
  @city
end

#company_idObject

Returns the value of attribute company_id.



7
8
9
# File 'lib/jigsaw/company_basic.rb', line 7

def company_id
  @company_id
end

#countryObject

Returns the value of attribute country.



7
8
9
# File 'lib/jigsaw/company_basic.rb', line 7

def country
  @country
end

#graveyardedObject

Returns the value of attribute graveyarded.



7
8
9
# File 'lib/jigsaw/company_basic.rb', line 7

def graveyarded
  @graveyarded
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/jigsaw/company_basic.rb', line 7

def name
  @name
end

#stateObject

Returns the value of attribute state.



7
8
9
# File 'lib/jigsaw/company_basic.rb', line 7

def state
  @state
end

#zipObject

Returns the value of attribute zip.



7
8
9
# File 'lib/jigsaw/company_basic.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_basic.rb', line 22

def self.list(api_key, options, fetch_all=false)

  options[:token]     = api_key
  options[:page_size] = options[:page_size] || 50 # 50 is the default.
  options[:offset]    = options[:offset] || 0 # 0 is the default.

  # Camelize options
  camelized_options = {}
  options.each do |key, value|
    camelized_options[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 = options[:offset]

  begin

    response = Request.search_company(camelized_options)

    total_hits = response['totalHits']
    fetched_hits += response['companies'].size

    companies << response['companies'].map do |result|
      self.new(result)
    end

    #Calculate the next offset.
    offset += options[:page_size]
    camelized_options[: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