Class: GoogleReader::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/google_reader/client.rb

Constant Summary collapse

BASE_URL =
"http://www.google.com/reader/atom/user/-/".freeze
STATE_URL =
BASE_URL + "state/com.google/".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Client

Returns a new instance of Client.



40
41
42
43
# File 'lib/google_reader/client.rb', line 40

def initialize(token)
  @token   = token
  @headers = {"Authorization" => "GoogleLogin auth=#{token}", "Accept" => "application/xml"}
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



38
39
40
# File 'lib/google_reader/client.rb', line 38

def headers
  @headers
end

#tokenObject (readonly)

Returns the value of attribute token.



38
39
40
# File 'lib/google_reader/client.rb', line 38

def token
  @token
end

Class Method Details

.authenticate(*args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/google_reader/client.rb', line 7

def self.authenticate(*args)
  case args.length
  when 1
    authenticate_using_token(args.first)
  when 2
    authenticate_using_username_and_password(args.first, args.last)
  else
    raise ArgumentError, "Expected either token, or username and password, received #{args.inspect}"
  end
end

.authenticate_using_token(token) ⇒ Object



18
19
20
# File 'lib/google_reader/client.rb', line 18

def self.authenticate_using_token(token)
  new(token)
end

.authenticate_using_username_and_password(username, password) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/google_reader/client.rb', line 22

def self.authenticate_using_username_and_password(username, password)
  resp = RestClient.post("https://www.google.com/accounts/ClientLogin",
                         :Email   => username,
                         :Passwd  => password,
                         :service => "reader")

  dict = resp.split.inject(Hash.new) do |memo, encoded_pair|
    key, value = encoded_pair.split("=").map {|val| CGI.unescape(val)}
    memo[key] = value
    memo
  end

  token = dict["Auth"]
  new(token)
end

Instance Method Details

#logger=(value) ⇒ Object



45
46
47
# File 'lib/google_reader/client.rb', line 45

def logger=(value)
  RestClient.log = value
end

#unread_items(options = {}) ⇒ Object



76
77
78
# File 'lib/google_reader/client.rb', line 76

def unread_items(options={})
  reading_list_feed(options)
end