Class: Sellsy::Contact

Inherits:
Object
  • Object
show all
Defined in:
lib/sellsy/contact.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#birth_dateObject

Returns the value of attribute birth_date.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def birth_date
  @birth_date
end

#emailObject

Returns the value of attribute email.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def email
  @email
end

#faxObject

Returns the value of attribute fax.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def fax
  @fax
end

#first_nameObject

Returns the value of attribute first_name.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def first_name
  @first_name
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def id
  @id
end

#last_nameObject

Returns the value of attribute last_name.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def last_name
  @last_name
end

#mobileObject

Returns the value of attribute mobile.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def mobile
  @mobile
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def name
  @name
end

#roleObject

Returns the value of attribute role.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def role
  @role
end

#telephoneObject

Returns the value of attribute telephone.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def telephone
  @telephone
end

#third_idObject

Returns the value of attribute third_id.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def third_id
  @third_id
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/sellsy/contact.rb', line 5

def title
  @title
end

#websiteObject

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



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sellsy/contact.rb', line 23

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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sellsy/contact.rb', line 42

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

Instance Method Details

#createObject



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_addressesObject



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/sellsy/contact.rb', line 77

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_paramsObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sellsy/contact.rb', line 61

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_id.blank? ? nil : [@third_id]
  }
end