Class: Spectate::Client
- Inherits:
-
Object
- Object
- Spectate::Client
- Defined in:
- lib/spectate/client.rb
Instance Attribute Summary collapse
-
#accept ⇒ Object
Returns the value of attribute accept.
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
Instance Method Summary collapse
- #get ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #root ⇒ Object
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( = {}) Spectate::Config.load_configuration unless Spectate::Config.loaded? @protocol = [:protocol] || Spectate::Config['protocol'] || 'http' @host = [:host] || Spectate::Config['host'] || 'localhost' @port = [:port] || Spectate::Config['port'] || 0 @accept = [:accept] || Spectate::Config['accept'] || 'application/json' @driver = RestClient::Resource.new(root, :accept => accept) end |
Instance Attribute Details
#accept ⇒ Object
Returns the value of attribute accept.
7 8 9 |
# File 'lib/spectate/client.rb', line 7 def accept @accept end |
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/spectate/client.rb', line 7 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/spectate/client.rb', line 7 def port @port end |
#protocol ⇒ Object
Returns the value of attribute protocol.
7 8 9 |
# File 'lib/spectate/client.rb', line 7 def protocol @protocol end |
Instance Method Details
#get ⇒ Object
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 |
#root ⇒ Object
19 20 21 22 23 24 |
# File 'lib/spectate/client.rb', line 19 def root protocol.tr(':/','') + '://' + host + ((port.to_i > 0) ? ":#{port}" : '') end |