Class: GizwitsSac::SnotiClient
- Inherits:
-
Object
- Object
- GizwitsSac::SnotiClient
- Defined in:
- lib/gizwits_sac/snoti_client.rb
Instance Method Summary collapse
-
#initialize(options) ⇒ SnotiClient
constructor
A new instance of SnotiClient.
- #start ⇒ Object
Constructor Details
#initialize(options) ⇒ SnotiClient
Returns a new instance of SnotiClient.
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gizwits_sac/snoti_client.rb', line 33 def initialize() @event_push = .delete(:event_push) || (Proc.new {|event_push_data| }) @remote_ctrl = .delete(:remote_ctrl) || (Proc.new { return nil }) @remote_ctrl_res = .delete(:remote_ctrl_res) || (Proc.new {|r_ctrl_data| }) @error_res = [:error_res] || (Proc.new {|err_data| }) @retry_count = .delete(:retry_count) || 5 @heartbeat_interval = .delete(:heartbeat_interval) || 60 @logger = .delete(:logger) || Logger.new(STDOUT) @heartbeat_thread = nil @remote_ctrl_thread = nil @socket = SnotiSocket.new() @exited = false end |
Instance Method Details
#start ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/gizwits_sac/snoti_client.rb', line 47 def start listen_shut_down connect_count = 0 begin connect_count += 1 # 1. Connect to Gizwits Snoti API @socket.connect # 2. Login to Gizwits Snoti API and Check if @socket.login_ok? # 3. Exchange data via SnotiSocket exchange else raise LoginError end rescue Exception => e if connect_count < @retry_count retry else # It needs to kill the backgroud thread after all retry failed dispose raise e end end end |