Dendreo 1.0.5 → 1.1.1
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 +5 -5
- data/.gitignore +2 -0
- data/.ruby-version +1 -0
- data/Dendreo-1.1.0.gem +0 -0
- data/README.md +58 -31
- data/dendreo.gemspec +5 -4
- data/lib/dendreo.rb +37 -30
- data/lib/dendreo/request.rb +64 -0
- data/lib/dendreo/requests/error.rb +11 -0
- data/lib/dendreo/requests/url.rb +35 -0
- data/lib/dendreo/version.rb +1 -1
- metadata +34 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 80deec797bcba45bc51d99def32ab84d15796a83e07e1219b6c379702d788ee5
|
4
|
+
data.tar.gz: ba2118cdb3d05e7f0f6e875634eeffeb2354ed98355ef0df5326d6d1a1081b76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d28f4d2e4b3410911cc932d471b797509872bb3f8d1b1cb08dacec9187d31f43ac1a06c72069e5d20ab1f249c4a464331f32d42cdc935e5950a3ee79062c84a
|
7
|
+
data.tar.gz: 145b8f63c3d285a33b6c2a7c98b39e423ee1d184237ec43fc9c4e0f7dd7350c160a2c95237970c9d6b39c020959fae3c9d60c8093bf07a861c829e3a726adf8d
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.1
|
data/Dendreo-1.1.0.gem
ADDED
Binary file
|
data/README.md
CHANGED
@@ -25,7 +25,7 @@ Ou installez la gem vous-même:
|
|
25
25
|
Instanciez votre API.
|
26
26
|
|
27
27
|
```ruby
|
28
|
-
dendreo = Dendreo::API.new(
|
28
|
+
dendreo = Dendreo::API.new('https://pro.dendreo.com/masociété/api', 'MaCleApi')
|
29
29
|
```
|
30
30
|
Attention à bien vérifier que votre url à bien ce format:
|
31
31
|
|
@@ -37,67 +37,94 @@ Attention à bien vérifier que votre url à bien ce format:
|
|
37
37
|
|
38
38
|
Je vous invite à bien lire la documentation de l'api ici => https://developers.dendreo.com/
|
39
39
|
|
40
|
-
La gem utilise la
|
40
|
+
La gem utilise la 'method_missing', il vous suffira donc de récupérer le nom de la resource que vous souhaitez récupérer, ajouter ou modifier.
|
41
41
|
|
42
42
|
Exemple:
|
43
43
|
|
44
44
|
Il faut donc piocher le nom de la ressource tel quel est dans l'url de la requête API.
|
45
45
|
|
46
|
-
-Catégories de module. =>
|
47
|
-
-Catégories de produits =>
|
48
|
-
-Modules/Produits =>
|
49
|
-
-Formateurs =>
|
50
|
-
-Entreprises =>
|
51
|
-
-Contacts =>
|
52
|
-
-Particuliers =>
|
53
|
-
-Participants =>
|
54
|
-
-Etapes =>
|
55
|
-
-Centres de formation =>
|
56
|
-
-Salles de formation =>
|
57
|
-
-Factures =>
|
58
|
-
-Actions de formation =>
|
59
|
-
-Créneaux =>
|
60
|
-
-Inscription d'un participant =>
|
61
|
-
-Programmation d'un module =>
|
62
|
-
-Mails =>
|
46
|
+
- Catégories de module. => 'categories_module'
|
47
|
+
- Catégories de produits => 'categories_produit'
|
48
|
+
- Modules/Produits => 'modules'
|
49
|
+
- Formateurs => 'formateurs'
|
50
|
+
- Entreprises => 'entreprises'
|
51
|
+
- Contacts => 'contacts'
|
52
|
+
- Particuliers => 'contacts' avec la variable 'particulier' = 1 sinon ajout d'un contact
|
53
|
+
- Participants => 'participants'
|
54
|
+
- Etapes => 'etapes'
|
55
|
+
- Centres de formation => 'centres_de_formation'
|
56
|
+
- Salles de formation => 'salles_de_formation'
|
57
|
+
- Factures => 'factures'
|
58
|
+
- Actions de formation => 'actions_de_formation'
|
59
|
+
- Créneaux => 'creneaux'
|
60
|
+
- Inscription d'un participant => 'laps'
|
61
|
+
- Programmation d'un module => 'lams'
|
62
|
+
- Mails => 'emails'
|
63
|
+
|
64
|
+
|
65
|
+
Arguments:
|
63
66
|
|
67
|
+
```ruby
|
68
|
+
# methode http
|
69
|
+
{ method: :get }
|
70
|
+
|
71
|
+
# toute information qui doit passer par l'url
|
72
|
+
{ url_data: { id: 123456 } }
|
73
|
+
|
74
|
+
# toute information que vous souhaitez modifier/créer
|
75
|
+
{ form_data: { email: 'dendreo@test.com' } }
|
76
|
+
|
77
|
+
# exemple d'utilisation
|
78
|
+
dendreo = Dendreo::API.new('https://pro.dendreo.com/masociété/api', 'MaCleApi')
|
79
|
+
|
80
|
+
dendreo.participants(
|
81
|
+
method: :post,
|
82
|
+
url_data: {
|
83
|
+
id_participant: 1345
|
84
|
+
},
|
85
|
+
form_data: {
|
86
|
+
nom: 'nouveau nom',
|
87
|
+
civilite: 'M.',
|
88
|
+
id_add: 2,
|
89
|
+
}
|
90
|
+
)
|
91
|
+
|
92
|
+
```
|
64
93
|
|
65
94
|
Pour les participants ( GET https://pro.dendreo.com/demo/api/participants.php?)
|
66
95
|
|
67
96
|
```ruby
|
68
97
|
# Renvoi tous les particpants
|
69
|
-
dendreo.participants(method:
|
98
|
+
dendreo.participants(method: 'get')
|
70
99
|
|
71
100
|
# Renvoi le particpant qui a l'id en question
|
72
|
-
dendreo.participants(method:
|
101
|
+
dendreo.participants(method: 'get', url_data: { id_participant: 1345 })
|
73
102
|
|
74
103
|
# Renvoi le ou les particpants qui ont l'email en question
|
75
|
-
dendreo.participants(method:
|
104
|
+
dendreo.participants(method: 'get', url_data: { email: 'mon_email@gmail.com' })
|
76
105
|
|
77
106
|
#Renvoi le ou les particpants qui ont le commentaire en question
|
78
|
-
dendreo.participants(method:
|
107
|
+
dendreo.participants(method: 'get', url_data: { search: 'Un nom ou ce que vous souhaitez id, email, commentaires etc..' })
|
79
108
|
```
|
80
109
|
|
81
110
|
Ajouter ou modifier un participant.
|
82
111
|
|
83
|
-
Attention, pour modifier un participant déjà existant, il vous suffit de remplacer
|
112
|
+
Attention, pour modifier un participant déjà existant, il vous suffit de remplacer 'id_participant' par 'id' tout court et d'ajouter un 'id_add' qui contiendra un id d'administrateur.
|
84
113
|
|
85
114
|
Faites appel au support dendreo pour plus d'informations, ils sont très réactifs equipe@dendreo.com .
|
86
115
|
|
87
116
|
```ruby
|
88
117
|
# Créer un participant
|
89
|
-
dendreo.participants(method:
|
118
|
+
dendreo.participants(method: 'post', form_data: { nom: 'nouveau nom', prenom: 'toto', civilite: 'M.', email: 'toto@gmail.com', id_add: 2 })
|
90
119
|
|
91
|
-
# Modifier un participant existant (Attention, bien remplacer
|
120
|
+
# Modifier un participant existant (Attention, bien remplacer 'id' par 'id_participant' et ajouter un 'id_add' pour
|
92
121
|
# s'identifier en admin sur la mise à jour.)
|
93
|
-
dendreo.participants(method:
|
122
|
+
dendreo.participants(method: 'post', url_data: { id_participant: 1345 }, form_data: { nom: 'nouveau nom', civilite: 'M.', id_add: 2 })
|
94
123
|
|
95
|
-
# Supprimer un participant (attention, il n'y a pas de methode
|
96
|
-
dendreo.participants(method:
|
124
|
+
# Supprimer un participant (attention, il n'y a pas de methode 'delete' sûr tous les endpoints)
|
125
|
+
dendreo.participants(method: 'delete', url_data: { id_participant: 1345 })
|
97
126
|
|
98
127
|
```
|
99
|
-
Cet exemple fonctionne sur toutes les ressources sauf les "particuliers" que l'on peut créer mais pas modifier.
|
100
|
-
|
101
128
|
|
102
129
|
## Contribution
|
103
130
|
|
data/dendreo.gemspec
CHANGED
@@ -30,8 +30,9 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
33
|
+
spec.add_development_dependency 'bundler'
|
34
|
+
spec.add_development_dependency 'rake'
|
35
|
+
spec.add_development_dependency 'rspec'
|
36
|
+
spec.add_development_dependency 'rest-client'
|
37
|
+
spec.add_development_dependency 'byebug'
|
37
38
|
end
|
data/lib/dendreo.rb
CHANGED
@@ -1,48 +1,55 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'byebug'
|
4
|
+
require 'dendreo/version'
|
5
|
+
require 'dendreo/requests/error'
|
6
|
+
require 'dendreo/requests/url'
|
7
|
+
require 'dendreo/request'
|
8
|
+
require 'json'
|
9
|
+
require 'rest-client'
|
10
|
+
|
5
11
|
module Dendreo
|
6
12
|
class API
|
7
|
-
attr_accessor :url
|
8
|
-
attr_accessor :api_key
|
13
|
+
attr_accessor :url, :api_key, :errors, :result
|
9
14
|
|
10
15
|
def initialize(url, api_key)
|
11
|
-
@url = url #
|
16
|
+
@url = url # https://pro.dendreo.com/my_company/api
|
12
17
|
@api_key = api_key
|
18
|
+
@request = Request.new(base_url: @url, api_key: @api_key)
|
19
|
+
@errors = @request.errors
|
20
|
+
@result = nil
|
21
|
+
handle_errors
|
13
22
|
end
|
14
23
|
|
15
24
|
def method_missing(method_name, *args)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
send_it(:post, "#{base_url}", datas)
|
25
|
-
when "delete"
|
26
|
-
send_it(:delete, "#{base_url}#{format_args_to_url(datas)}")
|
27
|
-
else
|
28
|
-
raise "Méthode inconnue '#{request_method}' !"
|
29
|
-
end
|
25
|
+
@errors = []
|
26
|
+
@result = @request.call(
|
27
|
+
http_method: args.first[:method],
|
28
|
+
endpoint: method_name,
|
29
|
+
args: args.first,
|
30
|
+
)
|
31
|
+
handle_errors
|
32
|
+
@result
|
30
33
|
end
|
31
34
|
|
32
35
|
private
|
33
36
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
37
|
+
def handle_errors
|
38
|
+
handle_init_errors
|
39
|
+
@errors += @request.errors
|
40
|
+
return if @errors.empty?
|
39
41
|
|
40
|
-
|
41
|
-
args.any? ? args.map{|k, v| k == args.keys.first ? "&#{k}=#{v}" : "#{k}=#{v}" }.join("&") : ""
|
42
|
+
raise Requests::Error.new(@errors.map(&:message).join(', '))
|
42
43
|
end
|
43
44
|
|
44
|
-
def
|
45
|
-
|
45
|
+
def handle_init_errors
|
46
|
+
errors << Requests::Error.new(
|
47
|
+
'Veuillez renseigner une url ex: https://pro.dendreo.com/my_company/api'
|
48
|
+
) if @url.nil? or @url == ''
|
49
|
+
|
50
|
+
errors << Requests::Error.new(
|
51
|
+
'Veuillez renseigner une clé API'
|
52
|
+
) if @api_key.nil? or @api_key == ''
|
46
53
|
end
|
47
54
|
end
|
48
55
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dendreo
|
4
|
+
class Request
|
5
|
+
attr_accessor :errors, :data
|
6
|
+
|
7
|
+
def initialize(base_url:, api_key:)
|
8
|
+
@url = base_url
|
9
|
+
@api_key = api_key
|
10
|
+
@errors = []
|
11
|
+
@form_data = nil
|
12
|
+
@url_data = nil
|
13
|
+
@request = nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(http_method:, endpoint:, args: {})
|
17
|
+
update_data(args)
|
18
|
+
handle_call_errors(http_method, endpoint, args)
|
19
|
+
execute(
|
20
|
+
http_method,
|
21
|
+
Requests::Url.new(@url, endpoint, @url_data, @api_key).complete_url,
|
22
|
+
@form_data,
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def update_data(args)
|
29
|
+
@form_data = args[:form_data] || []
|
30
|
+
@url_data = args[:url_data] || []
|
31
|
+
end
|
32
|
+
|
33
|
+
def execute(http_method, url, options = {})
|
34
|
+
@request = RestClient::Request.execute(
|
35
|
+
url: url,
|
36
|
+
method: http_method,
|
37
|
+
payload: options,
|
38
|
+
)
|
39
|
+
response_json(@request)
|
40
|
+
rescue SocketError => e
|
41
|
+
errors << Requests::Error.new('Veuillez renseigner une url ex: https://pro.dendreo.com/my_company/api')
|
42
|
+
rescue RestClient::ExceptionWithResponse => e
|
43
|
+
response_json(e.response)
|
44
|
+
end
|
45
|
+
|
46
|
+
def response_json(result)
|
47
|
+
JSON.parse(result == '' ? '[{}]' : result)
|
48
|
+
end
|
49
|
+
|
50
|
+
def handle_call_errors(http_method, endpoint, args = {})
|
51
|
+
errors << Requests::Error.new(
|
52
|
+
'Veuillez renseigner une méthode de requête ex: :post, :get, :delete'
|
53
|
+
) unless http_method
|
54
|
+
|
55
|
+
errors << Requests::Error.new(
|
56
|
+
'Veuillez renseigner une méthode de requête ex: :participants'
|
57
|
+
) unless endpoint
|
58
|
+
|
59
|
+
errors << Requests::Error.new(
|
60
|
+
'La data est vide sur une requête :post'
|
61
|
+
) if http_method == :post && args[:form_data].empty?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_String_literal: true
|
2
|
+
|
3
|
+
module Dendreo
|
4
|
+
module Requests
|
5
|
+
class Url
|
6
|
+
attr_reader :complete_url
|
7
|
+
|
8
|
+
def initialize(url, endpoint, url_data, api_key)
|
9
|
+
@endpoint = endpoint.to_s
|
10
|
+
@url_data = url_data
|
11
|
+
@url = url
|
12
|
+
@api_key = api_key
|
13
|
+
@complete_url = build_complete_url
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def build_data_url
|
19
|
+
@url_data.map do |k, v|
|
20
|
+
"#{k}=#{v}"
|
21
|
+
end.join('&')
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_url
|
25
|
+
return '' if @url_data&.empty?
|
26
|
+
|
27
|
+
build_data_url
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_complete_url
|
31
|
+
"#{@url}/#{@endpoint}.php?key=#{@api_key}&#{build_url}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/dendreo/version.rb
CHANGED
metadata
CHANGED
@@ -1,57 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Dendreo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ronan louarn
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rest-client
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
description: Simple gem for Dendreo CRM API
|
70
84
|
email:
|
71
85
|
- ronan33720@hotmail.Com
|
@@ -75,12 +89,14 @@ extra_rdoc_files: []
|
|
75
89
|
files:
|
76
90
|
- ".gitignore"
|
77
91
|
- ".rspec"
|
92
|
+
- ".ruby-version"
|
78
93
|
- ".travis.yml"
|
79
94
|
- Dendreo-1.0.0.gem
|
80
95
|
- Dendreo-1.0.1.gem
|
81
96
|
- Dendreo-1.0.2.gem
|
82
97
|
- Dendreo-1.0.3.gem
|
83
98
|
- Dendreo-1.0.4.gem
|
99
|
+
- Dendreo-1.1.0.gem
|
84
100
|
- Gemfile
|
85
101
|
- LICENSE.txt
|
86
102
|
- README.md
|
@@ -89,6 +105,9 @@ files:
|
|
89
105
|
- bin/setup
|
90
106
|
- dendreo.gemspec
|
91
107
|
- lib/dendreo.rb
|
108
|
+
- lib/dendreo/request.rb
|
109
|
+
- lib/dendreo/requests/error.rb
|
110
|
+
- lib/dendreo/requests/url.rb
|
92
111
|
- lib/dendreo/version.rb
|
93
112
|
homepage: http://lr-dev.fr
|
94
113
|
licenses:
|
@@ -110,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
129
|
- !ruby/object:Gem::Version
|
111
130
|
version: '0'
|
112
131
|
requirements: []
|
113
|
-
|
114
|
-
rubygems_version: 2.6.11
|
132
|
+
rubygems_version: 3.1.2
|
115
133
|
signing_key:
|
116
134
|
specification_version: 4
|
117
135
|
summary: Simple gem for Dendreo CRM API
|