Class: AdvisorsCommandClient::Models::ContactCollection

Inherits:
Object
  • Object
show all
Defined in:
lib/advisors_command_client/models/contact_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ ContactCollection

Returns a new instance of ContactCollection.



4
5
6
# File 'lib/advisors_command_client/models/contact_collection.rb', line 4

def initialize(args = {})
  @connection = args[:connection]
end

Instance Method Details

#find(contact_id) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/advisors_command_client/models/contact_collection.rb', line 25

def find(contact_id)
  resp = @connection.get("contacts/#{contact_id}")
  if resp.success?
    return AdvisorsCommandClient::Models::Contact.load(resp.body, @connection)
  else
    return nil
  end
end

#search(query) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/advisors_command_client/models/contact_collection.rb', line 8

def search(query)
  response = @connection.get('search', {search: query, from: 'orocrm_contact'})
  if response.success?
    return Parallel.map(Array(response.body['data'])) do |obj|
      begin
        next unless obj['record_string'].present?
        self.find(obj['record_id'].to_i)
      rescue Faraday::Error::ParsingError
        puts "Error parsing response for contact ID: #{obj['record_id']}"
        next nil
      end
    end.compact
  else
    raise ::AdvisorsCommandClient::SearchError, "Error connecting to advisors command."
  end
end