google_reader 1.0.3 → 1.1.0

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.
data/README.textile CHANGED
@@ -4,8 +4,16 @@ Access your Google Reader account from Ruby:
4
4
 
5
5
  <pre><code>require "google_reader"
6
6
  # Get an instance of a client like this
7
+ # This hits the network to get a token immediately
7
8
  client = GoogleReader::Client.authenticate(USERNAME, PASSWORD)
8
9
 
10
+ # Save the token to the database, somehow
11
+ client.token
12
+
13
+ # Alternatively, if you save the token, you can authenticate using
14
+ # the token, which doesn't hit the network
15
+ client = GoogleReader::Client.authenticate(TOKEN)
16
+
9
17
  # Then, call any of these
10
18
  client.unread_items
11
19
  client.read_items
@@ -4,7 +4,22 @@ require "cgi"
4
4
 
5
5
  module GoogleReader
6
6
  class Client
7
- def self.authenticate(username, password)
7
+ def self.authenticate(*args)
8
+ case args.length
9
+ when 1
10
+ authenticate_using_token(args.first)
11
+ when 2
12
+ authenticate_using_username_and_password(args.first, args.last)
13
+ else
14
+ raise ArgumentError, "Expected either token, or username and password, received #{args.inspect}"
15
+ end
16
+ end
17
+
18
+ def self.authenticate_using_token(token)
19
+ new(token)
20
+ end
21
+
22
+ def self.authenticate_using_username_and_password(username, password)
8
23
  resp = RestClient.post("https://www.google.com/accounts/ClientLogin",
9
24
  :Email => username,
10
25
  :Passwd => password,
@@ -17,13 +32,14 @@ module GoogleReader
17
32
  end
18
33
 
19
34
  token = dict["Auth"]
20
- new("Authorization" => "GoogleLogin auth=#{token}", "Accept" => "application/xml")
35
+ new(token)
21
36
  end
22
37
 
23
- attr_reader :headers
38
+ attr_reader :token, :headers
24
39
 
25
- def initialize(headers)
26
- @headers = headers
40
+ def initialize(token)
41
+ @token = token
42
+ @headers = {"Authorization" => "GoogleLogin auth=#{token}", "Accept" => "application/xml"}
27
43
  end
28
44
 
29
45
  BASE_URL = "http://www.google.com/reader/atom/user/-/".freeze
@@ -1,3 +1,3 @@
1
1
  module GoogleReader
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: google_reader
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.3
5
+ version: 1.1.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Fran\xC3\xA7ois Beausoleil"