Class: LinkedIn::Mash
- Inherits:
-
Hashie::Mash
- Object
- Hashie::Mash
- LinkedIn::Mash
- Defined in:
- lib/linked_in/mash.rb
Overview
The generalized pseudo-object that is returned for all query requests.
Class Method Summary collapse
-
.from_json(json_string) ⇒ LinkedIn::Mash
Convert a json string to a Mash.
Instance Method Summary collapse
-
#all ⇒ Array
Return the results array from the query.
-
#id ⇒ String
Returns the id of the object from LinkedIn.
-
#timestamp ⇒ Time
Convert the 'timestamp' field from a string to a Time object.
-
#to_date ⇒ Date
Returns a Date if we have year, month and day, and no conflicting key.
Class Method Details
.from_json(json_string) ⇒ LinkedIn::Mash
Convert a json string to a Mash
14 15 16 17 |
# File 'lib/linked_in/mash.rb', line 14 def self.from_json(json_string) result_hash = ::MultiJson.decode(json_string) new(result_hash) end |
Instance Method Details
#all ⇒ Array
Return the results array from the query
57 58 59 |
# File 'lib/linked_in/mash.rb', line 57 def all super || [] end |
#id ⇒ String
Returns the id of the object from LinkedIn
33 34 35 36 37 38 39 |
# File 'lib/linked_in/mash.rb', line 33 def id if self['id'] self['id'] else self['_key'] end end |
#timestamp ⇒ Time
Convert the 'timestamp' field from a string to a Time object
44 45 46 47 48 49 50 51 52 |
# File 'lib/linked_in/mash.rb', line 44 def value = self['timestamp'] if value.kind_of? Integer value = value / 1000 if value > 9999999999 Time.at(value) else value end end |
#to_date ⇒ Date
Returns a Date if we have year, month and day, and no conflicting key
22 23 24 25 26 27 28 |
# File 'lib/linked_in/mash.rb', line 22 def to_date if !self.has_key?('to_date') && contains_date_fields? Date.civil(self.year, self.month, self.day) else super end end |