Class: Sem4r::ReportDefinition
- Inherits:
-
Base
- Object
- Base
- Sem4r::ReportDefinition
show all
- Defined in:
- lib/sem4r/report_definition/report_definition.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
#_from_element, #_to_s, #_to_xml, included
Constructor Details
#initialize(account, name = nil, &block) ⇒ ReportDefinition
Returns a new instance of ReportDefinition.
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 78
def initialize(account, name = nil, &block)
super( account.adwords, account.credentials )
@account = account
self.name = name
if block_given?
@inside_initialize = true
block.arity < 1 ? instance_eval(&block) : block.call(self)
end
@inside_initialize = false
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
29
30
31
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 29
def id
@id
end
|
Class Method Details
.create(account, &block) ⇒ Object
161
162
163
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 161
def self.create(account, &block)
new(account, &block).save
end
|
.from_element(account, el) ⇒ Object
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 149
def self.from_element(account, el)
new(account) do
@id = el.at_xpath("id").text.strip.to_i
name el.at_xpath('reportName').text.strip
type el.at_xpath('reportType').text.strip
format el.at_xpath('downloadFormat').text.strip
end
end
|
Instance Method Details
#_xml(t) ⇒ Object
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 100
def _xml(t)
t.id @id if @id
if !fields.empty? or ( !!from and !!to )
t.selector do |t|
fields.each { |f| t.fields f}
if from and to
t.dateRange do |t|
t.min from
t.max to
end
end
end
end
t.reportName @name if @name
t.reportType @type if @type
t.dateRangeType @date_range if @date_range
t.downloadFormat @format if @format
end
|
#delete ⇒ Object
177
178
179
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 177
def delete
@account.report_definition_delete(self)
end
|
#inside_initialize? ⇒ Boolean
89
90
91
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 89
def inside_initialize?
@inside_initialize
end
|
#save ⇒ Object
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 165
def save
unless @id
op = ReportDefinitionOperation.new.add(self)
soap_message = service.report_definition.mutate(credentials, op.to_xml("operations"))
add_counters( soap_message.counters )
rval = soap_message.response.at_xpath("//mutateResponse/rval")
id = rval.at_xpath("id" )
@id = id.text.strip.to_i
end
self
end
|
#to_s ⇒ Object
93
94
95
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 93
def to_s
"#{@id}: '#{@name}'"
end
|
#to_xml(tag = "operand") ⇒ Object
142
143
144
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 142
def to_xml(tag = "operand")
xml(Builder::XmlMarkup.new, tag)
end
|
#xml(t, tag = nil) ⇒ Object
Marshall to xml using a Builder::Markup
134
135
136
137
138
139
140
|
# File 'lib/sem4r/report_definition/report_definition.rb', line 134
def xml(t, tag = nil)
if tag
t.__send__(tag) { |t| _xml(t) }
else
_xml(t)
end
end
|