Class: Sem4r::Report

Inherits:
Base
  • Object
show all
Defined in:
lib/sem4r/v13_report/report.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#adwords, #credentials, #service

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_counters

Methods included from Sem4rSoap::SoapAttributes

#_from_element, #_to_s, #_to_xml, included

Constructor Details

#initialize(account, &block) ⇒ Report

Returns a new instance of Report.



86
87
88
89
90
91
92
# File 'lib/sem4r/v13_report/report.rb', line 86

def initialize(, &block)
  super( .adwords, .credentials )
  @account = 
  if block_given?
    block.arity < 1 ? instance_eval(&block) : block.call(self)
  end
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



62
63
64
# File 'lib/sem4r/v13_report/report.rb', line 62

def 
  @account
end

#idObject (readonly)

Returns the value of attribute id.



61
62
63
# File 'lib/sem4r/v13_report/report.rb', line 61

def id
  @id
end

Class Method Details

.from_element(account, el) ⇒ Object



136
137
138
139
140
141
142
143
144
# File 'lib/sem4r/v13_report/report.rb', line 136

def self.from_element(, el)
  new() do
    @id       = el.at_xpath("id").text.strip.to_i # id is read only
    name        el.at_xpath("name").text.strip
    start_day   el.at_xpath("startDay").text.strip
    end_day     el.at_xpath("endDay").text.strip
    @status   = el.at_xpath("status").text.strip # status is read only
  end
end

Instance Method Details

#days(start_day, end_day) ⇒ Object



69
70
71
72
# File 'lib/sem4r/v13_report/report.rb', line 69

def days(start_day, end_day)
  self.start_day start_day
  self.end_day end_day
end

#download(path_name) ⇒ Object



185
186
187
# File 'lib/sem4r/v13_report/report.rb', line 185

def download(path_name)
  service.report.download(url, path_name)
end

#scheduleObject



168
169
170
171
172
173
174
175
# File 'lib/sem4r/v13_report/report.rb', line 168

def schedule
  soap_message = service.report.schedule(credentials, to_xml)
  add_counters( soap_message.counters )
  el = soap_message.response.xpath("//scheduleReportJobResponse/scheduleReportJobReturn").first
  @id = el.text
  # puts "requested report assigned job nr. #{@job_id}"
  ReportJob.new(self, @id)
end

#status(refresh = false) ⇒ Object



148
149
150
151
152
153
154
# File 'lib/sem4r/v13_report/report.rb', line 148

def status(refresh = false)
  return @status unless refresh
  soap_message = service.report.status(credentials, @id)
  add_counters( soap_message.counters )
  el = soap_message.response.xpath("//getReportJobStatusResponse/getReportJobStatusReturn").first
  @status = el.text
end

#to_sObject



94
95
96
# File 'lib/sem4r/v13_report/report.rb', line 94

def to_s
  "#{id} '#{name}' #{status}"
end

#to_xmlObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/sem4r/v13_report/report.rb', line 117

def to_xml
  builder = Builder::XmlMarkup.new
  builder.job("xsi:type" => "DefinedReportJob") do |t|
    xml(t)
    #        job.name                name
    #        job.selectedReportType  type
    #        job.startDay            start_day
    #        job.endDay              end_day
    #        job.aggregationTypes    aggregation
    #
    #        job.crossClient           cross_client
    #        job.includeZeroImpression zero_impression
    #
    #        columns.each do |column|
    #          job.selectedColumns column
    #        end
  end
end

#urlObject



177
178
179
180
181
182
183
# File 'lib/sem4r/v13_report/report.rb', line 177

def url
  soap_message = service.report.url(credentials, @id)
  add_counters( soap_message.counters )
  el = soap_message.response.xpath("//getReportDownloadUrlResponse/getReportDownloadUrlReturn").first
  url = el.text
  url
end

#validateObject

Validate the report definition to make sure it is valid. If it is not, an AdWords::Error::ApiError will be thrown.



158
159
160
161
162
163
164
165
166
# File 'lib/sem4r/v13_report/report.rb', line 158

def validate
  begin
    service.report.validate(credentials, to_xml)
    return true
  rescue SoapError => e
    puts e
  end
  return false
end

#xml(t) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/sem4r/v13_report/report.rb', line 98

def xml(t)
  t.name                name
  t.selectedReportType  type
  t.startDay            start_day
  t.endDay              end_day
  t.aggregationTypes    aggregation

  t.crossClient           cross_client
  t.includeZeroImpression zero_impression

  client_emails.each do |email|
    t.clientEmails email
  end unless client_emails.empty?

  columns.each do |column|
    t.selectedColumns column
  end
end