Class: Jigsaw::ContactSearch

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json_object) ⇒ ContactSearch

Returns a new instance of ContactSearch.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jigsaw/contact_search.rb', line 9

def initialize(json_object)
    @zip              = json_object['zip']
    @phone            = json_object['phone']  
    @areaCode         = json_object['areaCode']
    @updatedDate      = json_object['updatedDate']
    @seoContactURL    = json_object['seoContactUR']
    @state            = json_object['state']
    @lastname         = json_object['lastname']
    @firstname        = json_object['firstname']
    @companyName      = json_object['companyName']
    @contactURL       = json_object['contactURL']
    @contactSales     = json_object['contactSales']
    @country          = json_object['country']
    @owned            = json_object['owned']
    @city             = json_object['city']
    @title            = json_object['title']
    @contactId        = json_object['contactId']
    @email            = json_object['email']   
    @address          = json_object['address']
    @graveyardStatus  = json_object['graveyardStatus']
    @ownedType        = json_object['ownedType']
    @companyId        = json_object['companyId']
end

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#areaCodeObject

Returns the value of attribute areaCode.



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

def areaCode
  @areaCode
end

#cityObject

Returns the value of attribute city.



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

def city
  @city
end

#companyIdObject

Returns the value of attribute companyId.



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

def companyId
  @companyId
end

#companyNameObject

Returns the value of attribute companyName.



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

def companyName
  @companyName
end

#contactIdObject

Returns the value of attribute contactId.



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

def contactId
  @contactId
end

#contactSalesObject

Returns the value of attribute contactSales.



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

def contactSales
  @contactSales
end

#contactURLObject

Returns the value of attribute contactURL.



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

def contactURL
  @contactURL
end

#countryObject

Returns the value of attribute country.



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

def country
  @country
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#firstnameObject

Returns the value of attribute firstname.



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

def firstname
  @firstname
end

#graveyardStatusObject

Returns the value of attribute graveyardStatus.



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

def graveyardStatus
  @graveyardStatus
end

#lastnameObject

Returns the value of attribute lastname.



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

def lastname
  @lastname
end

#ownedObject

Returns the value of attribute owned.



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

def owned
  @owned
end

#ownedTypeObject

Returns the value of attribute ownedType.



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

def ownedType
  @ownedType
end

#phoneObject

Returns the value of attribute phone.



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

def phone
  @phone
end

#seoContactURLObject

Returns the value of attribute seoContactURL.



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

def seoContactURL
  @seoContactURL
end

#stateObject

Returns the value of attribute state.



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

def state
  @state
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#updatedDateObject

Returns the value of attribute updatedDate.



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

def updatedDate
  @updatedDate
end

#zipObject

Returns the value of attribute zip.



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

def zip
  @zip
end

Class Method Details

.list(api_key, options, fetch_all = false) ⇒ Object



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
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/jigsaw/contact_search.rb', line 34

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
  contacts = []
  total_hits = nil
  fetched_hits = 0
  offset = options[:offset]

  begin

    response = Request.search_contact(camelized_options)

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

    contacts << response['contacts'].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 contacts
  [total_hits, fetched_hits, contacts.flatten]

end