Class: GoogleContactsApi::Result
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- GoogleContactsApi::Result
- 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”.
Instance Attribute Summary collapse
-
#api ⇒ Object
readonly
Returns the value of attribute api.
Instance Method Summary collapse
-
#categories ⇒ Object
Returns the array of categories, as category is an array for Hashie.
- #content ⇒ Object
- #deleted? ⇒ Boolean
-
#etag ⇒ Object
TODO: Conditional retrieval? There might not be an etag in the JSON representation, there is in the XML representation.
- #id ⇒ Object
-
#initialize(source_hash = nil, default = nil, api = nil, &blk) ⇒ Result
constructor
Initialize a Result from a single result’s Hash/Hashie.
- #inspect ⇒ Object
-
#title ⇒ Object
For Contacts, returns the (full) name.
- #updated ⇒ Object
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
#api ⇒ Object (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
#categories ⇒ Object
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 |
#content ⇒ Object
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
48 49 50 |
# File 'lib/google_contacts_api/result.rb', line 48 def deleted? raise NotImplementedError end |
#etag ⇒ Object
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 |
#id ⇒ Object
20 21 22 23 |
# File 'lib/google_contacts_api/result.rb', line 20 def id _id = self["id"] _id ? _id["$t"] : nil end |
#inspect ⇒ Object
52 53 54 |
# File 'lib/google_contacts_api/result.rb', line 52 def inspect "<#{self.class}: #{title}>" end |
#title ⇒ Object
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 |
#updated ⇒ Object
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 |