sellsy-client 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 165af8ae3b65cccc9b2034b90bb589fb7f0161341bb4ef37f66def892cbb01c4
4
- data.tar.gz: 6e64eebc0fc8c72c15a762ac87f5b3f810c419a59900195b80e295f148b7c373
3
+ metadata.gz: 51a9e7f54826cc77b1784e91113329ea52380c9379a9fcf7a5b425a97fb2e952
4
+ data.tar.gz: 7060b5b64cd943c26d916eb87ce09e8fdeb76e48ac7b83b128982c2a87415a2b
5
5
  SHA512:
6
- metadata.gz: 77a2821b78be6529a6fdd1ebc03d359874f9f3fb6a0209f99395bb6ccaf7c3f4ec81f8b3e8f2c40b2491755db86e2dd2de07f2c89214b484d202bb61ae243234
7
- data.tar.gz: 7c9a532fd7e3d50d61c90132c0ac35b19fb631aca78bba4aa9c7998848d35591850ff8210965aa7fdbbc1c1dfb4d7089944a537c4ebf61a46c8cd974fd6f9e58
6
+ metadata.gz: 3379c071310f46fb48bd06a0e1a7bd51c26108f4b54e3f09e9a5944ceb68eae009eaef2fdde0179c813d973d75339bd6d9de47bdd0c93e98027376431b71559a
7
+ data.tar.gz: 4d91ace6f38ddfe6d23b0dfa22fee7239b7b47729cef31d0cc00abf27905181af4c01dbf544df98213875d05a0bed79b259254b9b474570cef49b88125394dc2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sellsy-client (0.1.0)
4
+ sellsy-client (0.2.0)
5
5
  multi_json (~> 1.11)
6
6
  rest-client (~> 2.0, >= 2.0.2)
7
7
 
@@ -2,23 +2,12 @@ require 'multi_json'
2
2
 
3
3
  module Sellsy
4
4
  class Address
5
- attr_accessor :id
6
- attr_accessor :part1, :town, :country_code, :linkedid, :linkedtype, :zip, :name
5
+ attr_accessor :id, :name, :address, :postal_code, :town, :country, :linkedid, :linkedtype
7
6
 
8
7
  def create
9
- params = {
10
- "name" => name,
11
- "linkedtype" => linkedtype,
12
- "linkedid" => linkedid,
13
- "part1" => part1,
14
- "zip" => zip,
15
- "town" => town,
16
- "countrycode" => country_code,
17
- }
18
-
19
8
  command = {
20
9
  'method' => 'Addresses.create',
21
- 'params' => params
10
+ 'params' => to_params
22
11
  }
23
12
 
24
13
  response = MultiJson.load(Sellsy::Api.request command)
@@ -42,12 +31,12 @@ module Sellsy
42
31
  if response['response']
43
32
  value = response['response']
44
33
  address.id = key
45
- address.part1 = value['part1']
34
+ address.address = [value['part1'], value['part2'] || ''].select {|p| !p.blank?}.join("\n")
46
35
  address.town = value['town']
47
- address.country_code = value['countrycode']
36
+ address.country = value['countrycode'].downcase unless value['countrycode'].blank?
48
37
  address.linkedid = value['linkedid']
49
38
  address.linkedtype = value['linkedtype']
50
- address.zip = value['zip']
39
+ address.postal_code = value['zip']
51
40
  end
52
41
 
53
42
  address
@@ -67,17 +56,30 @@ module Sellsy
67
56
  response['response']['result'].each do |key, value|
68
57
  address = Address.new
69
58
  address.id = key
70
- address.part1 = value['part1']
59
+ address.address = [value['part1'] || '', value['part2'] || ''].select {|p| !p.blank?}.join("\n")
71
60
  address.town = value['town']
72
- address.country_code = value['countrycode']
61
+ address.country = value['countrycode'].downcase unless value['countrycode'].blank?
73
62
  address.linkedid = value['linkedid']
74
63
  address.linkedtype = value['linkedtype']
75
- address.zip = value['zip']
64
+ address.postal_code = value['zip']
76
65
  addresses << address
