Class: Sem4r::AdGroupTextAd
Instance Attribute Summary
Attributes inherited from AdGroupAd
#ad_group, #type
Attributes inherited from Base
#adwords, #credentials, #service
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from AdGroupAd
#id, #saved?
Methods inherited from Base
#add_counters
#_from_element, #_to_s, #_to_xml, included
Constructor Details
#initialize(ad_group, &block) ⇒ AdGroupTextAd
Returns a new instance of AdGroupTextAd.
33
34
35
36
|
# File 'lib/sem4r/ad_group_ad/ad_group_text_ad.rb', line 33
def initialize(ad_group, &block)
self.type = TextAd
super
end
|
Class Method Details
.create(ad_group, &block) ⇒ Object
85
86
87
|
# File 'lib/sem4r/ad_group_ad/ad_group_text_ad.rb', line 85
def self.create(ad_group, &block)
new(ad_group, &block).save
end
|
.from_element(ad_group, el) ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/sem4r/ad_group_ad/ad_group_text_ad.rb', line 73
def self.from_element(ad_group, el)
new(ad_group) do
@id = el.at_xpath("id").text.strip.to_i
url el.at_xpath("url").text.strip
display_url el.at_xpath("displayUrl").text.strip
headline el.at_xpath("headline").text.strip
description1 el.at_xpath("description1").text.strip
description2 el.at_xpath("description2").text.strip
end
end
|
Instance Method Details
#_xml(t) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/sem4r/ad_group_ad/ad_group_text_ad.rb', line 45
def _xml(t)
t.adGroupId ad_group.id
t.ad("xsi:type" => "TextAd") do |ad|
ad.url url
ad.displayUrl display_url
ad.headline headline
ad.description1 description1
ad.description2 description2
end
t.status status
end
|
#save ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/sem4r/ad_group_ad/ad_group_text_ad.rb', line 89
def save
unless @id
ad_operation = AdGroupAdOperation.new.add self
soap_message = service.ad_group_ad.mutate(credentials, ad_operation.to_xml("operations"))
add_counters( soap_message.counters )
rval = soap_message.response.xpath("//mutateResponse/rval").first
id = rval.xpath("value/ad/id").first
@id = id.text.strip.to_i
end
self
end
|
#to_s ⇒ Object
38
39
40
|
# File 'lib/sem4r/ad_group_ad/ad_group_text_ad.rb', line 38
def to_s
"#{@id} textad '#{headline}' #{url}"
end
|
#to_xml(tag) ⇒ Object
68
69
70
|
# File 'lib/sem4r/ad_group_ad/ad_group_text_ad.rb', line 68
def to_xml(tag)
xml(Builder::XmlMarkup.new, tag)
end
|
#xml(t, tag = nil) ⇒ Object
Marshall with Builder::XmlMarkup
60
61
62
63
64
65
66
|
# File 'lib/sem4r/ad_group_ad/ad_group_text_ad.rb', line 60
def xml(t, tag = nil)
if tag
t.__send__(tag, "xsi:type" => "AdGroupAd") { |t| _xml(t) }
else
_xml(t)
end
end
|