class MosesacsSdk::Client
Public Class Methods
new(host, port=80)
click to toggle source
# File lib/mosesacs-sdk/client.rb, line 12 def initialize host, port=80 @q = Queue.new @t = Thread.new do EM.run { scheme = 'ws' url = "ws://#{host}:#{port}/api" headers = {'Origin' => 'http://localhost'} @ws = Faye::WebSocket::Client.new(url, nil, :headers => headers) @ws.onopen = lambda do |event| # p [:open] # @ws.send({"Cmd" => "readMib 00507F5FC268 InternetGatewayDevice.Time."}.to_json) @q.push("ready") end @ws.onmessage = lambda do |event| # p [:message, event.data] d = JSON.parse(event.data) if d["Cmd"] =~ /soap/ @q.push d["Cmd"] else # ignore logs puts d['reason'] @q.push "" end # ws.close 1002, 'Going away' end @ws.onclose = lambda do |event| # p [:close, event.code, event.reason] # puts "disconnected" EM.stop exit 1 end } end @q.pop # puts "Connected..." end
Public Instance Methods
CancelTransfer(serial)
click to toggle source
# File lib/mosesacs-sdk/client.rb, line 80 def CancelTransfer (serial) @ws.send({"MsgType" => "command", "Data" => {"command" => "canceltransfer", "serial" => serial}}.to_json) resp = @q.pop puts resp if resp != "" end
ChangeDuState(serial, ops)
click to toggle source
# File lib/mosesacs-sdk/client.rb, line 68 def ChangeDuState (serial, ops) @ws.send({"MsgType" => "command", "Data" => {"command" => "changeDuState #{serial}", "ops" => ops}}.to_json) resp = @q.pop puts resp if resp != "" end
Download(serial, url, username, password, filetype, filesize)
click to toggle source
# File lib/mosesacs-sdk/client.rb, line 74 def Download (serial, url, username, password, filetype, filesize) @ws.send({"MsgType" => "command", "Data" => {"command" => "download", "serial" => serial, "url" => url, "username" => username, "password" => password, "filetype" => filetype, "filesize" => filesize}}.to_json) resp = @q.pop puts resp if resp != "" end
GetParameterValues(serial, leaf)
click to toggle source
# File lib/mosesacs-sdk/client.rb, line 53 def GetParameterValues (serial, leaf) @ws.send({"MsgType" => "command", "Data" => {"command" => "readMib #{serial} #{leaf}"}}.to_json) resp = @q.pop doc = Nokogiri::XML(resp) message_type = doc.css("soap|Body").children.map(&:name)[1] if message_type == "Fault" raise "Got Fault Message: #{doc.css("FaultString")[0].text}" end doc.css("ParameterValueStruct").each do |par| puts "#{par.children[1].text}: #{par.children[3].text}" end end
ScheduleDownload(serial, url, username, password, filetype, filesize, windows)
click to toggle source
# File lib/mosesacs-sdk/client.rb, line 86 def ScheduleDownload(serial, url, username, password, filetype, filesize, windows) @ws.send({"MsgType" => "command", "Data" => {"command" => "scheduledownload", "serial" => serial, "url" => url, "username" => username, "password" => password, "filetype" => filetype, "filesize" => filesize, "windows" => windows}}.to_json) resp = @q.pop puts resp if resp != "" end