Class: Sellsy::Contact
- Inherits:
-
Object
- Object
- Sellsy::Contact
- Defined in:
- lib/sellsy/contact.rb
Instance Attribute Summary collapse
-
#birth_date ⇒ Object
Returns the value of attribute birth_date.
-
#email ⇒ Object
Returns the value of attribute email.
-
#fax ⇒ Object
Returns the value of attribute fax.
-
#first_name ⇒ Object
Returns the value of attribute first_name.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_name ⇒ Object
Returns the value of attribute last_name.
-
#linked_id ⇒ Object
Returns the value of attribute linked_id.
-
#linked_type ⇒ Object
Returns the value of attribute linked_type.
-
#mobile ⇒ Object
Returns the value of attribute mobile.
-
#name ⇒ Object
Returns the value of attribute name.
-
#role ⇒ Object
Returns the value of attribute role.
-
#telephone ⇒ Object
Returns the value of attribute telephone.
-
#third_ids ⇒ Object
Returns the value of attribute third_ids.
-
#title ⇒ Object
Returns the value of attribute title.
-
#website ⇒ Object
Returns the value of attribute website.
Class Method Summary collapse
- .find(people_id) ⇒ Object
- .find_by_contact(contact_id) ⇒ Object
- .search(name, b_date = nil) ⇒ Object
Instance Method Summary collapse
Instance Attribute Details
#birth_date ⇒ Object
Returns the value of attribute birth_date.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def birth_date @birth_date end |
#email ⇒ Object
Returns the value of attribute email.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def email @email end |
#fax ⇒ Object
Returns the value of attribute fax.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def fax @fax end |
#first_name ⇒ Object
Returns the value of attribute first_name.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def first_name @first_name end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def id @id end |
#last_name ⇒ Object
Returns the value of attribute last_name.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def last_name @last_name end |
#linked_id ⇒ Object
Returns the value of attribute linked_id.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def linked_id @linked_id end |
#linked_type ⇒ Object
Returns the value of attribute linked_type.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def linked_type @linked_type end |
#mobile ⇒ Object
Returns the value of attribute mobile.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def mobile @mobile end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def name @name end |
#role ⇒ Object
Returns the value of attribute role.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def role @role end |
#telephone ⇒ Object
Returns the value of attribute telephone.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def telephone @telephone end |
#third_ids ⇒ Object
Returns the value of attribute third_ids.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def third_ids @third_ids end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def title @title end |
#website ⇒ Object
Returns the value of attribute website.
5 6 7 |
# File 'lib/sellsy/contact.rb', line 5 def website @website end |
Class Method Details
.find(people_id) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sellsy/contact.rb', line 36 def self.find(people_id) command = { 'method' => 'Peoples.getOne', 'params' => { 'id' => people_id } } response = MultiJson.load(Sellsy::Api.request command) contact = Contact.new if response['response'] value = response['response'] contact.id = value['id'] end contact end |
.find_by_contact(contact_id) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sellsy/contact.rb', line 55 def self.find_by_contact(contact_id) command = { 'method' => 'Peoples.getOne', 'params' => { 'thirdcontactid' => contact_id } } response = MultiJson.load(Sellsy::Api.request command) contact = Contact.new if response['response'] value = response['response'] contact.id = value['id'] end contact end |
.search(name, b_date = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sellsy/contact.rb', line 74 def self.search(name, b_date = nil) contacts = [] unless name.blank? command = { 'method' => 'Peoples.getList', 'params' => { 'search' => { 'contains' => name, 'birthdate' => b_date.blank? ? nil : Date.parse(b_date).to_datetime.to_i, } } } response = MultiJson.load(Sellsy::Api.request command) if response['response'] response['response']['result'].each do |key, value| contact = Contact.new contact.id = key contact.linked_type = value['linkedtype'] contact.linked_id = value['linkedid'] contact.name = value['name'] contact.first_name = value['forename'] contact.email = value['email'] contact.third_ids = ((value['prospectList'] || []) + (value['thirdList'] || []) + (value['supplierList'] || [])).map {|e| e['id']} contacts << contact end end end contacts end |
Instance Method Details
#create ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sellsy/contact.rb', line 8 def create command = { 'method' => 'Peoples.create', 'params' => { 'people' => to_params } } response = MultiJson.load(Sellsy::Api.request command) @id = response['response']['id'] if response['response'] response['status'] == 'success' end |
#get_addresses ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/sellsy/contact.rb', line 124 def get_addresses command = { 'method' => 'Peoples.getAddresses', 'params' => { 'id' => id } } response = MultiJson.load(Sellsy::Api.request command) client = Contact.new if response['response'] value = response['response'] client.id = value['id'] end client end |
#to_params ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/sellsy/contact.rb', line 108 def to_params { 'civil' => civil_enum(@title), 'name' => @last_name || @name, 'forename' => @first_name, 'email' => @email, 'tel' => @telephone, 'fax' => @fax, 'mobile' => @mobile, 'web' => @website, 'position' => @role, 'birthdate' => @birth_date.blank? ? '' : Date.parse(@birth_date).to_datetime.to_i, 'thirdids' => @third_ids.blank? ? nil : @third_ids } end |