Class: Sem4r::AdGroup
- Inherits:
-
Base
- Object
- Base
- Sem4r::AdGroup
show all
- Defined in:
- lib/sem4r/ad_group/ad_group.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#adwords, #credentials, #service
Class Method Summary
collapse
Instance Method Summary
collapse
-
#ad_param(criterion, index = nil, text = nil, &block) ⇒ Object
-
#ad_params(refresh = false) ⇒ Object
-
#ads(refresh = false) ⇒ Object
-
#bids(el = nil) ⇒ Object
-
#criterions(refresh = false) ⇒ Object
-
#delete ⇒ Object
-
#empty? ⇒ Boolean
-
#find_criterion(criterion_id, refresh = false) ⇒ Object
-
#id ⇒ Object
-
#initialize(campaign, name = nil, &block) ⇒ AdGroup
constructor
A new instance of AdGroup.
-
#inside_initialize? ⇒ Boolean
-
#keyword(text = nil, match = nil, &block) ⇒ Object
instanziate an BiddableAdGroupCriterion but it is called ‘keyword’ for convenience.
-
#manual_cpc_bids(&block) ⇒ Object
-
#manual_cpm_bids(&block) ⇒ Object
-
#mobile_ad(&block) ⇒ Object
-
#negative_keyword(text = nil, match = CriterionKeyword::BROAD, &block) ⇒ Object
-
#p_ad_params(refresh = false) ⇒ Object
-
#p_ads(refresh = false) ⇒ Object
-
#p_criterions(refresh = false) ⇒ Object
-
#placement(url = nil, &block) ⇒ Object
-
#save ⇒ Object
-
#text_ad(&block) ⇒ Object
-
#to_s ⇒ Object
-
#to_xml(tag) ⇒ Builder::XmlMarkup
Marshall this object to xml.
-
#xml(t) ⇒ Object
Methods inherited from Base
#add_counters
#_from_element, #_to_s, #_to_xml, included
Constructor Details
#initialize(campaign, name = nil, &block) ⇒ AdGroup
Returns a new instance of AdGroup.
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 41
def initialize(campaign, name = nil, &block)
super( campaign.adwords, campaign.credentials )
@campaign = campaign
@id = nil
@criterions = nil
self.name = name unless name.nil?
if block_given?
@inside_initialize = true
block.arity < 1 ? instance_eval(&block) : block.call(self)
save unless campaign.inside_initialize?
end
@inside_initialize = false
end
|
Instance Attribute Details
#campaign ⇒ Object
Returns the value of attribute campaign.
36
37
38
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 36
def campaign
@campaign
end
|
Class Method Details
.create(campaign, &block) ⇒ Object
103
104
105
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 103
def self.create(campaign, &block)
new(campaign, &block).save
end
|
.from_element(campaign, el) ⇒ Object
Unmarshal this object from xml
112
113
114
115
116
117
118
119
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 112
def self.from_element(campaign, el)
new(campaign) do
@id = el.at_xpath("id").text.strip.to_i
name el.at_xpath("name").text.strip
status el.at_xpath("status").text.strip
bids el.at_xpath("bids")
end
end
|
Instance Method Details
#ad_param(criterion, index = nil, text = nil, &block) ⇒ Object
319
320
321
322
323
324
325
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 319
def ad_param(criterion, index = nil, text = nil, &block)
ad_param = AdParam.new(self, criterion, index, text, &block)
ad_param.save unless inside_initialize? or criterion.inside_initialize?
@ad_params ||= []
@ad_params.push( ad_param )
ad_param
end
|
#ad_params(refresh = false) ⇒ Object
327
328
329
330
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 327
def ad_params(refresh = false)
_ad_params unless @ad_params and !refresh
@ad_params
end
|
#ads(refresh = false) ⇒ Object
182
183
184
185
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 182
def ads(refresh = false)
_ads unless @ads and !refresh
@ads
end
|
#bids(el = nil) ⇒ Object
152
153
154
155
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 152
def bids(el = nil)
@bids = AdGroupBids.from_element(el) if el
@bids
end
|
#criterions(refresh = false) ⇒ Object
264
265
266
267
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 264
def criterions(refresh = false)
_criterions unless @criterions and !refresh
@criterions
end
|
#delete ⇒ Object
143
144
145
146
147
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 143
def delete
soap_message = service.ad_group.delete( credentials, @id )
add_counters( soap_message.counters )
@id = -1 end
|
#empty? ⇒ Boolean
96
97
98
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 96
def empty?
criterions.empty?
end
|
#find_criterion(criterion_id, refresh = false) ⇒ Object
276
277
278
279
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 276
def find_criterion(criterion_id, refresh = false)
_criterions unless @criterions and !refresh
@criterions.find {|c| c.id == criterion_id}
end
|
#id ⇒ Object
59
60
61
62
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 59
def id
_save unless @id
@id
end
|
#inside_initialize? ⇒ Boolean
55
56
57
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 55
def inside_initialize?
@inside_initialize
end
|
#keyword(text = nil, match = nil, &block) ⇒ Object
246
247
248
249
250
251
252
253
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 246
def keyword(text = nil, match = nil, &block)
biddable_criterion = BiddableAdGroupCriterion.new(self)
criterion = CriterionKeyword.new(self, text, match, &block)
biddable_criterion.criterion = criterion
@criterions ||= []
@criterions.push( biddable_criterion )
biddable_criterion
end
|
#manual_cpc_bids(&block) ⇒ Object
157
158
159
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 157
def manual_cpc_bids(&block)
@bids = ManualCPCAdGroupBids.new(&block)
end
|
#manual_cpm_bids(&block) ⇒ Object
161
162
163
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 161
def manual_cpm_bids(&block)
@bids = ManualCPMAdGroupBids.new(&block)
end
|
#mobile_ad(&block) ⇒ Object
175
176
177
178
179
180
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 175
def mobile_ad(&block)
ad = AdGroupMobileAd.new(self, &block)
@ads ||= []
@ads.push(ad)
ad
end
|
#negative_keyword(text = nil, match = CriterionKeyword::BROAD, &block) ⇒ Object
232
233
234
235
236
237
238
239
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 232
def negative_keyword(text = nil, match = CriterionKeyword::BROAD, &block)
negative_criterion = NegativeAdGroupCriterion.new(self)
criterion = CriterionKeyword.new(self, text, match, &block)
negative_criterion.criterion = criterion
@criterions ||= []
@criterions.push( negative_criterion )
negative_criterion
end
|
#p_ad_params(refresh = false) ⇒ Object
332
333
334
335
336
337
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 332
def p_ad_params(refresh = false)
ad_params(refresh).each do |ad_param|
puts ad_param.to_s
end
self
end
|
#p_ads(refresh = false) ⇒ Object
187
188
189
190
191
192
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 187
def p_ads(refresh = false)
ads(refresh).each do |ad|
puts ad.to_s
end
self
end
|
#p_criterions(refresh = false) ⇒ Object
269
270
271
272
273
274
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 269
def p_criterions(refresh = false)
criterions(refresh).each do |criterion|
puts criterion.to_s
end
self
end
|
#placement(url = nil, &block) ⇒ Object
255
256
257
258
259
260
261
262
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 255
def placement(url = nil, &block)
biddable_criterion = BiddableAdGroupCriterion.new(self)
criterion = CriterionPlacement.new(self, url, &block)
biddable_criterion.criterion = criterion
@criterions ||= []
@criterions.push( biddable_criterion )
biddable_criterion
end
|
#save ⇒ Object
121
122
123
124
125
126
127
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 121
def save
_save
_save_criterions
_save_ads
_save_ad_params
self
end
|
#text_ad(&block) ⇒ Object
168
169
170
171
172
173
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 168
def text_ad(&block)
ad = AdGroupTextAd.new(self, &block)
@ads ||= []
@ads.push(ad)
ad
end
|
#to_s ⇒ Object
64
65
66
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 64
def to_s
"#{@id ? @id : 'unsaved'} '#{@name}' (#{@status}) - #{@bid}"
end
|
#to_xml(tag) ⇒ Builder::XmlMarkup
Marshall this object to xml
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 85
def to_xml(tag)
builder = Builder::XmlMarkup.new
builder.tag!(tag) { |t|
xml(t)
}
end
|
#xml(t) ⇒ Object
72
73
74
75
76
77
|
# File 'lib/sem4r/ad_group/ad_group.rb', line 72
def xml(t)
t.campaignId campaign.id
t.name name
t.status "ENABLED"
@bids.to_xml(t) if @bids
end
|