Class: Netscaler::Server::Response

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

Instance Method Summary collapse

Constructor Details

#initialize(raw_response) ⇒ Response

Returns a new instance of Response.



3
4
5
# File 'lib/netscaler/server/response.rb', line 3

def initialize(raw_response)
  @info = raw_response
end

Instance Method Details

#ip_addressObject



11
12
13
# File 'lib/netscaler/server/response.rb', line 11

def ip_address
  @info[:ipaddress]
end

#nameObject



7
8
9
# File 'lib/netscaler/server/response.rb', line 7

def name
  @info[:name]
end

#servicesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/netscaler/server/response.rb', line 19

def services
  @parsed_services ||= []
  return @parsed_services if !@parsed_services.empty? || @info[:servicename].nil?

  if @info[:servicename][:item].is_a?(String)
    @parsed_services << ServiceInfo.new(@info, nil)
  else
    @info[:servicename][:item].each_with_index do |name, i|
      @parsed_services << ServiceInfo.new(@info, i)
    end
  end

  @parsed_services
end

#stateObject



15
16
17
# File 'lib/netscaler/server/response.rb', line 15

def state
  @info[:state]
end

#to_hashObject



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/netscaler/server/response.rb', line 34

def to_hash
  hash = { 
    :name => name,
    :ip_address => ip_address,
    :state => state,
  }

  if !services.empty?
    hash[:services] = services.map {|s| s.to_hash}
  end

  hash
end