google_reader 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +8 -0
- data/lib/google_reader/client.rb +21 -5
- data/lib/google_reader/version.rb +1 -1
- metadata +1 -1
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
|
data/lib/google_reader/client.rb
CHANGED
@@ -4,7 +4,22 @@ require "cgi"
|
|
4
4
|
|
5
5
|
module GoogleReader
|
6
6
|
class Client
|
7
|
-
def self.authenticate(
|
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(
|
35
|
+
new(token)
|
21
36
|
end
|
22
37
|
|
23
|
-
attr_reader :headers
|
38
|
+
attr_reader :token, :headers
|
24
39
|
|
25
|
-
def initialize(
|
26
|
-
@
|
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
|