Class: GnipApi::Apis::PowerTrack::Stream
- Inherits:
-
Object
- Object
- GnipApi::Apis::PowerTrack::Stream
- Defined in:
- lib/gnip_api/apis/power_track/stream.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
- #build_message(params) ⇒ Object
- #consume ⇒ Object
-
#initialize(params = {}) ⇒ Stream
constructor
A new instance of Stream.
- #log_system_messages(entries) ⇒ Object
- #logger ⇒ Object
- #parse_json(json) ⇒ Object
- #process_entries(entries) ⇒ Object
Constructor Details
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
5 6 7 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 5 def adapter @adapter end |
Instance Method Details
#build_message(params) ⇒ Object
45 46 47 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 45 def params Gnip::Message.build(params) end |
#consume ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 17 def consume request = create_request adapter.stream_get request do |chunk| @buffer.insert! chunk begin yield process_entries(@buffer.read!) rescue Exception => e puts e.class puts e. puts e.backtrace[0..10].join("\n") raise e end end end |
#log_system_messages(entries) ⇒ Object
39 40 41 42 43 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 39 def entries entries.select{|| . }.each do || GnipApi.logger.send(.log_method, .) end end |
#logger ⇒ Object
13 14 15 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 13 def logger GnipApi.logger end |
#parse_json(json) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 49 def parse_json json begin JSON.parse json rescue JSON::ParserError nil end end |
#process_entries(entries) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 32 def process_entries entries entries.map!{|e| parse_json(e)}.compact! entries.map!{|e| (e)} (entries) entries end |