Sha256: 5bd1251de4f75e35b273feb51372a15023d2817a287431953bbd4dff794840aa

Contents?: true

Size: 947 Bytes

Versions: 8

Compression:

Stored size: 947 Bytes

Contents

module GoogleContactsApi
  module Contacts
    # Retrieve the contacts for this user or group
    def contacts(params = {})
      # TODO: Should return empty ContactSet (haven't implemented one yet)
      return [] unless @api
      params = params.with_indifferent_access

      # compose params into a string
      # See http://code.google.com/apis/contacts/docs/3.0/reference.html#Parameters
      # alt, q, max-results, start-index, updated-min,
      # orderby, showdeleted, requirealldeleted, sortorder, group
      params["max-results"] = 100000 unless params.key?("max-results")
      url = "contacts/default/full"
      response = @api.get(url, params)
      
      # TODO: Define some fancy exceptions
      case response.code
      when 401; raise
      when 403; raise
      when 404; raise
      when 400...500; raise
      when 500...600; raise
      end
      GoogleContactsApi::ContactSet.new(response.body, @api)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
google_contacts_api-0.2.7 lib/google_contacts_api/contacts.rb
google_contacts_api-0.2.6 lib/google_contacts_api/contacts.rb
google_contacts_api-0.2.5 lib/google_contacts_api/contacts.rb
google_contacts_api-0.2.4 lib/google_contacts_api/contacts.rb
google_contacts_api-0.2.3 lib/google_contacts_api/contacts.rb
google_contacts_api-0.2.2 lib/google_contacts_api/contacts.rb
google_contacts_api-0.2.1 lib/google_contacts_api/contacts.rb
google_contacts_api-0.2.0 lib/google_contacts_api/contacts.rb