class Sellsy::Contact
Attributes
birth_date[RW]
email[RW]
fax[RW]
first_name[RW]
id[RW]
last_name[RW]
linked_id[RW]
linked_type[RW]
mobile[RW]
name[RW]
role[RW]
telephone[RW]
third_ids[RW]
title[RW]
website[RW]
Public Class Methods
find(people_id)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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
Public Instance Methods
create()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# 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
update()
click to toggle source
# File lib/sellsy/contact.rb, line 23 def update command = { 'method' => 'Peoples.update', 'params' => { 'id' => @id, 'people' => to_params } } response = MultiJson.load(Sellsy::Api.request command) response['status'] == 'success' end
Private Instance Methods
civil_enum(val)
click to toggle source
# File lib/sellsy/contact.rb, line 145 def civil_enum(val) case val when 'M.' 'man' when 'Mme' 'woman' else nil end end