Class: LinkedIn::Mash

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/linked_in/mash.rb

Overview

The generalized pseudo-object that is returned for all query requests.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_json(json_string) ⇒ LinkedIn::Mash

Convert a json string to a Mash

Parameters:

  • json_string (String)

Returns:


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

#allArray

Return the results array from the query

Returns:

  • (Array)

57
58
59
# File 'lib/linked_in/mash.rb', line 57

def all
  super || []
end

#idString

Returns the id of the object from LinkedIn

Returns:

  • (String)

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

#timestampTime

Convert the 'timestamp' field from a string to a Time object

Returns:

  • (Time)

44
45
46
47
48
49
50
51
52
# File 'lib/linked_in/mash.rb', line 44

def timestamp
  value = self['timestamp']
  if value.kind_of? Integer
    value = value / 1000 if value > 9999999999
    Time.at(value)
  else
    value
  end
end

#to_dateDate

Returns a Date if we have year, month and day, and no conflicting key

Returns:

  • (Date)

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