-
Notifications
You must be signed in to change notification settings - Fork 8
/
examples.rb
79 lines (60 loc) · 2.26 KB
/
examples.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# NOTE: CapsuleCRM::Person and CapsuleCRM::Organisation have virtually identically methods.
# find by id
person = CapsuleCRM::Person.find 123
# or if you don't know what you are searching for Party
something = CapsuleCRM::Party.find 123
something.is?(:person)
something.is?(:organisation)
# find by email
person = CapsuleCRM::Person.find_by_email 'foo@example.com'
# find all
person = CapsuleCRM::Person.find :all, :offset => 10, :limit => 5
# find by search term (searches name, telephone number and searchable custom fields)
person = CapsuleCRM::Person.search 'fred', :offset => 10, :limit => 5
# CapsuleCRM::Person attributes
person.id
person.title
person.first_name
person.last_name
person.job_title
person.about
# update a person object
person.first_name = "Homer"
person.last_name = "Simpson"
person.save # returns true/false
# create a person object
person = CapsuleCRM::Person.new
person.first_name = "Marge"
person.last_name = "Simpson"
person.save # returns true/false
# get the person's organisation
person.organisation # CapsuleCRM::Organisation
# CapsuleCRM::Organisation attributes:
organisation.about
organisation.name
# Contacts: CapsuleCRM::Phone (read-only)
person.phone_numbers # CapsuleCRM::Collection
person.phone_numbers.first.number # 01234 56789
person.phone_numbers.first.type # work
# Contacts: CapsuleCRM::Website (read-only)
party.websites # CapsuleCRM::Collection
party.websites.first.url # http://google.com
party.websites.first.web_address # http://google.com
# Contacts: CapsuleCRM::Email (read-only)
person.emails # CapsuleCRM::Collection
person.emails.first.address # 'foo@example.com'
person.emails.first.type # 'home'
# Contacts: CapsuleCRM::Address (read-only)
person.addresses # CapsuleCRM::Collection
person.addresses.first.street # 10 Somestreet
person.addresses.first.city # Manchester
person.addresses.first.state # Greater Manchester
person.addresses.first.zip # ME10 7TR
person.addresses.first.country # United Kingdom
# CapsuleCRM::CustomFields (read-only)
person.custom_fields # CapsuleCRM::Collection
person.custom_fields.first.label # 'Favourite colour'
person.custom_fields.first.value # 'Blue'
# CapsuleCRM::Tag (read-only)
person.tags # CapsuleCRM::Collection
person.tag_names # ["array", "of all", "tags", "as strings"]