77
66
  end
78
67
  end
79
68
 
80
69
  addresses
81
70
  end
71
+
72
+ def to_params
73
+ {
74
+ 'name' => 'Adresse principale',
75
+ 'part1' => @address.split(/(\r\n?)/)[0],
76
+ 'part2' => @address.split(/(\r\n?)/)[1],
77
+ 'zip' => @postal_code,
78
+ 'town' => @town,
79
+ 'countrycode' => @country.upcase,
80
+ "linkedtype" => linkedtype,
81
+ "linkedid" => linkedid
82
+ }
83
+ end
82
84
  end
83
85
  end
@@ -2,20 +2,14 @@ require 'multi_json'
2
2
 
3
3
  module Sellsy
4
4
  class Contact
5
- attr_accessor :id
6
- attr_accessor :name, :thirdid, :forename, :email, :position
5
+ attr_accessor :id, :title, :name, :first_name, :last_name, :third_id, :email, :telephone, :mobile, :fax, :website,
6
+ :role, :birth_date
7
7
 
8
8
  def create
9
9
  command = {
10
10
  'method' => 'Peoples.create',
11
11
  'params' => {
12
- 'people' => {
13
- 'name' => @name,
14
- 'forename' => @forename,
15
- 'email' => @email,
16
- 'position' => @position,
17
- 'thirdids' => [@thirdid]
18
- }
12
+ 'people' => to_params
19
13
  }
20
14
  }
21
15
 
@@ -26,11 +20,11 @@ module Sellsy
26
20
  response['status'] == 'success'
27
21
  end
28
22
 
29
- def self.find(id)
23
+ def self.find(people_id)
30
24
  command = {
31
25
  'method' => 'Peoples.getOne',
32
26
  'params' => {
33
- 'id' => id
27
+ 'id' => people_id
34
28
  }
35
29
  }
36
30
 
@@ -45,6 +39,41 @@ module Sellsy
45
39
  contact
46
40
  end
47
41
 
42
+ def self.find_by_contact(contact_id)
43
+ command = {
44
+ 'method' => 'Peoples.getOne',
45
+ 'params' => {
46
+ 'thirdcontactid' => contact_id
47
+ }
48
+ }
49
+
50
+ response = MultiJson.load(Sellsy::Api.request command)
51
+ contact = Contact.new
52
+
53
+ if response['response']
54
+ value = response['response']
55
+ contact.id = value['id']
56
+ end
57
+
58
+ contact
59
+ end
60
+
61
+ def to_params
62
+ {
63
+ 'civil' => civil_enum(@title),
64
+ 'name' => @last_name || @name,
65
+ 'forename' => @first_name,
66
+ 'email' => @email,
67
+ 'tel' => @telephone,
68
+ 'fax' => @fax,
69
+ 'mobile' => @mobile,
70
+ 'web' => @website,
71
+ 'position' => @role,
72
+ 'birthdate' => @birth_date.blank? ? '' : Date.parse(@birth_date).to_datetime.to_i,
73
+ 'thirdids' => @third_id.blank? ? nil : [@third_id]
74
+ }
75
+ end
76
+
48
77
  def get_addresses
49
78
  command = {
50
79
  'method' => 'Peoples.getAddresses',
@@ -63,5 +92,18 @@ module Sellsy
63
92
 
64
93
  client
65
94
  end
95
+
96
+ private
97
+
98
+ def civil_enum(val)
99
+ case val
100
+ when 'M.'
101
+ 'man'
102
+ when 'Mme'
103
+ 'woman'
104
+ else
105
+ nil
106
+ end
107
+ end
66
108
  end
67
109
  end
@@ -15,7 +15,7 @@ module Sellsy
15
15
  'params' => {
16
16
  'linkedtype' => linked_type(entity),
17
17
  'linkedid' => entity.id,
18
- 'values' => custom_fields.select {|cf| !cf.value.blank?}.map {|cf| {'cfid' => cf.id, 'value' => cf.value}}
18
+ 'values' => custom_fields.select {|cf| !cf.nil? && !cf.value.blank?}.map {|cf| {'cfid' => cf.id, 'value' => cf.value}}
19
19
  }
20
20
  }
