agx 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/agx/content/client.rb +22 -22
- data/lib/agx/sync/client.rb +15 -15
- data/lib/agx/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: cc30295d8784ea06646dec1957a98f5790267367ff7400cc945ef83075c8a0ae
|
4
|
+
data.tar.gz: fcd11958bd999df6292925fc94235809ae7000bba25a065b373bd53ce60fbfff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a2ac37901fcc2911f5bd32d508dab2f75124f3a23d229922a8320228a11cec38f4dcc619de87125b81a9c31d642ec803fcf70d8fe47c6328748e844b6df11b9
|
7
|
+
data.tar.gz: 8c0548b7c39144bc89c6212e4919a5074aff73e599c04168885cc638082c627ce7cf4330bbe4cec985875fded6f4bd6d5114eb5c48fe9a0f81ed77a454617068
|
data/README.md
CHANGED
@@ -33,6 +33,8 @@ Setup agX Content Client (OAuth 2 Client Credentials Flow)
|
|
33
33
|
client_secret: "your_client_secret",
|
34
34
|
version: "v1" # optional
|
35
35
|
prod: true # optional, false for QA
|
36
|
+
access_token: "token_if_stored", # optional
|
37
|
+
expires_at: "token_expires_at_if_stored" # optional
|
36
38
|
)
|
37
39
|
```
|
38
40
|
|
data/lib/agx/content/client.rb
CHANGED
@@ -3,7 +3,7 @@ module Agx
|
|
3
3
|
class Client
|
4
4
|
attr_accessor :client_id, :client_secret, :site, :token_url, :version
|
5
5
|
|
6
|
-
def initialize(client_id: nil, client_secret: nil, version: nil, prod: true)
|
6
|
+
def initialize(client_id: nil, client_secret: nil, version: nil, prod: true, access_token: nil, expires_at: nil)
|
7
7
|
domain = (prod ? "agxplatform.com" : "qaagxplatform.com")
|
8
8
|
@client_id = client_id || ENV['AGX_CONTENT_CLIENT_ID']
|
9
9
|
@client_secret = client_secret || ENV['AGX_CONTENT_CLIENT_SECRET']
|
@@ -12,8 +12,8 @@ module Agx
|
|
12
12
|
@version = version || "v1"
|
13
13
|
@client = set_client
|
14
14
|
@token = {
|
15
|
-
access_token:
|
16
|
-
expires_at:
|
15
|
+
access_token: access_token,
|
16
|
+
expires_at: expires_at
|
17
17
|
}
|
18
18
|
end
|
19
19
|
|
@@ -29,6 +29,25 @@ module Agx
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def current_token
|
33
|
+
if @token[:access_token].nil? || @token[:expires_at].nil?
|
34
|
+
new_token = api_token
|
35
|
+
else
|
36
|
+
oauth_token = OAuth2::AccessToken.new(
|
37
|
+
@client,
|
38
|
+
@token[:access_token],
|
39
|
+
{expires_at: @token[:expires_at]}
|
40
|
+
)
|
41
|
+
if Time.now.to_i + 180 >= @token[:expires_at] || oauth_token.expired?
|
42
|
+
new_token = api_token
|
43
|
+
else
|
44
|
+
new_token = oauth_token
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
new_token
|
49
|
+
end
|
50
|
+
|
32
51
|
protected
|
33
52
|
|
34
53
|
def validate_credentials
|
@@ -74,25 +93,6 @@ module Agx
|
|
74
93
|
raise error_to_raise
|
75
94
|
end
|
76
95
|
|
77
|
-
def current_token
|
78
|
-
if @token[:access_token].nil? || @token[:expires_at].nil?
|
79
|
-
new_token = api_token
|
80
|
-
else
|
81
|
-
oauth_token = OAuth2::AccessToken.new(
|
82
|
-
@client,
|
83
|
-
@token[:access_token],
|
84
|
-
{expires_at: @token[:expires_at]}
|
85
|
-
)
|
86
|
-
if Time.now.to_i + 180 >= @token[:expires_at] || oauth_token.expired?
|
87
|
-
new_token = api_token
|
88
|
-
else
|
89
|
-
new_token = oauth_token
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
new_token
|
94
|
-
end
|
95
|
-
|
96
96
|
def api_token
|
97
97
|
begin
|
98
98
|
new_token = @client.client_credentials.get_token(
|
data/lib/agx/sync/client.rb
CHANGED
@@ -116,6 +116,21 @@ module Agx
|
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
119
|
+
def current_token
|
120
|
+
new_token = OAuth2::AccessToken.new @client, @token[:access_token], {
|
121
|
+
expires_at: @token[:expires_at],
|
122
|
+
refresh_token: @token[:refresh_token]
|
123
|
+
}
|
124
|
+
if Time.now.to_i + 90 >= @token[:expires_at]
|
125
|
+
new_token = new_token.refresh!
|
126
|
+
@token[:access_token] = new_token.token
|
127
|
+
@token[:refresh_token] = new_token.refresh_token
|
128
|
+
@token[:expires_at] = new_token.expires_at
|
129
|
+
end
|
130
|
+
|
131
|
+
new_token
|
132
|
+
end
|
133
|
+
|
119
134
|
protected
|
120
135
|
|
121
136
|
def validate_credentials
|
@@ -179,21 +194,6 @@ module Agx
|
|
179
194
|
raise error_to_raise
|
180
195
|
end
|
181
196
|
|
182
|
-
def current_token
|
183
|
-
new_token = OAuth2::AccessToken.new @client, @token[:access_token], {
|
184
|
-
expires_at: @token[:expires_at],
|
185
|
-
refresh_token: @token[:refresh_token]
|
186
|
-
}
|
187
|
-
if Time.now.to_i + 90 >= @token[:expires_at]
|
188
|
-
new_token = new_token.refresh!
|
189
|
-
@token[:access_token] = new_token.token
|
190
|
-
@token[:refresh_token] = new_token.refresh_token
|
191
|
-
@token[:expires_at] = new_token.expires_at
|
192
|
-
end
|
193
|
-
|
194
|
-
new_token
|
195
|
-
end
|
196
|
-
|
197
197
|
def set_client
|
198
198
|
@client = OAuth2::Client.new(
|
199
199
|
@client_id,
|
data/lib/agx/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: agx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryce Johnston
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|