Class: WWTClient
- Inherits:
-
Object
show all
- Defined in:
- lib/WWT/WWTClient.rb
Constant Summary
collapse
- Default_host =
"http://0.0.0.0"
- Default_port =
"5050"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(url = nil, port = nil) ⇒ WWTClient
Returns a new instance of WWTClient.
14
15
16
17
|
# File 'lib/WWT/WWTClient.rb', line 14
def initialize(url=nil,port=nil)
@url ||= Default_host
@port ||= Default_port
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/WWT/WWTClient.rb', line 19
def method_missing(method_name,*args)
args ||= []
data = args.first.delete(:data) || ""
data = data.join(",") if data.class==Array
args_list = make_arg_list(args.first.merge({:cmd=>method_name}))
call_command args_list,data
end
|
Instance Attribute Details
#port ⇒ Object
Returns the value of attribute port.
9
10
11
|
# File 'lib/WWT/WWTClient.rb', line 9
def port
@port
end
|
#url ⇒ Object
Returns the value of attribute url.
9
10
11
|
# File 'lib/WWT/WWTClient.rb', line 9
def url
@url
end
|
Instance Method Details
#call_command(args_list, data = "") ⇒ Object
32
33
34
35
36
37
|
# File 'lib/WWT/WWTClient.rb', line 32
def call_command(args_list,data="")
puts "#{@url}:#{@port}/layerApi.aspx?#{args_list}"
puts "data is #{data}"
parse_responce(RestClient.post "#{@url}:#{@port}/layerApi.aspx?#{args_list}", data)
end
|
#layers ⇒ Object
52
53
54
|
# File 'lib/WWT/WWTClient.rb', line 52
def layers
self.layerlist :layersonly=>true
end
|
#look_at(subject) ⇒ Object
43
44
45
|
# File 'lib/WWT/WWTClient.rb', line 43
def look_at(subject)
self.mode :lookat=>subject
end
|
#make_arg_list(args) ⇒ Object
39
40
41
|
# File 'lib/WWT/WWTClient.rb', line 39
def make_arg_list (args)
args.to_a.inject(""){|str, arg| str+="&#{arg[0].to_s}=#{arg[1].to_s}"}
end
|
#move(command) ⇒ Object
47
48
49
|
# File 'lib/WWT/WWTClient.rb', line 47
def move(command)
self.call_command( make_arg_list({:cmd=>:move, :move=>command}))
end
|
#new_layer(*args) ⇒ Object
27
28
29
30
|
# File 'lib/WWT/WWTClient.rb', line 27
def new_layer (*args)
result = self.new args.first
return WWT_layer.new(self,result.first["newlayerid"][:content])
end
|
#parse_responce(responce) ⇒ Object
56
57
58
59
60
61
|
# File 'lib/WWT/WWTClient.rb', line 56
def parse_responce(responce)
puts responce
raise "WWT error #{parse.search('h2').inner_html}"if responce.match(/Error/)
parse = Document.new responce
parse.elements.to_a("/LayerApi/*") {|el| el.children.map{|c| {c.name =>{:content=>c.text, :properties=>c.attributes}}}}.first
end
|