orange_sms_api 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/orange_sms_api/client.rb +1 -0
- data/lib/orange_sms_api/configuration.rb +2 -1
- data/lib/orange_sms_api/interceptor.rb +68 -27
- data/lib/orange_sms_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04b48a1b630fe2954629e29933e7aa9f70b11dd33bbb4fb3271de3d2d081992c
|
4
|
+
data.tar.gz: 00b889d32c506fe40a5dcaf0816c227e74e1612123712080731c025e9744dd1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3d2495b83aea6da3494ca00fd946e371db1c43de9eeb642e30ca16ae8981d3a1b79dd7c90bb5eb0f7a4ebc63cc0a13dbc2ee54999dc1f92ac7c2632927a4cd34
|
7
|
+
data.tar.gz: 4d8a4b1b48033b36c66ecfcfc89940f76fcf5f50b244a7b43702174d1d35518c74dddccd8bca81a8411ac6378a7b675146822f22580a38245aecbe4b1a9e4b25
|
data/Gemfile.lock
CHANGED
@@ -3,42 +3,81 @@ module OrangeSmsApi
|
|
3
3
|
module HttpInterceptor
|
4
4
|
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
|
7
|
+
def api_configured?
|
8
|
+
base_url = OrangeSmsApi.configuration.base_url
|
9
|
+
authorization_header = OrangeSmsApi.configuration.authorization_header
|
10
|
+
authentication_endpoint = OrangeSmsApi.configuration.authentication_endpoint
|
11
|
+
|
12
|
+
if base_url.present? && authorization_header.present? && authentication_endpoint.present?
|
13
|
+
return true
|
14
|
+
else
|
15
|
+
return false
|
16
|
+
end
|
8
17
|
end
|
9
18
|
|
19
|
+
def access_token_validity?
|
20
|
+
access_token_date = OrangeSmsApi.configuration.access_token_date if OrangeSmsApi.configuration.access_token_date
|
21
|
+
current_date = Date.today
|
22
|
+
if access_token_date.present? && (current_date - access_token_date) <= 90
|
23
|
+
|
24
|
+
return true
|
25
|
+
else
|
26
|
+
return false
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
10
30
|
|
11
31
|
def get_token
|
32
|
+
if api_configured?
|
33
|
+
unless access_token_validity?
|
34
|
+
# Inialize a new connection.
|
35
|
+
conn = Faraday.new(OrangeSmsApi.configuration.base_url,
|
36
|
+
ssl: {
|
37
|
+
ca_path: "/usr/lib/ssl/certs"}
|
38
|
+
)
|
12
39
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
40
|
+
# Making a http post request
|
41
|
+
response = conn.post do |req|
|
42
|
+
req.url OrangeSmsApi.configuration.authentication_endpoint
|
43
|
+
req.headers['Content-Type'] = 'application/x-www-form-urlencoded'
|
44
|
+
req.headers['Authorization'] = OrangeSmsApi.configuration.authorization_header
|
45
|
+
req.body = "grant_type=client_credentials"
|
46
|
+
end
|
19
47
|
|
48
|
+
if response.status == 200
|
20
49
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
50
|
+
response_body = JSON.parse(response.body)
|
51
|
+
|
52
|
+
OrangeSmsApi.configuration.access_token = response_body["access_token"]
|
53
|
+
OrangeSmsApi.configuration.access_token_date = Date.today
|
54
|
+
|
55
|
+
puts "LE TOKEN: #{OrangeSmsApi.configuration.access_token}"
|
56
|
+
puts "TOKEN DATE: #{OrangeSmsApi.configuration.access_token_date}"
|
27
57
|
|
28
|
-
|
29
|
-
response_body = response.body
|
30
|
-
OrangeSmsApi.configuration.access_token = response_body.access_token
|
31
|
-
end
|
58
|
+
elsif response.status == 401
|
32
59
|
|
60
|
+
puts "RESPONSE BODY: #{response_body}"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
else
|
65
|
+
puts "API configuration error"
|
66
|
+
end
|
33
67
|
end
|
34
68
|
|
69
|
+
|
70
|
+
|
71
|
+
|
35
72
|
def post(endpoint, message)
|
36
73
|
|
37
74
|
|
38
|
-
if
|
39
|
-
|
75
|
+
if api_configured?
|
76
|
+
|
77
|
+
get_token
|
78
|
+
|
40
79
|
# Inialize a new connection.
|
41
|
-
conn = Faraday.new(
|
80
|
+
conn = Faraday.new(OrangeSmsApi.configuration.base_url)
|
42
81
|
|
43
82
|
payload = {:outboundSMSMessageRequest => {
|
44
83
|
:address => "tel:+#{message[:recipient_phone_number]}" ,
|
@@ -50,20 +89,22 @@ module OrangeSmsApi
|
|
50
89
|
}
|
51
90
|
|
52
91
|
response = conn.post do |req|
|
53
|
-
req.url
|
54
|
-
req.headers['Content-Type'] = 'application/
|
92
|
+
req.url endpoint + "/tel%3A%2B#{OrangeSmsApi.configuration.dev_phone_number}/requests"
|
93
|
+
req.headers['Content-Type'] = 'application/json'
|
55
94
|
req.headers['Authorization'] = 'Bearer ' + OrangeSmsApi.configuration.access_token
|
56
95
|
req.body = payload.to_json
|
57
96
|
end
|
58
97
|
|
59
98
|
|
60
99
|
if response.status == 200
|
61
|
-
puts "LA REPONSE DE LA REQUETTE EST: #{response.
|
100
|
+
puts "LA REPONSE DE LA REQUETTE EST: #{response.body}"
|
101
|
+
|
62
102
|
|
63
103
|
return response
|
64
|
-
|
65
|
-
puts "LA REPONSE DE LA REQUETTE EST: #{response.
|
66
|
-
|
104
|
+
elsif response.status == 401
|
105
|
+
puts "LA REPONSE DE LA REQUETTE EST: #{response.body}"
|
106
|
+
|
107
|
+
#get_token
|
67
108
|
end
|
68
109
|
else
|
69
110
|
render text: "Invalid API Base!"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orange_sms_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thkernel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-06-
|
11
|
+
date: 2019-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|