Class: FireEagle::User
- Inherits:
-
Object
- Object
- FireEagle::User
- Defined in:
- lib/fireeagle/user.rb
Instance Method Summary collapse
-
#best_guess ⇒ Object
FireEagle’s “best guess” form this User’s Location.
-
#initialize(doc) ⇒ User
constructor
Parses the XML response from FireEagle.
-
#locations ⇒ Object
An Array containing all Location granularity that the Client has been allowed to see for the User.
-
#token ⇒ Object
The User-specific token for this Client.
Constructor Details
#initialize(doc) ⇒ User
Parses the XML response from FireEagle.
5 6 7 8 |
# File 'lib/fireeagle/user.rb', line 5 def initialize(doc) doc = Hpricot(doc) unless doc.is_a?(Hpricot::Doc || Hpricot::Elem) @doc = doc end |
Instance Method Details
#best_guess ⇒ Object
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.
18 19 20 |
# File 'lib/fireeagle/user.rb', line 18 def best_guess @best_guess ||= locations.select { |location| location.best_guess? }.first rescue nil end |
#locations ⇒ Object
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.
27 28 29 30 31 |
# File 'lib/fireeagle/user.rb', line 27 def locations @locations ||= @doc.search("/user/location-hierarchy/location").map do |location| FireEagle::Location.new(location.to_s) end end |
#token ⇒ Object
The User-specific token for this Client.
11 12 13 |
# File 'lib/fireeagle/user.rb', line 11 def token @token ||= @doc.at("/user").attributes["token"] rescue nil end |