Class: GoogleContactsApi::User
- Inherits:
-
Object
- Object
- GoogleContactsApi::User
- Includes:
- Contacts
- Defined in:
- lib/google_contacts_api/user.rb
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
Instance Method Summary collapse
-
#groups(params = {}) ⇒ Object
Retrieve the groups for this user.
-
#initialize(oauth) ⇒ User
constructor
A new instance of User.
Methods included from Contacts
Constructor Details
#initialize(oauth) ⇒ 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
#api ⇒ Object (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.
11 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 11 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) # TODO: Better handle 401, 403, 404 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 |