Skip to content

Instantly share code, notes, and snippets.

@dwaynemac
Created March 15, 2013 15:27
Show Gist options
  • Save dwaynemac/5170662 to your computer and use it in GitHub Desktop.
Save dwaynemac/5170662 to your computer and use it in GitHub Desktop.
Google Contacts Clinet
require 'gdata'
class GoogleContactsClient
def initialize(username, password)
@username = username
@password = password
@client = GData::Client::Contacts.new
@client.clientlogin(@username,@password)
end
def create(first_name, last_name, email, phone)
body = <<XML_BODY
<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'>
<gd:name>
<gd:givenName>#{first_name}</gd:givenName>
<gd:familyName>#{last_name}</gd:familyName>
<gd:fullName>#{last_name} #{first_name}</gd:fullName>
</gd:name>
<atom:content type='text'>
Notes
</atom:content>
<gd:phoneNumber rel='http://schemas.google.com/g/2005#home' primary='true'>
#{phone}
</gd:phoneNumber>
<gd:email rel='http://schemas.google.com/g/2005#home' address='#{email}'/>
</atom:entry>
XML_BODY
@client.post("https://www.google.com/m8/feeds/contacts/default/full?v=3.0 ", body )
end
def self.get(id)
@client.get("https://www.google.com/m8/feeds/contacts/default/full/#{id}?v=3.0 ")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment