Class: GoogleContactsApi::Result

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/google_contacts_api/result.rb

Overview

Base class for Group and Contact. In the JSON responses, “:” from the equivalent XML response is replaced with a “$”, while element content is instead keyed with “$t”.

Direct Known Subclasses

Contact, Group

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_hash = nil, default = nil, api = nil, &blk) ⇒ Result

Initialize a Result from a single result’s Hash/Hashie



10
11
12
13
# File 'lib/google_contacts_api/result.rb', line 10

def initialize(source_hash = nil, default = nil, api = nil, &blk)
  @api = api if api
  super(source_hash, default, &blk)
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api.



8
9
10
# File 'lib/google_contacts_api/result.rb', line 8

def api
  @api
end

Instance Method Details

#categoriesObject

Returns the array of categories, as category is an array for Hashie. There is a scheme and a term.



44
45
46
# File 'lib/google_contacts_api/result.rb', line 44

def categories
  category
end

#contentObject



32
33
34
35
# File 'lib/google_contacts_api/result.rb', line 32

def content
  _content = self["content"]
  _content ? _content["$t"] : nil
end

#deleted?Boolean

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/google_contacts_api/result.rb', line 48

def deleted?
  raise NotImplementedError
end

#etagObject

TODO: Conditional retrieval? There might not be an etag in the JSON representation, there is in the XML representation



17
18
# File 'lib/google_contacts_api/result.rb', line 17

def etag
end

#idObject



20
21
22
23
# File 'lib/google_contacts_api/result.rb', line 20

def id
  _id = self["id"]
  _id ? _id["$t"] : nil
end

#inspectObject



52
53
54
# File 'lib/google_contacts_api/result.rb', line 52

def inspect
  "<#{self.class}: #{title}>"
end

#titleObject

For Contacts, returns the (full) name. For Groups, returns the name of the group.



27
28
29
30
# File 'lib/google_contacts_api/result.rb', line 27

def title
  _title = self["title"]
  _title ? _title["$t"] : nil
end

#updatedObject



37
38
39
40
# File 'lib/google_contacts_api/result.rb', line 37

def updated
  _updated = self["updated"]
  _updated ? DateTime.parse(_updated["$t"]) : nil
end