Class: Sem4r::AdGroupMobileAd

Inherits:
AdGroupAd show all
Defined in:
lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb

Overview

From: code.google.com/apis/adwords/v2009/docs/reference/AdGroupAdService.MobileAd.html

A mobile ad can contain a click-to-call phone number, a link to a website, or both.
You specify which features you want by setting certain fields, as shown in the following table.
For example, to create a click-to-call mobile ad, set the fields in the Click-to-call column.
A hyphen means don't set the corresponding field.

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

Methods included from Sem4rSoap::SoapAttributes

#_from_element, #_to_s, #_to_xml, included

Constructor Details

#initialize(ad_group, &block) ⇒ AdGroupMobileAd

Returns a new instance of AdGroupMobileAd.



42
43
44
45
46
# File 'lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb', line 42

def initialize(ad_group, &block)
  @carriers = []
  self.type = MobileAd
  super
end

Class Method Details

.from_element(ad_group, el) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb', line 103

def self.from_element(ad_group, el)
  new(ad_group) do
    @id         = el.at_xpath("id").text.strip.to_i
    # type          el.at_xpath("Ad.Type").text
    headline       el.at_xpath("headline").text.strip
    description    el.at_xpath("description").text.strip
    business_name  el.at_xpath("businessName").text.strip
    country_code   el.at_xpath("countryCode").text.strip
    phone_number   el.at_xpath("phoneNumber").text.strip
    # TODO: estrarre le carriers
  end
end

Instance Method Details

#_xml(t) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb', line 68

def _xml(t)
  t.adGroupId   ad_group.id
  t.ad("xsi:type" => "MobileAd") do |ad|
    ad.headline        headline
    ad.description     description
    unless markups.empty?
      markups.each do |m|
        ad.markupLanguages m
      end
    end
    unless carriers.empty?
      carriers.each do |carrier|
        ad.mobileCarriers carrier
      end
    end
    ad.businessName    business_name
    ad.countryCode     country_code
    ad.phoneNumber     phone_number
  end
  t.status status
end

#image(&block) ⇒ Object



57
58
59
# File 'lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb', line 57

def image
  @image
end

#saveObject



116
117
118
119
120
121
122
123
124
125
# File 'lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb', line 116

def save
  unless @id
    soap_message = service.ad_group_ad.create( credentials, to_xml("operand") )
    add_counters( soap_message.counters )
    rval = soap_message.response.xpath("//mutateResponse/rval", soap_message.response_headers).first
    id = rval.xpath("value/ad/id").first
    @id = id.text.strip.to_i
  end
  self
end

#to_xml(tag) ⇒ Object



98
99
100
# File 'lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb', line 98

def to_xml(tag)
  xml(Builder::XmlMarkup.new, tag)
end

#xml(t, tag = nil) ⇒ Object



90
91
92
93
94
95
96
# File 'lib/sem4r/ad_group_ad/ad_group_mobile_ad.rb', line 90

def xml(t, tag = nil)
  if tag
    t.__send__(tag, {"xsi:type" => "AdGroupAd"}) { |t| _xml(t) }
  else
    _xml(t)
  end
end