libriciel 0.1.2 → 0.1.3

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
2
  SHA256:
3
- metadata.gz: f75691fcd516c56ad41b703c8d406685c4ccae5ba84b2709f8509f885949aed8
4
- data.tar.gz: f4b57f164d625b13a1ec678a74d7b5a1f940c90154dc84b4b7b7aa3010ad87ea
3
+ metadata.gz: 25d59cf10cefb65f3ff969ac6d14543f9360a3e4226d8bfdb5f77648ef9b4033
4
+ data.tar.gz: 9f6029ed8be0b7985ebfecd34f5187327192c0c4f809865333ae426218fec878
5
5
  SHA512:
6
- metadata.gz: 0bac166ab2ed5759751478263e48c96078ff583d53b528d7168d1ffaedc13f8acdc6a607f1b515cd4a7d6a114a7a9c19a049e8f9eedd687255aac10b49c56fee
7
- data.tar.gz: 7f07b9e67f2a353461e381f385c4769c6c9abde965559658f910e7c3332964dfae6a73fb55fd63dc3bda474f9c8d6a74e3e63477bda7b688f801a8ce08ce7574
6
+ metadata.gz: 7cc25a0c0dacd66878e8923474db829c59cc84838d5efe02b6f496c6f9f7036734a64c52b607972a7f8fd23a0da2067f3c8e08ece8292f7b053ea92779b3d643
7
+ data.tar.gz: 425e7231941de2786b4cc5c8bb7951654af5b94bc9a092b9115751cf008ac38282180d294596da9a103918561e8f52224d98c0884b5a3059a1b63dd809fadf0b
@@ -1,3 +1,3 @@
1
1
  module Libriciel
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/libriciel.rb CHANGED
@@ -9,10 +9,31 @@ module Libriciel
9
9
 
10
10
  # Class ApiXivo to use Xivo Api
11
11
  class ApiXivo
12
- # Génération du token permettant l'authent ADMIN (ATTENTION) pour l'api Xivo
13
- def self.token_generate(user, pass)
14
12
 
15
- couplae_base64_pass_user = base64()
13
+ def self.token_validation(token)
14
+ url = URI("https://xivo.libriciel.fr:9497/0.1/token/#{token}")
15
+
16
+ http = Net::HTTP.new(url.host, url.port)
17
+ http.use_ssl = true
18
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
19
+
20
+ request = Net::HTTP::Head.new(url)
21
+ request["content-type"] = 'application/json'
22
+ request["cache-control"] = 'no-cache'
23
+
24
+ response = http.request(request)
25
+
26
+ if response.message == "NO CONTENT"
27
+ return true
28
+
29
+ else
30
+ return false
31
+
32
+ end
33
+ end
34
+
35
+ # Génération du token permettant l'authent ADMIN (ATTENTION) pour l'api Xivo
36
+ def self.token_generate(base64_enc)
16
37
  url = URI("https://xivo.libriciel.fr:9497/0.1/token")
17
38
 
18
39
  http = Net::HTTP.new(url.host, url.port)
@@ -21,13 +42,20 @@ module Libriciel
21
42
 
22
43
  request = Net::HTTP::Post.new(url)
23
44
  request["content-type"] = 'application/json'
24
- request["authorization"] = "Basic #{couplae_base64_pass_user}"
45
+ request["authorization"] = "Basic #{base64_enc}"
25
46
  request["cache-control"] = 'no-cache'
26
47
 
27
- request.body = "{\n \"backend\": \"xivo_admin\",\n \"expiration\": 5\n}"
48
+ request.body = "{\n \"backend\": \"xivo_admin\",\n \"expiration\": 100\n}"
28
49
 
29
50
  response = http.request(request)
30
- token = JSON.parse(response.read_body)['data']['token']
51
+ reponse_parsing = JSON.parse(response.read_body)
52
+
53
+ if !reponse_parsing.include?("data")
54
+ puts reponse_parsing["reason"]
55
+ exit 223
56
+ else
57
+ token = reponse_parsing['data']['token']
58
+ end
31
59
 
32
60
  return token
33
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libriciel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Axel CHEVRIER
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-19 00:00:00.000000000 Z
11
+ date: 2019-07-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler