Class: FireEagle::User

Inherits:
Object
  • Object
show all
Defined in:
lib/fireeagle/user.rb

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ User

Parses the XML response from FireEagle.



4
5
6
7
# File 'lib/fireeagle/user.rb', line 4

def initialize(doc)
  doc = Hpricot(doc) unless doc.is_a?(Hpricot::Doc || Hpricot::Elem)
  @doc = doc
end

Instance Method Details

#best_guessObject

FireEagle’s “best guess” form this User’s Location. This best guess is derived as the most accurate level of the hierarchy with a timestamp in the last half an hour or as the most accurate level of the hierarchy with the most recent timestamp.



22
23
24
# File 'lib/fireeagle/user.rb', line 22

def best_guess
  @best_guess ||= locations.select { |location| location.best_guess? }.first rescue nil
end

#located_atObject

The time at which this user was last located



15
16
17
# File 'lib/fireeagle/user.rb', line 15

def located_at
  @located_at ||= Time.parse(@doc.at("/user").attributes["located-at"]) rescue nil
end

#locationsObject

An Array containing all Location granularity that the Client has been allowed to see for the User. The Location elements returned are arranged in hierarchy order consisting of: Country, State, County, Large Cities, Neighbourhoods/Local Area, Postal Code and exact location. The Application should therefore be prepared to receive a response that may consist of (1) only country, or (2) country & state or (3) country, state & county and so forth.



31
32
33
34
35
# File 'lib/fireeagle/user.rb', line 31

def locations
  @locations ||= @doc.search("/user/location-hierarchy/location").map do |location|
    FireEagle::Location.new(location.to_s)
  end
end

#tokenObject

The User-specific token for this Client.



10
11
12
# File 'lib/fireeagle/user.rb', line 10

def token
  @token ||= @doc.at("/user").attributes["token"] rescue nil
end