Dendreo 1.0.1 → 1.1.1

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: 63be47926eb0cd7bb5ab066e23190dfece71b99f
4
- data.tar.gz: d07400d7f2e1feab51692777c552f50b0618423a
2
+ SHA256:
3
+ metadata.gz: 80deec797bcba45bc51d99def32ab84d15796a83e07e1219b6c379702d788ee5
4
+ data.tar.gz: ba2118cdb3d05e7f0f6e875634eeffeb2354ed98355ef0df5326d6d1a1081b76
5
5
  SHA512:
6
- metadata.gz: f491551e788fbcb198ea18ecf74e0f168f8e129171bf217d08d6bb03340c94465435702246de752c1f9110ae2b4f4fd3a042ac4637598fbb017c6e5497e823ac
7
- data.tar.gz: 0bbcec8f155706ffd246dc4724a9ba1ea168465b4d10dc2cb52134137fc2a1db4b17dab7ce7286e3678400de54175298034dfe9dc82b61b048d89400f90e19b2
6
+ metadata.gz: 6d28f4d2e4b3410911cc932d471b797509872bb3f8d1b1cb08dacec9187d31f43ac1a06c72069e5d20ab1f249c4a464331f32d42cdc935e5950a3ee79062c84a
7
+ data.tar.gz: 145b8f63c3d285a33b6c2a7c98b39e423ee1d184237ec43fc9c4e0f7dd7350c160a2c95237970c9d6b39c020959fae3c9d60c8093bf07a861c829e3a726adf8d
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
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
data/Gemfile CHANGED
@@ -4,3 +4,5 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in dendreo.gemspec
6
6
  gemspec
7
+
8
+
data/README.md CHANGED
@@ -5,17 +5,17 @@ Gem pour l'API du CRM Dendreo.
5
5
 
6
6
  ## Installation
7
7
 
8
- Ajoutez cette à votre Gemfile:
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:
15
15
 
16
16
  $ bundle
17
17
 
18
- Ou installez le gem vous-même:
18
+ Ou installez la gem vous-même:
19
19
 
20
20
  $ gem install dendreo
21
21
 
@@ -25,7 +25,7 @@ Ou installez le 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,47 +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'
63
+
64
+
65
+ Arguments:
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
+ ```
93
+
46
94
  Pour les participants ( GET https://pro.dendreo.com/demo/api/participants.php?)
47
95
 
48
96
  ```ruby
49
97
  # Renvoi tous les particpants
50
- dendreo.participants(method: "get")
98
+ dendreo.participants(method: 'get')
51
99
 
52
100
  # Renvoi le particpant qui a l'id en question
53
- dendreo.participants(method: "get", datas: {id_participant: 1345})
101
+ dendreo.participants(method: 'get', url_data: { id_participant: 1345 })
54
102
 
55
103
  # Renvoi le ou les particpants qui ont l'email en question
56
- dendreo.participants(method: "get", datas: {email: "mon_email@gmail.com"})
104
+ dendreo.participants(method: 'get', url_data: { email: 'mon_email@gmail.com' })
57
105
 
58
106
  #Renvoi le ou les particpants qui ont le commentaire en question
59
- 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..' })
60
108
  ```
61
109
 
62
110
  Ajouter ou modifier un participant.
63
111
 
64
- 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.
65
-
66
- 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.
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.
67
113
 
68
- L'API est faite comme cela, je n'y peut rien. Ceci n'est pas encore spécifié dans la documentation.
69
114
  Faites appel au support dendreo pour plus d'informations, ils sont très réactifs equipe@dendreo.com .
70
115
 
71
116
  ```ruby
72
117
  # Créer un participant
73
- 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 })
74
119
 
75
- # Modifier un participant existant
76
- dendreo.participants(method: "post", datas: {id: 1345, nom: "nouveau nom", civilite: "M.", id_add: 2})
120
+ # Modifier un participant existant (Attention, bien remplacer 'id' par 'id_participant' et ajouter un 'id_add' pour
121
+ # s'identifier en admin sur la mise à jour.)
122
+ dendreo.participants(method: 'post', url_data: { id_participant: 1345 }, form_data: { nom: 'nouveau nom', civilite: 'M.', id_add: 2 })
77
123
 
