Class: Sellsy::Customer

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#addressObject

Returns the value of attribute address.



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

def address
  @address
end

#apeObject

Returns the value of attribute ape.



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

def ape
  @ape
end

#apidae_member_idObject

Returns the value of attribute apidae_member_id.



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

def apidae_member_id
  @apidae_member_id
end

#categoryObject

Returns the value of attribute category.



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

def category
  @category
end

#college_typeObject

Returns the value of attribute college_type.



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

def college_type
  @college_type
end

#contactObject

Returns the value of attribute contact.



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

def contact
  @contact
end

#contactsObject

Returns the value of attribute contacts.



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

def contacts
  @contacts
end

#emailObject

Returns the value of attribute email.



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

def email
  @email
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

Returns the value of attribute legal_type.



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

def legal_type
  @legal_type
end

#main_contact_idObject

Returns the value of attribute main_contact_id.



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

def main_contact_id
  @main_contact_id
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#payment_methodObject

Returns the value of attribute payment_method.



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

def payment_method
  @payment_method
end

#person_typeObject

Returns the value of attribute person_type.



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

def person_type
  @person_type
end

#siretObject

Returns the value of attribute siret.



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

def siret
  @siret
end

#structure_nameObject

Returns the value of attribute structure_name.



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

def structure_name
  @structure_name
end

#websiteObject

Returns the value of attribute website.



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

def website
  @website
end

Class Method Details

.allObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/sellsy/customer.rb', line 93

def self.all
  command = {
      'method' => 'Client.getList',
      'params' => {}
  }

  response = MultiJson.load(Sellsy::Api.request command)

  clients = []
  if response['response']
    response['response']['result'].each do |key, value|
      client = Customer.new
      client.id = key
      client.name = value['fullName']
      clients << client
    end
  end

  clients
end

.find(id) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/sellsy/customer.rb', line 48

def self.find(id)
  command = {
      'method' => 'Client.getOne',
      'params' => {
          'clientid' => id
      }
  }

  response = MultiJson.load(Sellsy::Api.request command)

  client = Customer.new

  if response['response']
    value = response['response']['client']
    client.id = value['id']
    client.name = value['name']
    client.contacts = response['response']['contacts']
  end

  client
end

.search(params) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/sellsy/customer.rb', line 70

def self.search(params)
  command = {
      'method' => 'Client.getList',
      'params' => params
  }

  response = MultiJson.load(Sellsy::Api.request command)

  clients = []
  if response['response']
    response['response']['result'].each do |key, value|
      client = Customer.new
      client.id = key
      client.name = value['fullName']
      client.email = value['email']
      client.siret = value['siret']
      clients << client
    end
  end

  clients
end

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/sellsy/customer.rb', line 9

def create
  command = {
      'method' => 'Client.create',
      'params' => to_params
  }

  response = MultiJson.load(Sellsy::Api.request command)
  @id = response['response']
  response['status'] == 'success'
end

#to_paramsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sellsy/customer.rb', line 30

def to_params
  {
      'clientid' => @id,
      'third' => {
          'name' => person_type == 'pp' ? @name : @structure_name,
          'type' => person_type == 'pp' ? 'person' : 'corporation',
          'ident' => apidae_member_id,
          'email' => @email,
          'web' => @website,
          'siret' => @siret,
          'corpType' => @legal_type,
          'apenaf' => @ape
      },
      'contact' => contact ? contact.to_params : {},
      'address' => address ? address.to_params : {}
  }
end

#updateObject



20
21
22
23
24
25
26
27
28
# File 'lib/sellsy/customer.rb', line 20

def update
  command = {
      'method' => 'Client.update',
      'params' => to_params
  }

  response = MultiJson.load(Sellsy::Api.request command)
  response['status'] == 'success'
end