Class: GoogleContactsApi::User

Inherits:
Object
  • Object
show all
Includes:
Contacts
Defined in:
lib/google_contacts_api/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Contacts

#contacts

Constructor Details

#initialize(oauth) ⇒ User

Returns a new instance of User.



6
7
8
# File 'lib/google_contacts_api/user.rb', line 6

def initialize(oauth)
  @api = GoogleContactsApi::Api.new(oauth)
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



5
6
7
# File 'lib/google_contacts_api/user.rb', line 5

def api
  @api
end

Instance Method Details

#groups(params = {}) ⇒ Object

Retrieve the groups for this user TODO: Handle 403, 404, 401



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/google_contacts_api/user.rb', line 12

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