Class: CapsuleCRM::Party

Inherits:
Base
  • Object
show all
Includes:
History
Defined in:
lib/capsulecrm/party.rb

Direct Known Subclasses

Organisation, Person

Instance Attribute Summary

Attributes inherited from Base

#id, #raw_data

Class Method Summary collapse

Instance Method Summary collapse

Methods included from History

#add_history, #history, #history!

Methods inherited from Base

#==, #errors, find, #initialize, last_response, #new_record?

Constructor Details

This class inherits a constructor from CapsuleCRM::Base

Class Method Details

.find_all_by_email(email, options = {}) ⇒ Object



91
92
93
94
# File 'lib/capsulecrm/party.rb', line 91

def self.find_all_by_email(email, options={})
  options[:email] = email
  find_all(options)
end

.find_by_email(email) ⇒ Object

nodoc



98
99
100
# File 'lib/capsulecrm/party.rb', line 98

def self.find_by_email(email)
  find_all_by_email(email, :limit => 1, :offset => 0).first
end

.get_pathObject

nodoc



86
87
88
# File 'lib/capsulecrm/party.rb', line 86

def self.get_path
  '/api/party'
end

.init_one(response) ⇒ Object



109
110
111
112
113
# File 'lib/capsulecrm/party.rb', line 109

def self.init_one(response)
  return CapsuleCRM::Person.init_one(response) if response['person']
  return CapsuleCRM::Organisation.init_one(response) if response['organisation']
  raise CapsuleCRM::RecordNotRecognised, "Could not recognise returned entity type: #{response}"
end

.search(query, options = {}) ⇒ Object

nodoc



104
105
106
107
# File 'lib/capsulecrm/party.rb', line 104

def self.search(query, options={})
  options[:q] = query
  find_all(options)
end

Instance Method Details

#addressesObject

nodoc



5
6
7
8
9
# File 'lib/capsulecrm/party.rb', line 5

def addresses
  return @addresses if @addresses
  data = raw_data['contacts'].try(:[], 'address')
  @addresses = CapsuleCRM::Address.init_many(self, data)
end

#custom_fieldsObject

nodoc



13
14
15
16
17
18
19
20
# File 'lib/capsulecrm/party.rb', line 13

def custom_fields
  return @custom_fields if @custom_fields
  path = self.class.get_path
  path = [path, '/', id, '/customfield'].join
  last_response = self.class.get(path)
  data = last_response['customFields'].try(:[], 'customField')
  @custom_fields = CapsuleCRM::CustomField.init_many(self, data)
end

#emailsObject

nodoc



36
37
38
39
40
# File 'lib/capsulecrm/party.rb', line 36

def emails
  return @emails if @emails
  data = raw_data['contacts'].try(:[], 'email')
  @emails = CapsuleCRM::Email.init_many(self, data)
end

#is?(kind) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
60
# File 'lib/capsulecrm/party.rb', line 57

def is?(kind)
  required_class = kind.to_s.camelize
  self.class.to_s.include? required_class
end

#phone_numbersObject

nodoc



44
45
46
47
48
# File 'lib/capsulecrm/party.rb', line 44

def phone_numbers
  return @phone_numbers if @phone_numbers
  data = raw_data['contacts'].try(:[], 'phone')
  @phone_numbers = CapsuleCRM::Phone.init_many(self, data)
end

#tag(value) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/capsulecrm/party.rb', line 62

def tag(value)
  # unset tags so that if anyone were to request tags again, it
  # requests an update from the server.
  @tags = nil
  path = self.class.get_path
  tag = URI.escape(value.to_s)
  path = [path, id, 'tag', tag].join('/')
  req = self.class.post(path)
  req.response.code == ("201" || "200")
end

#tag_namesObject



31
32
33
# File 'lib/capsulecrm/party.rb', line 31

def tag_names
  tags.map(&:name)
end

#tagsObject



22
23
24
25
26
27
28
29
# File 'lib/capsulecrm/party.rb', line 22

def tags
  return @tags if @tags
  path = self.class.get_path
  path = [path, '/', id, '/tag'].join
  last_response = self.class.get(path)
  data = last_response['tags'].try(:[], 'tag')
  @tags = CapsuleCRM::Tag.init_many(self, data)
end

#untag(value) ⇒ Object



74
75
76
77
78
79
80
81
82
83
# File 'lib/capsulecrm/party.rb', line 74

def untag(value)
  # unset tags so that if anyone were to request tags again, it
  # requests an update from the server.
  @tags = nil
  path = self.class.get_path
  tag = URI.escape(value.to_s)
  path = [path, id, 'tag', tag].join('/')
  req = self.class.delete(path)
  req.response.code == "200"
end

#websitesObject

nodoc



51
52
53
54
55
# File 'lib/capsulecrm/party.rb', line 51

def websites
  return @websites if @websites
  data = raw_data['contacts'].try(:[], 'website')
  @websites = CapsuleCRM::Website.init_many(self, data)
end