redd 0.4.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dbf5efd8e87b68f78da263ecb19dd9ee403eb06c
4
- data.tar.gz: ee5a23284444562f4eb2160e700793e3af3b6f33
3
+ metadata.gz: cac2352c74273319e7d9d2459a05469a03e19725
4
+ data.tar.gz: 610eede3dc4cd4c0adc0edcb7a0a647f8531a4d6
5
5
  SHA512:
6
- metadata.gz: bf79a0705655e2b559984a1cdcc0ef59bdbf78aa46515b14dc2a3aee06090e7d4193993e68264ed6e8994f9fded9dc7ce72814da4a86beca17509e356733a1f8
7
- data.tar.gz: 9eb1cf158dc96a0258315072b25c7c456ee3f36e241db6b31f0de8f67b03a6aa534915fd3619f662fd604e1959d01ef741a8736ee1a2f56d9aaf7b66758a9fc1
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
- client = Redd::Client::Unauthenticated.new
8
- if username.nil? || password.nil?
9
- client
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
- client.login(username, password)
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.
@@ -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 = Time.now + response[:expires_in]
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
- expires_in: (@expires_at - Time.now).to_i
43
+ expires_at: @expires_at.to_i
39
44
  )
40
45
  end
41
46
 
data/lib/redd/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # The main Redd module.
2
2
  module Redd
3
3
  # The semantic version number for Redd.
4
- VERSION = "0.4.1"
4
+ VERSION = "0.4.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Avinash Dwarapu