Class: GizwitsSac::SnotiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/gizwits_sac/snoti_client.rb

Instance Method Summary collapse

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(options)
	@event_push = options.delete(:event_push) || (Proc.new {|event_push_data| })
	@remote_ctrl = options.delete(:remote_ctrl) || (Proc.new { return nil })
	@remote_ctrl_res = options.delete(:remote_ctrl_res) || (Proc.new {|r_ctrl_data| })
	@error_res = options[:error_res] || (Proc.new {|err_data| })
	@retry_count = options.delete(:retry_count) || 5
	@heartbeat_interval = options.delete(:heartbeat_interval) || 60
	@logger = options.delete(:logger) || Logger.new(STDOUT)
	@heartbeat_thread = nil
	@remote_ctrl_thread = nil
	@socket = SnotiSocket.new(options)
	@exited = false
end

Instance Method Details

#startObject



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.
			# 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