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.
18 19 20 21 22 23 24 25 26 |
# File 'lib/flex_bullet/listener.rb', line 18 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.
16 17 18 |
# File 'lib/flex_bullet/listener.rb', line 16 def args @args end |
#command ⇒ Object
Returns the value of attribute command.
16 17 18 |
# File 'lib/flex_bullet/listener.rb', line 16 def command @command end |
#last_message ⇒ Object
Returns the value of attribute last_message.
16 17 18 |
# File 'lib/flex_bullet/listener.rb', line 16 def @last_message end |
#sender ⇒ Object
Returns the value of attribute sender.
16 17 18 |
# File 'lib/flex_bullet/listener.rb', line 16 def sender @sender end |
Instance Method Details
#get_1h_history ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/flex_bullet/listener.rb', line 33 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
28 29 30 31 |
# File 'lib/flex_bullet/listener.rb', line 28 def = JSON::parse(get_1h_history)['pushes'].first Message.new(:parsed_json => ) end |
#stream(tb_config = nil) ⇒ Object
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 69 70 71 72 73 74 75 |
# File 'lib/flex_bullet/listener.rb', line 42 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 |