Dendreo 1.0.2 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: be5be5e5e6ceb74626673f5a5a3fb76a3b34611f
4
- data.tar.gz: 92e9cfbbee2d84f649753ae66bcb313064b22ed4
2
+ SHA256:
3
+ metadata.gz: d5e251ec6787004223c11a9f86927755a51e33e1593347d2fc836cff2b357904
4
+ data.tar.gz: 708399f2691f945b04c9f37956525d8d1ed2d6b40f00ab38e81d525938628464
5
5
  SHA512:
6
- metadata.gz: ffee2de89031124dbbb9af5917a5691f3c5d70d4f64f0967eeb8bc34447e46f8697972a16e512d8645fc271a1a329161276ed434048d344d6e15fd3e152066e1
7
- data.tar.gz: eb2400411556691be6f9f1ec837ed94b3d577aa51f33c7fc20a7f8895695d4313871909c5e72982db78b23819e6f36c8834562aa686665cec5834f2bd6da5908
6
+ metadata.gz: 371b50ebfe3db73d280bf4637874719572b75006633c699a2198fef68e66d502ddbdee5e988d417597fda4ff9dcef97270fdc7192fc0c47deaf5926c17927b61
7
+ data.tar.gz: c939bc7d33ddfdea8ea83dace82ec9f2eee86469bc1b02aa012700a1ff21fbae41253bac2288a1039f092d3767480b1b842660f86f04caba8c893621eefc222a
data/.gitignore CHANGED
@@ -10,3 +10,5 @@
10
10
 
11
11
  # rspec failure tracking
12
12
  .rspec_status
13
+ .byebug_history
14
+ .idea/
@@ -0,0 +1 @@
1
+ 2.7.1
data/README.md CHANGED
@@ -8,7 +8,7 @@ Gem pour l'API du CRM Dendreo.
8
8
  Ajoutez cette ligne à votre Gemfile:
9
9
 
10
10
  ```ruby
11
- gem 'dendreo'
11
+ gem 'Dendreo'
12
12
  ```
13
13
 
14
14
  Bien entendu:
@@ -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("https://pro.dendreo.com/masociété/api", "MaCleApi")
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,70 +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 "method_missing", il vous suffira donc de récupérer le nom de la resource que vous souhaitez récupérer, ajouter ou modifier (hé oui c'est possible!).
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. => "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"
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: "get")
98
+ dendreo.participants(method: 'get')
70
99
 
71
100
  # Renvoi le particpant qui a l'id en question
72
- dendreo.participants(method: "get", datas: {id_participant: 1345})
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: "get", datas: {email: "mon_email@gmail.com"})
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: "get", datas: {search: "Un joli nom ou ce que vous souhaitez id, email, commentaires etc.."})
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 "id_participant" par "id" tout court et d'ajouter un "id_add" qui contiendra un id d'administrateur.
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
- Je porte votre attention sur le fait que si vous modifiez un utilisateur il faudra re-rentrer la totalité des données, même si elles étaient déjà existantes auparavant, sinon il ne les gardera pas. Vous pouvez donc utiliser la méthode get avec l'id en question pour récupérer les informations avant de faire vôtre modification.
86
-
87
- L'API est faite comme cela. Ceci n'est pas encore spécifié dans la documentation.
88
114
  Faites appel au support dendreo pour plus d'informations, ils sont très réactifs equipe@dendreo.com .
89
115
 
90
116
  ```ruby
91
117
  # Créer un participant
92
- dendreo.participants(method: "post", datas: {nom: "nouveau nom", prenom: "toto", civilite: "M.", email: "toto@gmail.com", id_add: 2})
118
+ dendreo.participants(method: 'post', form_data: { nom: 'nouveau nom', prenom: 'toto', civilite: 'M.', email: 'toto@gmail.com', id_add: 2 })
93
119
 
94
- # Modifier un participant existant (Attention, bien remplacer "id" par "id_participant" et ajouter un "id_add" pour
120
+ # Modifier un participant existant (Attention, bien remplacer 'id' par 'id_participant' et ajouter un 'id_add' pour
95
121
  # s'identifier en admin sur la mise à jour.)
96
- dendreo.participants(method: "post", datas: {id_participant: 1345, nom: "nouveau nom", civilite: "M.", id_add: 2})
122
+ dendreo.participants(method: 'post', url_data: { id_participant: 1345 }, form_data: { nom: 'nouveau nom', civilite: 'M.', id_add: 2 })
97
123
 
98
- # Supprimer un participant (attention, il n'y a pas de methode "delete" sûr tous les endpoints)
99
- dendreo.participants(method: "delete", datas: {id_participant: 1345})
124
+ # Supprimer un participant (attention, il n'y a pas de methode 'delete' sur tous les endpoints)
125
+ dendreo.participants(method: 'delete', url_data: { id_participant: 1345 })
100
126
 
101
127
  ```
102
- Cet exemple fonctionne sur toutes les ressources sauf les "particuliers" que l'on peut créer mais pas modifier.
103
-
104
128
 
105
129
  ## Contribution
106
130
 