78
- ```
79
- Cet exemple fonctionne sur toutes les ressources sauf les "particuliers" que l'on peut créer mais pas modifier.
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 })
80
126
 
127
+ ```
81
128
 
82
129
  ## Contribution
83
130
 
@@ -30,7 +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"
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'
36
38
  end
@@ -1,49 +1,55 @@
1
- require "dendreo/version"
2
- require 'net/http'
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
+
3
11
  module Dendreo
4
12
  class API
5
- attr_accessor :url
6
- attr_accessor :api_key
13
+ attr_accessor :url, :api_key, :errors, :result
7
14
 
8
15
  def initialize(url, api_key)
9
- @url = url #exemple = https://pro.dendreo.com/my_company/api
16
+ @url = url # https://pro.dendreo.com/my_company/api
10
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
11
22
  end
12
23
 
13
24
  def method_missing(method_name, *args)
14
- method_name_string = method_name.to_s
15
- request_method = args.first[:method]
16
- datas = args.any? ? args.first[:datas] : {}
17
- case request_method
18
- when "get"
19
- args_formatted = format_args_to_url(datas)
20
- url = "#{@url}/#{method_name_string}.php?key=#{@api_key}#{args_formatted}"
21
- puts url
22
- get(url)
23
- when "post"
24
- post("#{@url}/#{method_name_string}.php?key=#{@api_key}", args.first[:datas])
25
- 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
26
33
  end
27
34
 
28
35
  private
29
36
 
30
- def post( url, options = {})
31
- uri = URI(url)
32
- result = Net::HTTP.post_form(uri, options)
33
- res = result == "" ? "[{}]" : result.body
34
- JSON.parse(res)
35
- end
37
+ def handle_errors
38
+ handle_init_errors
39
+ @errors += @request.errors
40
+ return if @errors.empty?
36
41
 
37
- def get(url)
38
- uri = URI(url)
39
- result = Net::HTTP.get(uri)
40
- res = result == "" ? "[{}]" : result
41
- JSON.parse(res)
42
+ raise Requests::Error.new(@errors.map(&:message).join(', '))
42
43
  end
43
44
 
44
- def format_args_to_url(args = {})
45
- args.any? ? args.map{|k, v| k == args.keys.first ? "&#{k}=#{v}" : "#{k}=#{v}" }.join("&") : ""
46
- end
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 == ''
47
49
 
50
+ errors << Requests::Error.new(
51
+ 'Veuillez renseigner une clé API'
52
+ ) if @api_key.nil? or @api_key == ''
53
+ end
48
54
  end
49
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,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.1"
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,57 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Dendreo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.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: 2017-10-14 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
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
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'
55
83
  description: Simple gem for Dendreo CRM API
56
84
  email:
57
85
  - ronan33720@hotmail.Com
@@ -61,7 +89,14 @@ extra_rdoc_files: []
61
89
  files:
62
90
  - ".gitignore"
63
91
  - ".rspec"
92
+ - ".ruby-version"
64
93
  - ".travis.yml"
94
+ - Dendreo-1.0.0.gem
95
+ - Dendreo-1.0.1.gem
96
+ - Dendreo-1.0.2.gem
97
+ - Dendreo-1.0.3.gem
98
+ - Dendreo-1.0.4.gem
99
+ - Dendreo-1.1.0.gem
65
100
  - Gemfile
66
101
  - LICENSE.txt
67
102
  - README.md
@@ -70,6 +105,9 @@ files:
70
105
  - bin/setup
71
106
  - dendreo.gemspec
72
107
  - lib/dendreo.rb
108
+ - lib/dendreo/request.rb
109
+ - lib/dendreo/requests/error.rb
110
+ - lib/dendreo/requests/url.rb
73
111
  - lib/dendreo/version.rb
74
112
  homepage: http://lr-dev.fr
75
113
  licenses:
@@ -91,8 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
129
  - !ruby/object:Gem::Version
92
130
  version: '0'
93
131
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.6.11
132
+ rubygems_version: 3.1.2
96
133
  signing_key:
97
134
  specification_version: 4
98
135
  summary: Simple gem for Dendreo CRM API