gmail_contacts 1.0.1 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,6 +1,18 @@
1
- === 1.0.0 / 2009-04-08
1
+ === 1.1 / 2009-04-30
2
2
 
3
- * 1 major enhancement
3
+ * 1 minor enhancement
4
+ * Allow for saved session tokens
5
+
6
+ * 1 bug fix
7
+ * Fix stubs for gdata 1.1
8
+
9
+ === 1.0.1 / 2009-04-14
4
10
 
11
+ * 1 bug fix
12
+ * Fix for contacts without an email address
13
+
14
+ === 1.0 / 2009-04-08
15
+
16
+ * 1 major enhancement
5
17
  * Birthday!
6
18
 
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ Hoe.new('gmail_contacts', GmailContacts::VERSION) do |p|
8
8
  p.rubyforge_name = 'seattlerb' # if different than lowercase project name
9
9
  p.developer 'Eric Hodel', 'drbrain@segment7.net'
10
10
 
11
- p.extra_deps << ['gdata', '~> 1.0']
11
+ p.extra_deps << ['gdata', '~> 1.1']
12
12
  p.extra_deps << ['nokogiri', '~> 1.2']
13
13
  end
14
14
 
@@ -10,68 +10,16 @@ require 'nokogiri'
10
10
 
11
11
  class GmailContacts
12
12
 
13
- VERSION = '1.0.1'
13
+ VERSION = '1.1'
14
14
 
15
- Contact = Struct.new :title, :emails, :ims, :phone_numbers, :addresses
15
+ Contact = Struct.new :title, :emails, :ims, :phone_numbers, :addresses,
16
+ :photo_url
16
17
 
17
18
  ##
18
19
  # Struct containing title, emails, ims, phone_numbers and addresses
19
20
 
20
21
  class Contact
21
22
 
22
- def pretty_print(q) # :nodoc:
23
- q.text "#{title}"
24
- q.breakable
25
-
26
- q.group 2 do
27
- q.breakable
28
- q.group 2, 'emails: ' do
29
- emails.each_with_index do |email, i|
30
- unless i == 0 then
31
- q.text ','
32
- q.breakable
33
- end
34
-
35
- email += " (Primary)" if i == 0
36
- q.text email
37
- end
38
- end
39
-
40
- q.breakable
41
- q.group 2, 'ims: ' do
42
- ims.each_with_index do |(address, type), i|
43
- unless i == 0 then
44
- q.text ','
45
- q.breakable
46
- end
47
-
48
- q.text "#{address} (#{type.sub(/.*#/, '')})"
49
- end
50
- end
51
-
52
- q.breakable
53
- q.group 2, 'phone numbers: ' do
54
- phone_numbers.each_with_index do |(number, type), i|
55
- unless i == 0 then
56
- q.text ','
57
- q.breakable
58
- end
59
-
60
- q.text "#{number} (#{type.sub(/.*#/, '')})"
61
- end
62
- end
63
-
64
- q.breakable
65
- addresses.each do |address, type|
66
- q.group 2, "#{type.sub(/.*#/, '')} address:\n" do
67
- address = address.split("\n").each do |line|
68
- q.text "#{' ' * q.indent}#{line}\n"
69
- end
70
- end
71
- end
72
- end
73
- end
74
-
75
23
  ##
76
24
  # Returns the user's primary email address
77
25
 
@@ -121,9 +69,9 @@ class GmailContacts
121
69
  # See GData::Client::Base in the gdata gem and
122
70
  # http://code.google.com/apis/accounts/docs/AuthSub.html for more details.
123
71
 
124
- def initialize(authsub_token = nil)
72
+ def initialize(authsub_token = nil, session_token = false)
125
73
  @authsub_token = authsub_token
126
- @session_token = false
74
+ @session_token = session_token
127
75
 
128
76
  @id = nil
129
77
  @title = nil
@@ -154,14 +102,26 @@ class GmailContacts
154
102
 
155
103
  uri = next_uri['href']
156
104
  end
105
+
106
+ yield if block_given?
157
107
  ensure
158
108
  revoke_token if token?
159
109
  end
160
110
 
111
+ ##
112
+ # Fetches the photo data for +contact+
113
+
114
+ def fetch_photo(contact)
115
+ res = @contact_api.get contact.photo_url
116
+
117
+ res.body
118
+ end
119
+
161
120
  ##
162
121
  # Fetches an AuthSub session token
163
122
 
164
123
  def get_token
124
+ return if @session_token
165
125
  @contact_api.authsub_token = @authsub_token
166
126
  @contact_api.auth_handler.upgrade
167
127
  @session_token = true
@@ -204,7 +164,10 @@ class GmailContacts
204
164
  addresses << [address.text, address['rel']]
205
165
  end
206
166
 
207
- contact = Contact.new title, emails, ims, phones, addresses
167
+ photo_link = entry.xpath('.//xmlns:link[@rel="http://schemas.google.com/contacts/2008/rel#photo"]').first
168
+ photo_url = photo_link['href'] if photo_link
169
+
170
+ contact = Contact.new title, emails, ims, phones, addresses, photo_url
208
171
 
209
172
  @contacts << contact
