Class: AdwordsApi::ReportStream
- Inherits:
-
Object
- Object
- AdwordsApi::ReportStream
- Defined in:
- lib/adwords_api/report_stream.rb
Class Method Summary collapse
- .set_up(report_utils, report_definition, cid = nil, &block) ⇒ Object
- .set_up_with_awql(report_utils, report_query, format, cid = nil, &block) ⇒ Object
Instance Method Summary collapse
- #each_line ⇒ Object
-
#initialize(report_utils, report_definition, cid = nil, format = nil, is_awql = false, &block) ⇒ ReportStream
constructor
A new instance of ReportStream.
Constructor Details
#initialize(report_utils, report_definition, cid = nil, format = nil, is_awql = false, &block) ⇒ ReportStream
Returns a new instance of ReportStream.
23 24 25 26 27 28 29 30 31 |
# File 'lib/adwords_api/report_stream.rb', line 23 def initialize(report_utils, report_definition, cid = nil, format = nil, is_awql = false, &block) @report_utils = report_utils @report_definition = report_definition @format = format @cid = cid @block = block @is_awql = is_awql end |
Class Method Details
.set_up(report_utils, report_definition, cid = nil, &block) ⇒ Object
33 34 35 |
# File 'lib/adwords_api/report_stream.rb', line 33 def self.set_up(report_utils, report_definition, cid = nil, &block) return ReportStream.new(report_utils, report_definition, cid, &block) end |
.set_up_with_awql(report_utils, report_query, format, cid = nil, &block) ⇒ Object
37 38 39 40 41 |
# File 'lib/adwords_api/report_stream.rb', line 37 def self.set_up_with_awql( report_utils, report_query, format, cid = nil, &block) return ReportStream.new( report_utils, report_query, cid, format, true, &block) end |
Instance Method Details
#each_line ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/adwords_api/report_stream.rb', line 43 def each_line() # Determine which method and arguments to use depending on whether # this is an AWQL request or not. method = 'download_report_as_stream' method += '_with_awql' if @is_awql args = [@report_definition] args << @format if @is_awql args << @cid leftover_data = '' @report_utils.send(method, *args) do |batch| data_to_process = leftover_data + batch lines = data_to_process.split('\n') leftover_data = lines.pop lines.each do |line| @block.call(line) end end @block.call(leftover_data) unless leftover_data.empty?() end |