21
21
 
@@ -40,5 +40,19 @@ module Sellsy
40
40
  nil
41
41
  end
42
42
  end
43
+
44
+ def self.all
45
+ command = {
46
+ 'method' => 'CustomFields.getList',
47
+ 'params' => {
48
+ 'pagination' => {
49
+ 'nbperpage' => 30
50
+ }
51
+ }
52
+ }
53
+ response = MultiJson.load(Sellsy::Api.request command)
54
+
55
+ response['status'] == 'success' ? response['response']['result'] : {}
56
+ end
43
57
  end
44
58
  end
@@ -2,14 +2,14 @@ require 'multi_json'
2
2
 
3
3
  module Sellsy
4
4
  class Customer
5
- attr_accessor :id, :title, :name, :first_name, :last_name, :structure_name, :category, :college_type, :siret,
6
- :ape, :legal_type, :role, :birth_date, :address, :postal_code, :town, :country, :telephone, :email,
7
- :website, :payment_method, :person_type, :apidae_member_id, :main_contact_id
5
+ attr_accessor :id, :name, :structure_name, :category, :college_type, :siret, :ape, :legal_type, :email,
6
+ :website, :payment_method, :person_type, :apidae_member_id, :main_contact_id, :contact, :address,
7
+ :contacts
8
8
 
9
9
  def create
10
10
  command = {
11
11
  'method' => 'Client.create',
12
- 'params' => api_params
12
+ 'params' => to_params
13
13
  }
14
14
 
15
15
  response = MultiJson.load(Sellsy::Api.request command)
@@ -20,14 +20,14 @@ module Sellsy
20
20
  def update
21
21
  command = {
22
22
  'method' => 'Client.update',
23
- 'params' => api_params
23
+ 'params' => to_params
24
24
  }
25
25
 
26
26
  response = MultiJson.load(Sellsy::Api.request command)
27
27
  response['status'] == 'success'
28
28
  end
29
29
 
30
- def api_params
30
+ def to_params
31
31
  {
32
32
  'id' => @id,
33
33
  'third' => {
@@ -40,23 +40,8 @@ module Sellsy
40
40
  'corpType' => @legal_type,
41
41
  'apenaf' => @ape
42
42
  },
43
- 'contact' => {
44
- 'civil' => civil_enum(@title),
45
- 'name' => @last_name || @name,
46
- 'forename' => @first_name,
47
- 'email' => @email,
48
- 'tel' => @telephone,
49
- 'mobile' => @telephone,
50
- 'position' => @role,
51
- },
52
- 'address' => {
53
- 'name' => 'Adresse principale',
54
- 'part1' => @address.split(/(\r\n?)/)[0],
55
- 'part2' => @address.split(/(\r\n?)/)[0],
56
- 'zip' => @postal_code,
57
- 'town' => @town,
58
- 'countrycode' => @country.upcase
59
- }
43
+ 'contact' => contact ? contact.to_params : {},
44
+ 'address' => address ? address.to_params : {}
60
45
  }
61
46
  end
62
47
 
@@ -76,9 +61,8 @@ module Sellsy
76
61
  value = response['response']['client']
77
62
  client.id = value['id']
78
63
  client.name = value['name']
79
- client.joindate = value['joindate']
80
64
  client.type = value['type']
81
- client.main_contact_id = value['maincontactid']
65
+ client.contacts = response['response']['contacts']
82
66
  end
83
67
 
84
68
  client
@@ -125,18 +109,5 @@ module Sellsy
125
109
 
126
110
  clients
127
111
  end
128
-
129
- private
130
-
131
- def civil_enum(val)
132
- case val
133
- when 'M.'
134
- 'man'
135
- when 'Mme'
136
- 'woman'
137
- else
138
- nil
139
- end
140
- end
141
112
  end
142
113
  end
@@ -65,6 +65,7 @@ module Sellsy
65
65
  source = get_source
