Sha256: e081e9fe427f5e9029e486106f6ef279b52900217c04191a2348ef998513a1f5

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

module GoogleContactsApi
  class User
    include GoogleContactsApi::Contacts
    
    attr_reader :api
    def initialize(oauth)
      @api = GoogleContactsApi::Api.new(oauth)
    end

    # Retrieve the groups for this user
    # TODO: Handle 403, 404, 401
    def groups(params = {})
      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
      params["max-results"] = 100000 unless params.key?("max-results")

      # Set the version, for some reason the header is not effective on its own?
      params["v"] = 2

      url = "groups/default/full"
      # TODO: So weird thing, version 3 doesn't return system groups
      # When it does, uncomment this line and use it to request instead
      # response = @api.get(url, params)
      response = @api.get(url, params)

      case GoogleContactsApi::Api.parse_response_code(response)
      when 401; raise
      when 403; raise
      when 404; raise
      when 400...500; raise
      when 500...600; raise
      end
      GoogleContactsApi::GroupSet.new(response.body, @api)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
google_contacts_api-0.4.1 lib/google_contacts_api/user.rb
google_contacts_api-0.4.0 lib/google_contacts_api/user.rb
google_contacts_api-0.3.3 lib/google_contacts_api/user.rb
google_contacts_api-0.3.2 lib/google_contacts_api/user.rb
google_contacts_api-0.3.1 lib/google_contacts_api/user.rb