Skip to content

Commit

Permalink
adding specs for gmail and refactor for gmail profile picture
Browse files Browse the repository at this point in the history
  • Loading branch information
asmatameem committed Sep 25, 2015
1 parent d23c89c commit 1b26f1e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 3 additions & 3 deletions lib/omnicontacts/importer/gmail.rb
Expand Up @@ -24,7 +24,7 @@ def initialize *args
def fetch_contacts_using_access_token access_token, token_type
fetch_current_user(access_token, token_type)
contacts_response = https_get(@contacts_host, @contacts_path, contacts_req_params, contacts_req_headers(access_token, token_type))
contacts_from_response contacts_response
contacts_from_response(contacts_response, access_token)
end

def fetch_current_user access_token, token_type
Expand All @@ -43,7 +43,7 @@ def contacts_req_headers token, token_type
{"GData-Version" => "3.0", "Authorization" => "#{token_type} #{token}"}
end

def contacts_from_response response_as_json
def contacts_from_response(response_as_json, access_token)
response = JSON.parse(response_as_json)

return [] if response['feed'].nil? || response['feed']['entry'].nil?
Expand Down Expand Up @@ -161,7 +161,7 @@ def contacts_from_response response_as_json
if entry["link"] && entry["link"].is_a?(Array)
entry["link"].each do |link|
if link["type"] == 'image/*' && link["gd$etag"]
contact[:profile_picture] = link["href"] + "?&access_token=" + @env["omnicontacts.user"][:access_token]
contact[:profile_picture] = link["href"] + "?&access_token=" + access_token
break
end
end
Expand Down
2 changes: 1 addition & 1 deletion omnicontacts.gemspec
Expand Up @@ -4,7 +4,7 @@ require File.expand_path('../lib/omnicontacts', __FILE__)
Gem::Specification.new do |gem|
gem.name = 'omnicontacts'
gem.description = %q{A generalized Rack middleware for importing contacts from major email providers.}
gem.authors = ['Diego Castorina', 'Jordan Lance']
gem.authors = ['Diego Castorina', 'Jordan Lance', 'Asma Tameem', 'Randy Villanueva']
gem.email = ['diegocastorina@gmail.com', 'voorruby@gmail.com']

gem.add_runtime_dependency 'rack'
Expand Down
13 changes: 8 additions & 5 deletions spec/omnicontacts/importer/gmail_spec.rb
Expand Up @@ -5,7 +5,7 @@

let(:gmail) { OmniContacts::Importer::Gmail.new({}, "client_id", "client_secret") }

let(:gmail_with_scope_args) { OmniContacts::Importer::Gmail.new({}, "client_id", "client_secret", {scope: "https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/contacts.readonly"}) }
let(:gmail_with_scope_args) { OmniContacts::Importer::Gmail.new({}, "client_id", "client_secret", {scope: "https://www.googleapis.com/auth/contacts.readonly https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/userinfo.profile"}) }

let(:self_response) {
'{
Expand Down Expand Up @@ -39,6 +39,8 @@
"title":{"$t":"Users\'s Contacts"},
"link":[
{"rel":"http://schemas.google.com/contacts/2008/rel#photo","type":"image/*",
"href":"https://www.google.com/m8/feeds/photos/media/logged_in_user%40gmail.com/6b41d030b05abc","gd$etag":"\"VSxuN0cISit7I2A1UVUSdy12KHwgBFkE333.\""},
{"rel":"alternate","type":"text/html","href":"http://www.google.com/"},
{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full"},
{"rel":"http://schemas.google.com/g/2005#post","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full"},
Expand All @@ -60,7 +62,8 @@
"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://schemas.google.com/contact/2008#contact"}],
"title":{"$t":"Edward Bennet"},
"link":[
{"rel":"http://schemas.google.com/contacts/2008/rel#photo","type":"image/*","href":"https://www.google.com/m8/feeds/photos/media/logged_in_user%40gmail.com/1"},
{"rel":"http://schemas.google.com/contacts/2008/rel#photo","type":"image/*",
"href":"https://www.google.com/m8/feeds/photos/media/logged_in_user%40gmail.com/6b41d030b05abc", "gd$etag":"\"VSxuN0cISit7I2A1UVUSdy12KHwgBFkE333.\""},
{"rel":"self","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full/1"},
{"rel":"edit","type":"application/atom+xml","href":"https://www.google.com/m8/feeds/contacts/logged_in_user%40gmail.com/full/1"}
],
Expand Down Expand Up @@ -128,8 +131,8 @@
end
gmail.fetch_contacts_using_access_token token, token_type

gmail.scope.should eq "https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/userinfo.profile"
gmail_with_scope_args.scope.should eq "https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/contacts.readonly"
gmail.scope.should eq "https://www.googleapis.com/auth/contacts.readonly https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/userinfo.profile"
gmail_with_scope_args.scope.should eq "https://www.googleapis.com/auth/contacts.readonly https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/userinfo.profile"
end

it "should correctly parse id, name, email, gender, birthday, profile picture and relation for 1st contact" do
Expand All @@ -146,7 +149,7 @@
result.first[:gender].should eq("male")
result.first[:birthday].should eq({:day=>02, :month=>07, :year=>1954})
result.first[:relation].should eq('father')
result.first[:profile_picture].should eq("https://profiles.google.com/s2/photos/profile/bennet")
result.first[:profile_picture].should eq("https://www.google.com/m8/feeds/photos/media/logged_in_user%40gmail.com/6b41d030b05abc?&access_token=token")
result.first[:dates][0][:name].should eq("anniversary")
end

Expand Down

0 comments on commit 1b26f1e

Please sign in to comment.