66
66
  if funnel && step && source
67
67
  {
68
+ 'id' => @id,
68
69
  'opportunity' => {
69
70
  'linkedtype' => @entity_type,
70
71
  'linkedid' => @entity_id,
@@ -95,7 +96,7 @@ module Sellsy
95
96
  opportunity = Opportunity.new
96
97
 
97
98
  if response['response']
98
- value = response['response']['opportunity']
99
+ value = response['response']
99
100
  opportunity.id = value['id']
100
101
  opportunity.name = value['name']
101
102
  end
@@ -2,14 +2,14 @@ require 'multi_json'
2
2
 
3
3
  module Sellsy
4
4
  class Prospect
5
- attr_accessor :id, :title, :name, :first_name, :last_name, :structure_name, :category, :college_type, :siret,
6
- :ape, :legal_type, :role, :birth_date, :address, :postal_code, :town, :country, :telephone, :email,
7
- :website, :payment_method, :person_type, :apidae_member_id, :main_contact_id
5
+ attr_accessor :id, :name, :structure_name, :category, :college_type, :siret, :ape, :legal_type, :email,
6
+ :website, :payment_method, :person_type, :apidae_member_id, :main_contact_id, :contact, :address,
7
+ :contacts
8
8
 
9
9
  def create
10
10
  command = {
11
11
  'method' => 'Prospects.create',
12
- 'params' => api_params
12
+ 'params' => to_params
13
13
  }
14
14
 
15
15
  response = MultiJson.load(Sellsy::Api.request command)
@@ -20,14 +20,14 @@ module Sellsy
20
20
  def update
21
21
  command = {
22
22
  'method' => 'Prospects.update',
23
- 'params' => api_params
23
+ 'params' => to_params
24
24
  }
25
25
 
26
26
  response = MultiJson.load(Sellsy::Api.request command)
27
27
  response['status'] == 'success'
28
28
  end
29
29
 
30
- def api_params
30
+ def to_params
31
31
  {
32
32
  'id' => @id,
33
33
  'third' => {
@@ -39,24 +39,8 @@ module Sellsy
39
39
  'corpType' => @legal_type,
40
40
  'apenaf' => @ape
41
41
  },
42
- 'contact' => {
43
- 'civil' => civil_enum(@title),
44
- 'name' => @last_name || @name,
45
- 'forename' => @first_name,
46
- 'email' => @email,
47
- 'tel' => @telephone,
48
- 'mobile' => @telephone,
49
- 'position' => @role,
50
- 'birthdate' => @birth_date.blank? ? '' : Date.parse(@birth_date).to_datetime.to_i
51
- },
52
- 'address' => {
53
- 'name' => 'Adresse principale',
54
- 'part1' => @address.split(/(\r\n?)/)[0],
55
- 'part2' => @address.split(/(\r\n?)/)[1],
56
- 'zip' => @postal_code,
57
- 'town' => @town,
58
- 'countrycode' => @country.upcase
59
- }
42
+ 'contact' => contact ? contact.to_params : {},
43
+ 'address' => address ? address.to_params : {}
60
44
  }
61
45
  end
62
46
 
@@ -76,7 +60,7 @@ module Sellsy
76
60
  value = response['response']['client']
77
61
  prospect.id = value['id']
78
62
  prospect.name = value['name']
79
- prospect.main_contact_id = value['maincontactid']
63
+ prospect.contacts = response['response']['contacts']
80
64
  end
81
65
 
82
66
  return prospect
@@ -123,18 +107,5 @@ module Sellsy
123
107
 
124
108
  prospects
125
109
  end
126
-
127
- private
128
-
129
- def civil_enum(val)
130
- case val
131
- when 'M.'
132
- 'man'
133
- when 'Mme'
134
- 'woman'
135
- else
136
- nil
137
- end
138
- end
139
110
  end
140
111
  end
@@ -1,3 +1,3 @@
1
1
  module Sellsy
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sellsy-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Stammers
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2020-03-20 00:00:00.000000000 Z
14
+ date: 2020-03-26 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: multi_json