public
Description: Implementing the Google Contacts Data API in Ruby
Clone URL: git://github.com/mislav/contacts.git
Search Repo:
doc love baby
mislav (author)
Sun Mar 16 05:06:32 -0700 2008
commit  b81702730cecfabe27e7647aced4996f68312dba
tree    7240b48b890b228473b9f4e5477fd66fe2d5df68
parent  69d830a3590b1111ca97195fce81eeb39a4d9a07
...
1
2
 
...
1
2
3
0
@@ -1,2 +1,3 @@
0
 .DS_Store
0
 /doc
0
+/coverage
...
19
20
21
 
22
23
24
...
27
28
29
 
30
31
32
 
33
34
35
36
37
 
 
 
 
 
 
...
19
20
21
22
23
24
25
...
28
29
30
31
32
33
 
34
35
36
37
38
39
40
41
42
43
44
45
0
@@ -19,6 +19,7 @@ Use that token in the next step:
0
 
0
 This is still alpha. It has been tested only with mocks, not live.
0
 Feel free to contribute; I plan to support more APIs (Microsoft, etc).
0
+Read more in Contacts::Gmail.
0
 
0
 Author: Mislav Marohnić (mislav.marohnic@gmail.com)
0
 
0
@@ -27,11 +28,18 @@ Author: Mislav Marohnić (mislav.marohnic@gmail.com)
0
 Contacts::Gmail.authentication_url
0
 - generates a URL for target with default parameters
0
 - should handle boolean parameters
0
+- skips parameters that have nil value
0
 
0
 Contacts::Gmail
0
-- is ready to query contacts from a specific account
0
+- should be set to query contacts from a specific account
0
 - fetches contacts feed via HTTP GET
0
 - handles gzipped response
0
 - raises a FetchingError when something goes awry
0
 - parses the resulting feed into name/email pairs
0
 - makes modification time available after parsing
0
+
0
+Contacts::Gmail GET query parameter handling
0
+- abstracts ugly parameters behind nicer ones
0
+- should have implicit :descending with :order
0
+- should have default :limit of 200
0
+- should skip nil values in parameters
...
6
7
8
9
10
 
 
 
11
12
 
 
 
 
 
 
 
 
 
 
 
 
 
13
14
15
16
17
 
 
 
 
 
 
 
 
 
 
18
19
20
...
40
41
42
 
 
 
 
 
 
 
 
 
 
43
44
45
...
112
113
114
 
 
115
116
117
118
 
119
120
121
122
 
123
124
125
...
6
7
8
 
 
9
10
11
12
 
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
...
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
0
@@ -6,15 +6,38 @@ require 'hpricot'
0
 require 'date'
0
 
0
 module Contacts
0
- # AuthSub proxy authentication is used by web applications that need to
0
- # authenticate their users to Google Accounts.
0
+ # Web applications should use
0
+ # AuthSub[http://code.google.com/apis/contacts/developers_guide_protocol.html#auth_sub]
0
+ # proxy authentication to get an authentication token for a Google account.
0
   #
0
- # http://code.google.com/apis/contacts/developers_guide_protocol.html#auth_sub
0
+ # First, get the user to follow the following URL:
0
+ #
0
+ # Contacts::Gmail.authentication_url('http://mysite.com/invite')
0
+ #
0
+ # After he authenticates successfully, Google will redirect him back to the target URL
0
+ # (specified as argument above) and provide the token GET parameter. Use it to create a
0
+ # new instance of this class and request the contact list:
0
+ #
0
+ # gmail = Contacts::Gmail.new('example@gmail.com', params[:token])
0
+ # contacts = gmail.contacts
0
+ # #-> [ ['Fitzgerald', 'fubar@gmail.com', 'fubar@example.com'],
0
+ # ['William Paginate', 'will.paginate@gmail.com'], ...
0
+ # ]
0
   class Gmail
0
     DOMAIN = 'www.google.com'
0
     AuthSubURL = "https://#{DOMAIN}/accounts/AuthSubRequest"
0
     AuthScope = "http://#{DOMAIN}/m8/feeds/"
0
 
0
+ # URL to Google site where user authenticates. Afterwards, Google redirects to your
0
+ # site with the URL specified as +target+.
0
+ #
0
+ # Options are:
0
+ # * <tt>:scope</tt> -- the AuthSub scope in which the resulting token is valid
0
+ # (default: "http://www.google.com/m8/feeds/")
0
+ # * <tt>:secure</tt> -- boolean indicating whether the token will be secure
0
+ # (default: false)
0
+ # * <tt>:session</tt> -- boolean indicating if the token can be exchanged for a session token
0
+ # (default: false)
0
     def self.authentication_url(target, options = {})
0
       params = { :next => target,
0
                  :scope => AuthScope,
0
@@ -40,6 +63,16 @@ module Contacts
0
 
0
     attr_reader :uri
0
     
0
+ # User email and token are required here. By default, an AuthSub token from Google is
0
+ # one-time only, which means you can only make a single request with it.
0
+ #
0
+ # ==== Options
0
+ # * <tt>:limit</tt> -- use a large number to fetch a bigger contact list (default: 200)
0
+ # * <tt>:offset</tt> -- 0-based value, can be used for pagination
0
+ # * <tt>:order</tt> -- currently the only value support by Google is "lastmodified"
0
+ # * <tt>:descending</tt> -- boolean
0
+ # * <tt>:updated_after</tt> -- string or time-like object, use to only fetch contacts
0
+ # that were updated after this date
0
     def initialize(email, token, options = {})
0
       @token = token.to_s
0
       @email = email.to_s
0
@@ -112,14 +145,18 @@ module Contacts
0
       @updated_string = @doc.at('/feed/updated').inner_text
0
     end
0
 
0
+ # Timestamp of last update (DateTime). This value is available only after the XML
0
+ # document has been parsed; for instance after fetching the contact list.
0
     def updated_at
0
       @updated_at ||= DateTime.parse @updated_string if @updated_string
0
     end
0
 
0
+ # Timestamp of last update as it appeared in the XML document
0
     def updated_at_string
0
       @updated_string
0
     end
0
 
0
+ # Fetches, parses and returns the contact list.
0
     def contacts
0
       parse
0
       all = []

Comments

    No one has commented yet.