@@ -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 "bundler", "~> 1.15"
34
- spec.add_development_dependency "rake", "~> 10.0"
35
- spec.add_development_dependency "rspec", "~> 3.0"
36
- spec.add_development_dependency "rest-client"
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
@@ -1,48 +1,55 @@
1
- require "dendreo/version"
2
- require "json"
3
- require 'net/http'
4
- require "rest-client"
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 #exemple = https://pro.dendreo.com/my_company/api
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
- method_name_string = method_name.to_s
17
- request_method = args.first[:method]
18
- datas = args.any? ? args.first[:datas] : {}
19
- base_url = "#{@url}/#{method_name_string}.php?key=#{@api_key}"
20
- case request_method
21
- when "get"
22
- send_it(:get, "#{base_url}#{format_args_to_url(datas)}")
23
- when "post"
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&.dig(: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 send_it(http_method, url, options = {})
35
- hsh = {url: url, method: http_method }
36
- hsh.merge!(payload: options) if http_method == :post
37
- response_json(RestClient::Request.execute(hsh))
38
- end
37
+ def handle_errors
38
+ handle_init_errors
39
+ @errors += @request.errors
40
+ return if @errors.empty?
39
41
 
40
- def format_args_to_url(args = {})
41
- args.any? ? args.map{|k, v| k == args.keys.first ? "&#{k}=#{v}" : "#{k}=#{v}" }.join("&") : ""
42
+ raise Requests::Error.new(@errors.map(&:message).uniq.join(', '))
42
43
  end
43
44
 
44
- def response_json(result)
45
- JSON.parse(result == "" ? "[{}]" : result)
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,70 @@
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)
19
+ execute(
20
+ http_method,
21
+ endpoint,
22
+ Requests::Url.new(@url, endpoint, @url_data, @api_key).complete_url,
23
+ @form_data,
24
+ )
25
+ end
26
+
27
+ private
28
+
29
+ def update_data(args)
30
+ @form_data = args&.dig(:form_data) || []
31
+ @url_data = args&.dig(:url_data) || []
32
+ end
33
+
34
+ def execute(http_method, endpoint, url, options = {})
35
+ @request = RestClient::Request.execute(
36
+ url: url,
37
+ method: http_method,
38
+ payload: options,
39
+ )
40
+ response_json(@request)
41
+ rescue SocketError => _e
42
+ errors << Requests::Error.new('Veuillez renseigner une url ex: https://pro.dendreo.com/my_company/api')
43
+ rescue RestClient::ExceptionWithResponse => e
44
+ return response_json(e.response) if e.http_headers[:content_type] == 'application/json'
45
+
46
+ e.to_json
47
+ rescue => _e
48
+ handle_call_errors(http_method, endpoint)
49
+ end
50
+
51
+ def response_json(result)
52
+ JSON.parse(result == '' ? '[{}]' : result)
53
+ end
54
+
55
+ def handle_call_errors(http_method, endpoint)
56
+ errors << Requests::Error.new(
57
+ 'Veuillez renseigner une méthode de requête ex: :post, :get, :delete'
58
+ ) unless http_method
59
+
60
+ errors << Requests::Error.new(
61
+ 'Veuillez renseigner une méthode de requête ex: :participants'
62
+ ) unless endpoint
63
+ return unless http_method == :post
64
+
65
+ errors << Requests::Error.new(
66
+ 'La data à mettre à jour (form_data:) est manquante sur une requête :post'
67
+ ) if @form_data.empty?
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dendreo
4
+ module Requests
5
+ class Error < StandardError
6
+ def initialize(msg)
7
+ super(msg)
8
+ end
9
+ end
10
+ end
11
+ 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
@@ -1,3 +1,3 @@
1
1
  module Dendreo
2
- VERSION = "1.0.2"
2
+ VERSION = '1.1.2'
3
3
  end
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.0.2
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ronan louarn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-11 00:00:00.000000000 Z
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: '1.15'
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: '1.15'
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: '10.0'
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: '10.0'
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: '3.0'
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: '3.0'
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,9 +89,8 @@ extra_rdoc_files: []
75
89
  files:
76
90
  - ".gitignore"
77
91
  - ".rspec"
92
+ - ".ruby-version"
78
93
  - ".travis.yml"
79
- - Dendreo-1.0.0.gem
80
- - Dendreo-1.0.1.gem
81
94
  - Gemfile
82
95
  - LICENSE.txt
83
96
  - README.md
@@ -86,6 +99,9 @@ files:
86
99
  - bin/setup
87
100
  - dendreo.gemspec
88
101
  - lib/dendreo.rb
102
+ - lib/dendreo/request.rb
103
+ - lib/dendreo/requests/error.rb
104
+ - lib/dendreo/requests/url.rb
89
105
  - lib/dendreo/version.rb
90
106
  homepage: http://lr-dev.fr
91
107
  licenses:
@@ -107,8 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
123
  - !ruby/object:Gem::Version
108
124
  version: '0'
109
125
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.6.11
126
+ rubygems_version: 3.1.2
112
127
  signing_key:
113
128
  specification_version: 4
114
129
  summary: Simple gem for Dendreo CRM API
Binary file
Binary file