plutora_rest 0.0.13 → 0.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/plutora_rest.rb +41 -0
- data/lib/plutora_rest/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af752f0cf2bd2acbb29fe2d25cd4f371d1e1a3cd
|
4
|
+
data.tar.gz: 8cd2ca23af496bdf34df752294e1780590098c3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caaa89f0b62e0a8519df19adbde0357e97c743ccea1be5cbc1013fec05617fc3a83ff8768e4756348765f4bc5668e9e919367dfe2722c50eef634e478ee6e5e0
|
7
|
+
data.tar.gz: 929de371644b8692a47c7faf6da118a92865bccfa3f2d69c8b9cab1d1b1765982f6b20504d70d41042ddc13c9b07423d7b5c858b2bfbac6aeef87c3e9fecbf07
|
data/lib/plutora_rest.rb
CHANGED
@@ -34,10 +34,51 @@ module PlutoraRest
|
|
34
34
|
|
35
35
|
rConnect=plutora_post({:url => oauth_url, :params => params, :headers => headers})
|
36
36
|
rConnect=JSON.parse(rConnect)
|
37
|
+
|
37
38
|
@token=rConnect['access_token']
|
39
|
+
@expires_in=rConnect['expires_in']
|
40
|
+
@expiresAt=DateTime.now + @expires_in.to_i.seconds
|
41
|
+
@refresh_token=rConnect['refresh_token']
|
42
|
+
|
43
|
+
@oauthURL=oauth_url
|
44
|
+
@clientID=opts[:client_id]
|
45
|
+
@clientSecret=opts[:client_secret]
|
46
|
+
|
38
47
|
return @token
|
39
48
|
end
|
40
49
|
|
50
|
+
#---- Refresh Token If Expired ----
|
51
|
+
def refresh_token_if_expired
|
52
|
+
if token_expired?
|
53
|
+
param={'grant_type' => 'refresh_token',
|
54
|
+
'refresh_token' => @refresh_token,
|
55
|
+
'client_id' => @clientID,
|
56
|
+
'client_secret' => @clientSecret
|
57
|
+
}
|
58
|
+
|
59
|
+
headers = {'Accept' => 'application/json',
|
60
|
+
'Content-Type' => 'application/x-www-form-urlencoded'
|
61
|
+
}
|
62
|
+
|
63
|
+
refreshConnect=plutora_post({:url => @oauthURL, :params => params, :headers =>})
|
64
|
+
refreshConnect=JSON.parse(refreshConnect)
|
65
|
+
|
66
|
+
@token=refreshConnect['access_token']
|
67
|
+
@expires_in=refreshConnect['expires_in']
|
68
|
+
@expiresAt=DateTime.now + @expires_in.to_i.seconds
|
69
|
+
@refresh_token=refreshConnect['refresh_token']
|
70
|
+
|
71
|
+
return @token
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
#---- Token Expired? ----
|
76
|
+
def token_expired?
|
77
|
+
expiry=Time.at(@expiresAt)
|
78
|
+
return true if expiry < Time.now
|
79
|
+
false
|
80
|
+
end
|
81
|
+
|
41
82
|
#---- POST REST Call ----
|
42
83
|
def plutora_post(opts)
|
43
84
|
resp=RestClient.post(opts[:url], opts[:params], opts[:headers])
|
data/lib/plutora_rest/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plutora_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ProjectYeti
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-03-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|