Class: FlexBullet::Listener
- Inherits:
-
Object
- Object
- FlexBullet::Listener
- Defined in:
- lib/flex_bullet/listener.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#command ⇒ Object
Returns the value of attribute command.
-
#last_message ⇒ Object
Returns the value of attribute last_message.
-
#sender ⇒ Object
Returns the value of attribute sender.
Instance Method Summary collapse
- #get_1h_history ⇒ Object
- #get_last_message ⇒ Object
-
#initialize(args) ⇒ Listener
constructor
A new instance of Listener.
- #stream(tb_config = nil) ⇒ Object
Constructor Details
#initialize(args) ⇒ Listener
Returns a new instance of Listener.
11 12 13 14 15 16 17 18 19 |
# File 'lib/flex_bullet/listener.rb', line 11 def initialize (args) @user_obj = if args.is_a?(FlexBullet::User) args else FlexBullet::User.new(args[:email], args[:auth], args[:name]) end @tasker = Tasker.new(@user_obj) end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
9 10 11 |
# File 'lib/flex_bullet/listener.rb', line 9 def args @args end |
#command ⇒ Object
Returns the value of attribute command.
9 10 11 |
# File 'lib/flex_bullet/listener.rb', line 9 def command @command end |
#last_message ⇒ Object
Returns the value of attribute last_message.
9 10 11 |
# File 'lib/flex_bullet/listener.rb', line 9 def @last_message end |
#sender ⇒ Object
Returns the value of attribute sender.
9 10 11 |
# File 'lib/flex_bullet/listener.rb', line 9 def sender @sender end |
Instance Method Details
#get_1h_history ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/flex_bullet/listener.rb', line 26 def get_1h_history get_1h_history = Curl::Easy.new("https://api.pushbullet.com/v2/pushes?modified_after=#{(Time.now - 3600).to_i}") { |curl| curl.headers['Authorization'] = "Bearer #{@user_obj.auth}" curl.verbose = false } get_1h_history.perform get_1h_history.body_str end |
#get_last_message ⇒ Object
21 22 23 24 |
# File 'lib/flex_bullet/listener.rb', line 21 def = JSON::parse(get_1h_history)['pushes'].first Message.new(:parsed_json => ) end |
#stream(tb_config = nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/flex_bullet/listener.rb', line 35 def stream (tb_config = nil) FlexConfig.new('/Users/YCL/Documents/RubyProjects/EL_library/tunnel_blick/config', tb_config) unless tb_config.nil? EM.run { ws = Faye::WebSocket::Client.new("wss://stream.pushbullet.com/websocket/#{@user_obj.auth}") ws.on :open do |event| p [:open] end ws.on :message do |event| response = JSON::parse(event.data) if response['type'] == 'nop' print '.' end if response['type'] == 'tickle' && response['subtype'] == 'push' = if .email != @user_obj.email @tasker.incoming() end end end ws.on :close do |event| p [:close, event.code, event.reason] ws = nil end } end |