Class: Events
- Defined in:
- lib/ff/ruby/server/sdk/connector/events.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(url, headers, updater, config) ⇒ Events
constructor
A new instance of Events.
- #on_closed ⇒ Object
- #on_error(reason = "") ⇒ Object
- #on_message(message) ⇒ Object
- #on_open ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(url, headers, updater, config) ⇒ Events
Returns a new instance of Events.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ff/ruby/server/sdk/connector/events.rb', line 8 def initialize( url, headers, updater, config ) @url = url @headers = headers @headers['params'] = {} @updater = updater @config = config if @updater != nil unless @updater.kind_of?(Updater) raise "The 'callback' parameter must be of '" + Updater.to_s + "' data type" end end if @config.logger != nil @logger = @config.logger else @logger = Logger.new(STDOUT) end @updater.on_ready end |
Instance Method Details
#close ⇒ Object
59 60 61 |
# File 'lib/ff/ruby/server/sdk/connector/events.rb', line 59 def close stop end |
#on_closed ⇒ Object
74 75 76 77 |
# File 'lib/ff/ruby/server/sdk/connector/events.rb', line 74 def on_closed SdkCodes::warn_stream_disconnected @logger, "on_closed called" @updater.on_disconnected end |
#on_error(reason = "") ⇒ Object
68 69 70 71 72 |
# File 'lib/ff/ruby/server/sdk/connector/events.rb', line 68 def on_error(reason="") SdkCodes::warn_stream_disconnected @logger, reason @updater.on_error stop end |
#on_message(message) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/ff/ruby/server/sdk/connector/events.rb', line 79 def () SdkCodes::info_stream_event_received @logger, .to_s msg = JSON.parse() @updater.update(msg) end |
#on_open ⇒ Object
63 64 65 66 |
# File 'lib/ff/ruby/server/sdk/connector/events.rb', line 63 def on_open SdkCodes::info_stream_connected @logger @updater.on_connected end |
#start ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ff/ruby/server/sdk/connector/events.rb', line 37 def start @logger.debug "Starting EventSource service" begin conn = RestClient::Request.execute(method: :get, url: @url, headers: @headers, block_response: proc { |response| response_handler response }, before_execution_proc: nil, log: false, read_timeout: 60, ssl_ca_file: @config.ssl_ca_cert) rescue => e on_error e. end end |
#stop ⇒ Object
54 55 56 57 |
# File 'lib/ff/ruby/server/sdk/connector/events.rb', line 54 def stop @logger.debug "Stopping EventSource service" on_closed end |