go_to_webinar 0.2.1 → 0.2.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/lib/go_to_webinar.rb +8 -8
- data/lib/go_to_webinar/auth.rb +3 -3
- data/lib/go_to_webinar/auth/client.rb +71 -69
- data/lib/go_to_webinar/auth/configuration.rb +29 -29
- data/lib/go_to_webinar/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 19769749decf1f85cdef785033508713f861605fe4f774eaef3d1c71f1415e35
|
4
|
+
data.tar.gz: dd1861bb0ee155828a73e4a70d97de4c2acb7ce49de6cf19c3d76ee789e3a299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45ae3ffb0b21c2326d60bf37b8daa912d629793b43e2ec2a30be2c434009b28eb80f55fcbc1bada32f69d80986899aad73ffeba1f6979c2c318de15df655d5af
|
7
|
+
data.tar.gz: 46b4c88cfff2aaf456754b554b1cf195f4c55e5b5379b8073f00bac5ac8cb099f7cd2efa67d9f1d05101531e227b88061531909b69dfa0854be4edb8fa2c35cf
|
data/lib/go_to_webinar.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'rest-client'
|
2
2
|
require 'json'
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
require_relative 'go_to_webinar/attendee'
|
4
|
+
require_relative 'go_to_webinar/client'
|
5
|
+
require_relative 'go_to_webinar/configuration'
|
6
|
+
require_relative 'go_to_webinar/auth'
|
7
|
+
require_relative 'go_to_webinar/registrant'
|
8
|
+
require_relative 'go_to_webinar/session'
|
9
|
+
require_relative 'go_to_webinar/version'
|
10
|
+
require_relative 'go_to_webinar/webinar'
|
11
11
|
|
12
12
|
module GoToWebinar
|
13
13
|
class << self
|
data/lib/go_to_webinar/auth.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'oauth2'
|
2
|
-
|
3
|
-
|
2
|
+
require 'go_to_webinar/auth/client'
|
3
|
+
require 'go_to_webinar/auth/configuration'
|
4
4
|
|
5
5
|
module GoToWebinar
|
6
|
-
|
6
|
+
module Auth
|
7
7
|
class << self
|
8
8
|
attr_accessor :client, :configuration
|
9
9
|
|
@@ -1,88 +1,90 @@
|
|
1
1
|
require 'oauth2'
|
2
2
|
require 'redis'
|
3
3
|
|
4
|
-
module GoToWebinar
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
4
|
+
module GoToWebinar
|
5
|
+
module Auth
|
6
|
+
class Client
|
7
|
+
attr_accessor :basic_auth_username, :basic_auth_password, :consumer_key, :secret_key
|
8
|
+
|
9
|
+
def initialize(basic_auth_username:, basic_auth_password:, consumer_key:, secret_key:)
|
10
|
+
config = GoToWebinar::Auth.configuration
|
11
|
+
@redis = Redis.new(url: config.redis_url)
|
12
|
+
@basic_auth_username = basic_auth_username || config.basic_auth_username
|
13
|
+
@basic_auth_password = basic_auth_password || config.basic_auth_password
|
14
|
+
@consumer_key = consumer_key || config.consumer_key
|
15
|
+
@secret_key = secret_key || config.secret_key
|
16
|
+
@site = config.site
|
17
|
+
@authorize_url = config.authorize_url
|
18
|
+
@token_url = config.token_url
|
19
|
+
@auth_scheme = config.auth_scheme
|
20
|
+
@oauth2_client = new_oauth2_client
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
def new_oauth2_client
|
24
|
+
oauth2_client = OAuth2::Client.new(
|
25
|
+
consumer_key,
|
26
|
+
secret_key,
|
27
|
+
site: site,
|
28
|
+
authorize_url: authorize_url,
|
29
|
+
token_url: token_url,
|
30
|
+
auth_scheme: auth_scheme
|
31
|
+
)
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
def access_token
|
35
|
+
@access_token || get_access_token_from_redis || get_new_access_token
|
36
|
+
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
def get_new_access_token
|
39
|
+
token = oauth2_client.password.get_token(basic_auth_username, basic_auth_password)
|
40
|
+
save_to_redis(token)
|
41
|
+
@access_token = token
|
42
|
+
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
|
44
|
+
def refresh_access_token
|
45
|
+
@access_token = access_token&.refresh!
|
46
|
+
end
|
46
47
|
|
47
|
-
|
48
|
+
private
|
48
49
|
|
49
|
-
|
50
|
-
|
50
|
+
attr_accessor :redis, :site, :authorize_url, :authorize_url_optional_params
|
51
|
+
attr_accessor :token_url, :auth_scheme, :oauth2_client
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
def get_access_token_from_redis(redis_key: 'g2w_access_token')
|
54
|
+
# retrieve from redis
|
55
|
+
token_json = @redis.get(redis_key)
|
56
|
+
token_hash = JSON.parse(token_json)&.[]("token") if token_json
|
57
|
+
@access_token = OAuth2::AccessToken.from_hash(oauth2_client, token_hash) if token_hash
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
# if we found it redis, let's return it
|
60
|
+
return @access_token if @access_token
|
60
61
|
|
61
|
-
|
62
|
-
|
63
|
-
|
62
|
+
# if it doesn't currently exist in redis, return nil
|
63
|
+
nil
|
64
|
+
end
|
64
65
|
|
65
|
-
|
66
|
-
|
67
|
-
|
66
|
+
def save_to_redis(token, redis_key: 'g2w_access_token')
|
67
|
+
@redis.set(redis_key, token.to_hash.to_json)
|
68
|
+
end
|
68
69
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
70
|
+
def oauth2_client
|
71
|
+
OAuth2::Client.new(
|
72
|
+
consumer_key,
|
73
|
+
secret_key,
|
74
|
+
site: site,
|
75
|
+
authorize_url: authorize_url,
|
76
|
+
token_url: token_url,
|
77
|
+
auth_scheme: auth_scheme
|
78
|
+
)
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
def authorize_url
|
82
|
+
authorize_url + '?' + authorize_url_params
|
83
|
+
end
|
83
84
|
|
84
|
-
|
85
|
-
|
85
|
+
def authorize_url_params
|
86
|
+
URI.encode_www_form({client_id: consumer_key}.merge(authorize_url_optional_params))
|
87
|
+
end
|
86
88
|
end
|
87
89
|
end
|
88
90
|
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
module GoToWebinar
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module GoToWebinar
|
2
|
+
module Auth
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :redis_url, :consumer_key, :secret_key, :site
|
5
|
+
attr_accessor :authorize_url, :token_url, :auth_scheme
|
6
|
+
attr_accessor :basic_auth_username, :basic_auth_password
|
7
|
+
attr_accessor :authorize_optional_params
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def initialize
|
10
|
+
@site = GoToWebinar::Auth::Configuration.site
|
11
|
+
@authorize_url = GoToWebinar::Auth::Configuration.authorize_url
|
12
|
+
@authorize_optional_params = GoToWebinar::Auth::Configuration.authorize_optional_params
|
13
|
+
@token_url = GoToWebinar::Auth::Configuration.token_url
|
14
|
+
@auth_scheme = GoToWebinar::Auth::Configuration.auth_scheme
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def self.site
|
18
|
+
'https://api.getgo.com'
|
19
|
+
end
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def self.authorize_url
|
22
|
+
'/oauth/v2/authorize'
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
def self.authorize_optional_params
|
26
|
+
{ response_type: "code" }
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
30
|
-
|
29
|
+
def self.token_url
|
30
|
+
'/oauth/v2/token'
|
31
|
+
end
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
def self.auth_scheme
|
34
|
+
'basic_auth'
|
35
|
+
end
|
34
36
|
end
|
35
37
|
end
|
36
38
|
end
|
37
|
-
|
38
|
-
redis = Redis.new(url: ENV['REDISCLOUD_URL'] )
|