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
permalink #initialize(params = {}) ⇒ Stream
Returns a new instance of Stream.
7 8 9 10 11 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 7 def initialize params = {} @stream = params[:stream] || GnipApi.config.label @source = params[:source] || GnipApi.config.source set_config end |
Instance Attribute Details
permalink #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
permalink #build_message(params) ⇒ Object
[View source]
45 46 47 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 45 def params Gnip::Message.build(params) end |
permalink #consume ⇒ Object
[View source]
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 |
permalink #log_system_messages(entries) ⇒ Object
[View source]
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 |
permalink #logger ⇒ Object
[View source]
13 14 15 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 13 def logger GnipApi.logger end |
permalink #parse_json(json) ⇒ Object
[View source]
49 50 51 52 53 54 55 |
# File 'lib/gnip_api/apis/power_track/stream.rb', line 49 def parse_json json begin GnipApi::JsonParser.parse json rescue GnipApi::Errors::JsonParser::ParseError nil end end |
permalink #process_entries(entries) ⇒ Object
[View source]
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 |