lib/omnicontacts/importer/gmail.rb in omnicontacts-0.3.5 vs lib/omnicontacts/importer/gmail.rb in omnicontacts-0.3.6
- old
+ new
@@ -11,11 +11,11 @@
def initialize *args
super *args
@auth_host = "accounts.google.com"
@authorize_path = "/o/oauth2/auth"
@auth_token_path = "/o/oauth2/token"
- @scope = "https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/userinfo.profile"
+ @scope = (args[3] && args[3][:scope]) || "https://www.google.com/m8/feeds https://www.googleapis.com/auth/userinfo#email https://www.googleapis.com/auth/userinfo.profile"
@contacts_host = "www.google.com"
@contacts_path = "/m8/feeds/contacts/default/full"
@max_results = (args[3] && args[3][:max_results]) || 100
@self_host = "www.googleapis.com"
@profile_path = "/oauth2/v1/userinfo"
@@ -43,10 +43,11 @@
{"GData-Version" => "3.0", "Authorization" => "#{token_type} #{token}"}
end
def contacts_from_response response_as_json
response = JSON.parse(response_as_json)
+
return [] if response['feed'].nil? || response['feed']['entry'].nil?
contacts = []
return contacts if response.nil?
response['feed']['entry'].each do |entry|
# creating nil fields to keep the fields consistent across other networks
@@ -86,10 +87,10 @@
end if entry['gd$email']
# Support older versions of the gem by keeping singular entries around
contact[:email] = contact[:emails][0][:email] if contact[:emails][0]
contact[:first_name], contact[:last_name], contact[:name] = email_to_name(contact[:name]) if !contact[:name].nil? && contact[:name].include?('@')
- contact[:first_name], contact[:last_name], contact[:name] = email_to_name(contact[:emails][0][:email]) if contact[:name].nil? && contact[:emails][0][:email]
+ contact[:first_name], contact[:last_name], contact[:name] = email_to_name(contact[:emails][0][:email]) if (contact[:name].nil? && contact[:emails][0] && contact[:emails][0][:email])
#format - year-month-date
contact[:birthday] = birthday(entry['gContact$birthday']['when']) if entry['gContact$birthday']
# value is either "male" or "female"
contact[:gender] = entry['gContact$gender']['value'] if entry['gContact$gender']