Class: Spectate::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/spectate/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



9
10
11
12
13
14
15
16
17
# File 'lib/spectate/client.rb', line 9

def initialize(options = {})
  Spectate::Config.load_configuration unless Spectate::Config.loaded?
  @protocol = options[:protocol] || Spectate::Config['protocol'] || 'http'
  @host = options[:host] || Spectate::Config['host'] || 'localhost'
  @port = options[:port] || Spectate::Config['port'] || 0
  @accept = options[:accept] || Spectate::Config['accept'] || 'application/json'
  
  @driver = RestClient::Resource.new(root, :accept => accept)
end

Instance Attribute Details

#acceptObject

Returns the value of attribute accept.



7
8
9
# File 'lib/spectate/client.rb', line 7

def accept
  @accept
end

#hostObject

Returns the value of attribute host.



7
8
9
# File 'lib/spectate/client.rb', line 7

def host
  @host
end

#portObject

Returns the value of attribute port.



7
8
9
# File 'lib/spectate/client.rb', line 7

def port
  @port
end

#protocolObject

Returns the value of attribute protocol.



7
8
9
# File 'lib/spectate/client.rb', line 7

def protocol
  @protocol
end

Instance Method Details

#getObject



26
27
28
29
30
31
32
33
# File 'lib/spectate/client.rb', line 26

def get
  response = @driver.get
  s = Spectate::Status.new(root,'/',JSON.parse(response)) if accept == 'application/json'
rescue RestClient::ResourceNotFound
  nil
rescue Errno::ECONNREFUSED
  nil
end

#rootObject



19
20
21
22
23
24
# File 'lib/spectate/client.rb', line 19

def root
  protocol.tr(':/','') + 
  '://' +
  host + 
  ((port.to_i > 0) ? ":#{port}" : '')
end