Class: FireEagle::Response

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

Instance Method Summary collapse

Constructor Details

#initialize(doc) ⇒ Response

Parses the XML response from FireEagle



5
6
7
8
9
# File 'lib/fireeagle/response.rb', line 5

def initialize(doc)
  doc = Hpricot(doc) unless doc.is_a?(Hpricot::Doc || Hpricot::Elem)
  @doc = doc
  raise FireEagle::FireEagleException, @doc.at("/rsp/err").attributes["msg"] if !success? 
end

Instance Method Details

#locationsObject

A Location array.



24
25
26
27
28
# File 'lib/fireeagle/response.rb', line 24

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

#success?Boolean

does the response indicate success?

Returns:

  • (Boolean)


12
13
14
# File 'lib/fireeagle/response.rb', line 12

def success?
  @doc.at("/rsp").attributes["stat"] == "ok" rescue false
end

#usersObject

An array of of User-specific tokens and their Location at all levels the Client can see and larger.



17
18
19
20
21
# File 'lib/fireeagle/response.rb', line 17

def users
  @users ||= @doc.search("/rsp//user").map do |user|
    FireEagle::User.new(user.to_s)
  end
end