sellsy-client 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,156 @@
1
+ require 'multi_json'
2
+
3
+ module Sellsy
4
+ class Opportunity
5
+ attr_accessor :id, :name, :reference, :amount, :entity_type, :entity_id, :source_name, :funnel_name, :step_name,
6
+ :comments
7
+
8
+ def create
9
+ command = {
10
+ 'method' => 'Opportunities.create',
11
+ 'params' => api_params
12
+ }
13
+
14
+ response = MultiJson.load(Sellsy::Api.request command)
15
+ @id = response['response']
16
+ response['status'] == 'success'
17
+ end
18
+
19
+ def update
20
+ command = {
21
+ 'method' => 'Opportunities.update',
22
+ 'params' => api_params
23
+ }
24
+
25
+ response = MultiJson.load(Sellsy::Api.request command)
26
+ response['status'] == 'success'
27
+ end
28
+
29
+ def get_funnel
30
+ command = {'method' => 'Opportunities.getFunnels', 'params' => {}}
31
+ response = MultiJson.load(Sellsy::Api.request command)
32
+
33
+ funnel = nil
34
+ unless response['response'].blank? || funnel_name.blank?
35
+ funnel = response['response'].values.find {|f| f['name'].parameterize == funnel_name.parameterize}
36
+ end
37
+ funnel
38
+ end
39
+
40
+ def get_step(funnel_id)
41
+ command = {'method' => 'Opportunities.getStepsForFunnel', 'params' => {'funnelid' => funnel_id}}
42
+ response = MultiJson.load(Sellsy::Api.request command)
43
+
44
+ step = [nil]
45
+ unless response['response'].blank? || step_name.blank?
46
+ step = response['response'].find {|s| s['label'].parameterize == step_name.parameterize}
47
+ end
48
+ step
49
+ end
50
+
51
+ def get_source
52
+ command = {'method' => 'Opportunities.getSources', 'params' => {}}
53
+ response = MultiJson.load(Sellsy::Api.request command)
54
+
55
+ source = nil
56
+ unless response['response'].blank? || source_name.blank?
57
+ source = response['response'].values.find {|s| s['label'].parameterize == source_name.parameterize}
58
+ end
59
+ source
60
+ end
61
+
62
+ def api_params
63
+ funnel = get_funnel
64
+ step = get_step(funnel['id'])
65
+ source = get_source
66
+ if funnel && step && source
67
+ {
68
+ 'opportunity' => {
69
+ 'linkedtype' => @entity_type,
70
+ 'linkedid' => @entity_id,
71
+ 'ident' => @reference,
72
+ 'sourceid' => source['id'],
73
+ 'name' => @name,
74
+ 'potential' => @amount,
75
+ 'funnelid' => funnel['id'],
76
+ 'dueDate' => (Date.today + 1.month).to_datetime.to_i,
77
+ 'stepid' => step['id']
78
+ }
79
+ }
80
+ else
81
+ raise Exception.new("Could not find funnel, step, or source with names #{funnel_name} - #{step_name} - #{source_name}")
82
+ end
83
+ end
84
+
85
+ def self.find(id)
86
+ command = {
87
+ 'method' => 'Opportunities.getOne',
88
+ 'params' => {
89
+ 'clientid' => id
90
+ }
91
+ }
92
+
93
+ response = MultiJson.load(Sellsy::Api.request command)
94
+
95
+ opportunity = Opportunity.new
96
+
97
+ if response['response']
98
+ value = response['response']['opportunity']
99
+ opportunity.id = value['id']
100
+ opportunity.name = value['name']
101
+ end
102
+
103
+ return opportunity
104
+ end
105
+
106
+ def self.search(params)
107
+ command = {
108
+ 'method' => 'Opportunities.getList',
109
+ 'params' => params
110
+ }
111
+
112
+ response = MultiJson.load(Sellsy::Api.request command)
113
+
114
+ opportunities = []
115
+ if response['response']
116
+ response['response']['result'].each do |key, value|
117
+ opportunity = Opportunity.new
118
+ opportunity.id = key
119
+ opportunity.status = value['status']
120
+ opportunity.name = value['name']
121
+ opportunity.ident = value['ident']
122
+ opportunity.signed = value['signed']
123
+ opportunity.linkedid = value['linkedid']
124
+ opportunities << opportunity
125
+ end
126
+ end
127
+
128
+ opportunities
129
+ end
130
+
131
+ def self.all
132
+ command = {
133
+ 'method' => 'Opportunities.getList',
134
+ 'params' => {}
135
+ }
136
+
137
+ response = MultiJson.load(Sellsy::Api.request command)
138
+
139
+ opportunities = []
140
+ if response['response']
141
+ response['response']['result'].each do |key, value|
142
+ opportunity = Opportunity.new
143
+ opportunity.id = key
144
+ opportunity.status = value['status']
145
+ opportunity.name = value['name']
146
+ opportunity.ident = value['ident']
147
+ opportunity.signed = value['signed']
148
+ opportunity.linkedid = value['linkedid']
149
+ opportunities << opportunity
150
+ end
151
+ end
152
+
153
+ opportunities
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,138 @@
1
+ require 'multi_json'
2
+
3
+ module Sellsy
4
+ class Prospect
5
+
6
+ attr_accessor :id, :title, :name, :first_name, :last_name, :structure_name, :category, :college_type, :siret,
7
+ :ape, :legal_type, :role, :birth_date, :address, :postal_code, :town, :country, :telephone, :email,
8
+ :website, :payment_method, :person_type, :apidae_member_id
9
+
10
+ def create
11
+ command = {
12
+ 'method' => 'Prospects.create',
13
+ 'params' => api_params
14
+ }
15
+
16
+ response = MultiJson.load(Sellsy::Api.request command)
17
+ @id = response['response']
18
+ response['status'] == 'success'
19
+ end
20
+
21
+ def update
22
+ command = {
23
+ 'method' => 'Prospects.update',
24
+ 'params' => api_params
25
+ }
26
+
27
+ response = MultiJson.load(Sellsy::Api.request command)
28
+ response['status'] == 'success'
29
+ end
30
+
31
+ def api_params
32
+ {
33
+ 'third' => {
34
+ 'name' => person_type == 'pp' ? @name : @structure_name,
35
+ 'type' => person_type == 'pp' ? 'person' : 'corporation',
36
+ 'email' => @email,
37
+ 'web' => @website,
38
+ 'siret' => @siret,
39
+ 'corpType' => @legal_type,
40
+ 'apenaf' => @ape
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
+ },
51
+ 'address' => {
52
+ 'name' => 'adresse souscription',
53
+ 'part1' => @address.split(/(\r\n?)/)[0],
54
+ 'part2' => @address.split(/(\r\n?)/)[0],
55
+ 'zip' => @postal_code,
56
+ 'town' => @town,
57
+ 'countrycode' => @country.upcase
58
+ }
59
+ }
60
+ end
61
+
62
+ def self.find(id)
63
+ command = {
64
+ 'method' => 'Prospects.getOne',
65
+ 'params' => {
66
+ 'id' => id
67
+ }
68
+ }
69
+
70
+ response = MultiJson.load(Sellsy::Api.request command)
71
+
72
+ prospect = Prospect.new
73
+
74
+ if response['response']
75
+ value = response['response']['client']
76
+ prospect.id = value['id']
77
+ prospect.name = value['name']
78
+ end
79
+
80
+ return prospect
81
+ end
82
+
83
+ def self.search(params)
84
+ command = {
85
+ 'method' => 'Prospects.getList',
86
+ 'params' => params
87
+ }
88
+
89
+ response = MultiJson.load(Sellsy::Api.request command)
90
+
91
+ prospects = []
92
+ if response['response']
93
+ response['response']['result'].each do |key, value|
94
+ prospect = Prospect.new
95
+ prospect.id = key
96
+ prospect.name = value['fullName']
97
+ prospects << prospect
98
+ end
99
+ end
100
+
101
+ prospects
102
+ end
103
+
104
+ def self.all
105
+ command = {
106
+ 'method' => 'Prospects.getList',
107
+ 'params' => {}
108
+ }
109
+
110
+ response = MultiJson.load(Sellsy::Api.request command)
111
+
112
+ prospects = []
113
+ if response['response']
114
+ response['response']['result'].each do |key, value|
115
+ prospect = Prospect.new
116
+ prospect.id = key
117
+ prospect.name = value['fullName']
118
+ prospects << prospect
119
+ end
120
+ end
121
+
122
+ prospects
123
+ end
124
+
125
+ private
126
+
127
+ def civil_enum(val)
128
+ case val
129
+ when 'M.'
130
+ 'man'
131
+ when 'Mme'
132
+ 'woman'
133
+ else
134
+ nil
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,3 @@
1
+ module Sellsy
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'lib/sellsy/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "sellsy-client"
5
+ spec.version = Sellsy::VERSION
6
+ spec.authors = ["Jens Stammers", "Guirec Corbel", "François Guilbert", "Jean-Baptiste Vilain"]
7
+ spec.email = ["jbvilain@gmail.com"]
8
+
9
+ spec.summary = "A Ruby gem wrapping a REST client for the Sellsy API"
10
+ spec.description = "To be completed"
11
+ spec.homepage = "https://github.com/hotentic/sellsy-client"
12
+ spec.license = "MIT"
13
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
+
15
+ # Specify which files should be added to the gem when it is released.
16
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
17
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ end
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "multi_json", "~> 1.11"
23
+ spec.add_dependency "rest-client", "~> 2.0", ">= 2.0.2"
24
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sellsy-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jens Stammers
8
+ - Guirec Corbel
9
+ - François Guilbert
10
+ - Jean-Baptiste Vilain
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2020-02-28 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: multi_json
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: '1.11'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.11'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rest-client
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.0'
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.0.2
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 2.0.2
50
+ description: To be completed
51
+ email:
52
+ - jbvilain@gmail.com
53
+ executables: []
54
+ extensions: []
55
+ extra_rdoc_files: []
56
+ files:
57
+ - ".gitignore"
58
+ - ".travis.yml"
59
+ - CODE_OF_CONDUCT.md
60
+ - Gemfile
61
+ - Gemfile.lock
62
+ - LICENSE.txt
63
+ - README.md
64
+ - Rakefile
65
+ - bin/console
66
+ - bin/setup
67
+ - lib/sellsy.rb
68
+ - lib/sellsy/address.rb
69
+ - lib/sellsy/api.rb
70
+ - lib/sellsy/attachment.rb
71
+ - lib/sellsy/contact.rb
72
+ - lib/sellsy/custom_field.rb
73
+ - lib/sellsy/customer.rb
74
+ - lib/sellsy/document.rb
75
+ - lib/sellsy/invoice.rb
76
+ - lib/sellsy/opportunity.rb
77
+ - lib/sellsy/prospect.rb
78
+ - lib/sellsy/version.rb
79
+ - sellsy-client.gemspec
80
+ homepage: https://github.com/hotentic/sellsy-client
81
+ licenses:
82
+ - MIT
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: 2.3.0
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 2.7.6.2
101
+ signing_key:
102
+ specification_version: 4
103
+ summary: A Ruby gem wrapping a REST client for the Sellsy API
104
+ test_files: []