210
173
  end
@@ -143,7 +143,10 @@ class GmailContacts
143
143
 
144
144
  def get_token
145
145
  if @authsub_token == 'recycled_authsub_token' then
146
- raise GData::Client::AuthorizationError, 'recycled token'
146
+ res = GData::HTTP::Response.new
147
+ res.status_code = 403
148
+ res.body = 'recycled token'
149
+ raise GData::Client::AuthorizationError, res
147
150
  end
148
151
  old_get_token
149
152
  @contact_api.stub_reset
@@ -15,26 +15,8 @@ class TestGmailContacts < Test::Unit::TestCase
15
15
  [%w[example http://schemas.google.com/g/2005#AIM]],
16
16
  [%w[999\ 555\ 1212 http://schemas.google.com/g/2005#mobile]],
17
17
  [["123 Any Street\nAnyTown, ZZ 99999",
18
- "http://schemas.google.com/g/2005#home"]])
19
- end
20
-
21
- def test_contact_pretty_print
22
- str = ''
23
- PP.pp @eric, str
24
-
25
- expected = <<-EXPECTED
26
- Eric
27
-
28
- emails: eric@example.com (Primary), eric@example.net
29
- ims: example (AIM)
30
- phone numbers: 999 555 1212 (mobile)
31
- home address:
32
- 123 Any Street
33
- AnyTown, ZZ 99999
34
-
35
- EXPECTED
36
-
37
- assert_equal expected, str
18
+ "http://schemas.google.com/g/2005#home"]],
19
+ "http://www.google.com/m8/feeds/photos/media/eric%40example.com/18")
38
20
  end
39
21
 
40
22
  def test_fetch
@@ -57,7 +39,8 @@ Eric
57
39
 
58
40
  def test_fetch_forbidden
59
41
  @api.stub_data << proc do
60
- raise GData::Client::AuthorizationError
42
+ res = GData::HTTP::Response.new
43
+ raise GData::Client::AuthorizationError, res
61
44
  end
62
45
 
63
46
  assert_raise GData::Client::AuthorizationError do
@@ -74,6 +57,14 @@ Eric
74
57
  assert @api.auth_handler.revoked?
75
58
  end
76
59
 
60
+ def test_fetch_photo
61
+ @api.stub_data << 'THIS IS A PHOTO!'
62
+
63
+ photo = @gc.fetch_photo @eric
64
+
65
+ assert_equal 'THIS IS A PHOTO!', photo
66
+ end
67
+
77
68
  def test_parse
78
69
  @gc.parse Nokogiri::XML(GmailContacts::TestStub::CONTACTS)
79
70
 
@@ -82,8 +73,11 @@ Eric
82
73
  assert_equal 'drbrain', @gc.author_name
83
74
  assert_equal 'eric@example.com', @gc.author_email
84
75
 
76
+ photo_url = 'http://www.google.com/m8/feeds/photos/media/eric%40example.com/0'
77
+
85
78
  expected = [
86
- GmailContacts::Contact.new('Sean', %w[sean@example.com], [], [], []),
79
+ GmailContacts::Contact.new('Sean', %w[sean@example.com], [], [], [],
80
+ photo_url),
87
81
  @eric
88
82
  ]
89
83
 
@@ -99,10 +93,15 @@ Eric
99
93
  assert_equal 'drbrain', @gc.author_name
100
94
  assert_equal 'eric@example.com', @gc.author_email
101
95
 
96
+ sean_photo_url = "http://www.google.com/m8/feeds/photos/media/eric%40example.com/0"
97
+ coby_photo_url = "http://www.google.com/m8/feeds/photos/media/eric%40example.com/5834fb5d0b47bfd7"
98
+
102
99
  expected = [
103
- GmailContacts::Contact.new('Sean', %w[sean@example.com], [], [], []),
100
+ GmailContacts::Contact.new('Sean', %w[sean@example.com], [], [], [],
101
+ sean_photo_url),
104
102
  @eric,
105
- GmailContacts::Contact.new('Coby', %w[coby@example.com], [], [], []),
103
+ GmailContacts::Contact.new('Coby', %w[coby@example.com], [], [], [],
104
+ coby_photo_url),
106
105
  ]
107
106
 
108
107
  assert_equal expected, @gc.contacts
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gmail_contacts
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: "1.1"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Hodel
@@ -30,7 +30,7 @@ cert_chain:
30
30
  x52qPcexcYZR7w==
31
31
  -----END CERTIFICATE-----
32
32
 
33
- date: 2009-04-14 00:00:00 -07:00
33
+ date: 2009-05-01 00:00:00 -07:00
34
34
  default_executable:
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
@@ -41,7 +41,7 @@ dependencies:
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
- version: "1.0"
44
+ version: "1.1"
45
45
  version:
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: nokogiri
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  requirements: []
113
113
 
114
114
  rubyforge_project: seattlerb
115
- rubygems_version: 1.3.1.2162
115
+ rubygems_version: 1.3.2.2179
116
116
  signing_key:
117
117
  specification_version: 3
118
118
  summary: Simple Gmail contacts extraction using GData
metadata.gz.sig CHANGED
Binary file