redd 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/redd.rb +6 -5
- data/lib/redd/client/authenticated.rb +4 -0
- data/lib/redd/oauth2_access.rb +7 -2
- data/lib/redd/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cac2352c74273319e7d9d2459a05469a03e19725
|
4
|
+
data.tar.gz: 610eede3dc4cd4c0adc0edcb7a0a647f8531a4d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 147e0bc9cba206f042cce9f7c580e8ffe88fbef02a841c8ec25e8e0cc2507d6e5e59a3a30e8e5947fc6cdc58b332fe28dab37748d3e9684f90bdd983918c7caa
|
7
|
+
data.tar.gz: 0cabe42cbca0d9eb9b2c321ee836e2bedd5f5c47d808c1108875efa3229b5df19ab0fa2dda296f0dbb011abf134e00444877b54d0cd1b253d90dfb94ecd84325
|
data/lib/redd.rb
CHANGED
@@ -3,12 +3,13 @@ require "redd/client/authenticated"
|
|
3
3
|
require "redd/client/oauth2"
|
4
4
|
|
5
5
|
module Redd
|
6
|
-
def self.client(username = nil, password = nil)
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def self.client(username = nil, password = nil, redirect_uri = nil, options = {})
|
7
|
+
if redirect_uri
|
8
|
+
Redd::Client::OAuth2.new(username, password, redirect_uri, options)
|
9
|
+
elsif username && password
|
10
|
+
Redd::Client::Authenticated.new_from_credentials(username, password, options)
|
10
11
|
else
|
11
|
-
|
12
|
+
Redd::Client::Unauthenticated.new
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -41,6 +41,10 @@ module Redd
|
|
41
41
|
# @return [String] The returned modhash used when making requests.
|
42
42
|
attr_reader :modhash
|
43
43
|
|
44
|
+
def new_from_credentials(username, password, options = {})
|
45
|
+
Redd::Client::Unauthenticated.new.login(username, password, options)
|
46
|
+
end
|
47
|
+
|
44
48
|
# Set up an authenticated connection to reddit.
|
45
49
|
#
|
46
50
|
# @param [String] cookie The cookie to use when sending a request.
|
data/lib/redd/oauth2_access.rb
CHANGED
@@ -17,7 +17,12 @@ module Redd
|
|
17
17
|
@refresh_token = response[:refresh_token]
|
18
18
|
@scope = response[:scope].split(",").map { |s| s.to_sym }
|
19
19
|
@duration = @refresh_token ? :permanent : :temporary
|
20
|
-
@expires_at =
|
20
|
+
@expires_at =
|
21
|
+
if response[:expires_at]
|
22
|
+
Time.at(response[:expires_at])
|
23
|
+
else
|
24
|
+
Time.now + response[:expires_in]
|
25
|
+
end
|
21
26
|
end
|
22
27
|
|
23
28
|
def refresh(response)
|
@@ -35,7 +40,7 @@ module Redd
|
|
35
40
|
access_token: @access_token,
|
36
41
|
refresh_token: @refresh_token,
|
37
42
|
scope: @scope.join(","),
|
38
|
-
|
43
|
+
expires_at: @expires_at.to_i
|
39
44
|
)
|
40
45
|
end
|
41
46
|
|
data/lib/redd/version.rb
CHANGED