google_contacts_api 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +6 -2
- data/VERSION +1 -1
- data/google_contacts_api.gemspec +2 -2
- data/lib/google_contacts_api/contact.rb +7 -3
- data/spec/contact_set.json +1 -7
- data/spec/google_contacts_api_spec.rb +10 -0
- data/spec/spec_helper.rb +8 -0
- metadata +3 -3
data/README.markdown
CHANGED
@@ -4,7 +4,8 @@ An unofficial Google Contacts API for ruby. Might not be stable (but probably is
|
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
|
-
You need to provide an OAuth access token from
|
7
|
+
You need to provide an OAuth client, with access token, from an OAuth access library to this library. I've tested it with OAuth::AccessToken from the [oauth-ruby](https://github.com/oauth/oauth-ruby) gem. I'm guessing there would be a few small changes in implementation details of the GoogleContactsApi::Api class if you use another library, mostly to change how the base get/post/put/delete methods work.
|
8
|
+
|
8
9
|
Then you can instantiate a GoogleContactsApi::Api object for direct posting and parsing, or a
|
9
10
|
GoogleContactsApi::User object for easier stuff.
|
10
11
|
|
@@ -28,6 +29,8 @@ contact.emails
|
|
28
29
|
|
29
30
|
In addition, Contacts and Groups are subclasses of [Hashie::Mash](https://github.com/intridea/hashie), so you can access any of the underlying data directly. Note that data is retrieved using Google's JSON API so the equivalent content of an XML element from the XML API is stored under the key "$t".
|
30
31
|
|
32
|
+
The easiest way to see the convenience methods I've provided is to look at the RSpec tests.
|
33
|
+
|
31
34
|
## TODO
|
32
35
|
|
33
36
|
I welcome patches and pull requests, see the guidelines below (handily auto-generated
|
@@ -37,7 +40,8 @@ by jeweler).
|
|
37
40
|
* Read more contact information (structured name, address, phone, ...)
|
38
41
|
* Get single contacts and groups
|
39
42
|
* Posting/putting/deleting groups, contacts and their photos. This might require XML?
|
40
|
-
*
|
43
|
+
* Test other OAuth libraries ([oauth2](https://github.com/intridea/oauth2) is next on my list). Does Google support OAuth 2.0 for contacts?
|
44
|
+
* Support ClientLogin (maybe not, since Google's old library covers it)
|
41
45
|
|
42
46
|
## Contributing to google_contacts_api
|
43
47
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.4
|
data/google_contacts_api.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{google_contacts_api}
|
8
|
-
s.version = "0.2.
|
8
|
+
s.version = "0.2.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Alvin Liang"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-12}
|
13
13
|
s.description = %q{Lets you read from the Google Contacts API. Posting to come later. Tests to come later.}
|
14
14
|
s.email = %q{ayliang@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -60,13 +60,17 @@ module GoogleContactsApi
|
|
60
60
|
|
61
61
|
# Returns all email addresses for the contact
|
62
62
|
def emails
|
63
|
-
self["gd$email"].map { |e| e.address }
|
63
|
+
self["gd$email"] ? self["gd$email"].map { |e| e.address } : []
|
64
64
|
end
|
65
65
|
|
66
66
|
# Returns primary email for the contact
|
67
67
|
def primary_email
|
68
|
-
|
69
|
-
|
68
|
+
if self["gd$email"]
|
69
|
+
_email = self["gd$email"].find { |e| e.primary == "true" }
|
70
|
+
_email ? _email.address : nil
|
71
|
+
else
|
72
|
+
nil # no emails at all
|
73
|
+
end
|
70
74
|
end
|
71
75
|
end
|
72
76
|
end
|
data/spec/contact_set.json
CHANGED
@@ -147,11 +147,6 @@
|
|
147
147
|
"rel": "edit",
|
148
148
|
"type": "application/atom+xml",
|
149
149
|
"href": "https://www.google.com/m8/feeds/contacts/example%40gmail.com/full/1"
|
150
|
-
}],
|
151
|
-
"gd$email": [{
|
152
|
-
"rel": "http://schemas.google.com/g/2005#other",
|
153
|
-
"address": "contact2@example.com",
|
154
|
-
"primary": "true"
|
155
150
|
}]
|
156
151
|
},
|
157
152
|
{
|
@@ -190,8 +185,7 @@
|
|
190
185
|
}],
|
191
186
|
"gd$email": [{
|
192
187
|
"rel": "http://schemas.google.com/g/2005#other",
|
193
|
-
"address": "contact3@example.com"
|
194
|
-
"primary": "true"
|
188
|
+
"address": "contact3@example.com"
|
195
189
|
}]
|
196
190
|
},
|
197
191
|
{
|
@@ -154,6 +154,16 @@ describe "GoogleContactsApi" do
|
|
154
154
|
it "should return the right primary e-mail address" do
|
155
155
|
@contact.primary_email.should == "contact1@example.com"
|
156
156
|
end
|
157
|
+
it "should return an empty array if there are no e-mail addresses" do
|
158
|
+
@contact = contact_no_emails_json_hash
|
159
|
+
@contact.emails.should == []
|
160
|
+
end
|
161
|
+
it "should return nil if there is no primary e-mail address" do
|
162
|
+
@contact2 = contact_no_emails_json_hash
|
163
|
+
@contact2.primary_email.should be_nil
|
164
|
+
@contact3 = contact_no_primary_email_json_hash
|
165
|
+
@contact3.primary_email.should be_nil
|
166
|
+
end
|
157
167
|
end
|
158
168
|
|
159
169
|
describe "Group" do
|
data/spec/spec_helper.rb
CHANGED
@@ -31,6 +31,14 @@ def contact_json_hash
|
|
31
31
|
Hashie::Mash.new(JSON.parse(contact_set_json)).feed.entry.first
|
32
32
|
end
|
33
33
|
|
34
|
+
def contact_no_emails_json_hash
|
35
|
+
Hashie::Mash.new(JSON.parse(contact_set_json)).feed.entry[1]
|
36
|
+
end
|
37
|
+
|
38
|
+
def contact_no_primary_email_json_hash
|
39
|
+
Hashie::Mash.new(JSON.parse(contact_set_json)).feed.entry[2]
|
40
|
+
end
|
41
|
+
|
34
42
|
def group_json_hash
|
35
43
|
Hashie::Mash.new(JSON.parse(group_set_json)).feed.entry.first
|
36
44
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: google_contacts_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.2.
|
5
|
+
version: 0.2.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Alvin Liang
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-07-
|
13
|
+
date: 2011-07-12 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -157,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
157
|
requirements:
|
158
158
|
- - ">="
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
hash:
|
160
|
+
hash: -2760858629422999937
|
161
161
|
segments:
|
162
162
|
- 0
|
163
163
|
version: "0"
|