Class: Sem4r::AdParam
Instance Attribute Summary collapse
-
#ad_group ⇒ Object
readonly
Returns the value of attribute ad_group.
-
#criterion ⇒ Object
readonly
Returns the value of attribute criterion.
Attributes inherited from Base
#adwords, #credentials, #service
Class Method Summary collapse
Instance Method Summary collapse
-
#_xml(t) ⇒ Object
adGroupId Id of ad_group This field is required and should not be null.
-
#initialize(ad_group, criterion, index = nil, text = nil, &block) ⇒ AdParam
constructor
A new instance of AdParam.
- #save ⇒ Object
- #saved? ⇒ Boolean
- #to_s ⇒ Object
- #to_xml(tag) ⇒ Object
-
#xml(t, tag = nil) ⇒ Object
Marshall to xml.
Methods inherited from Base
Methods included from Sem4rSoap::SoapAttributes
#_from_element, #_to_s, #_to_xml, included
Constructor Details
#initialize(ad_group, criterion, index = nil, text = nil, &block) ⇒ AdParam
Returns a new instance of AdParam.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sem4r/ad_param/ad_param.rb', line 34 def initialize(ad_group, criterion, index = nil, text = nil, &block) super( ad_group.adwords, ad_group.credentials ) @saved = false @ad_group = ad_group @criterion = criterion self.index = index unless index.nil? self.text = text unless text.nil? if block_given? block.arity < 1 ? instance_eval(&block) : block.call(self) save unless criterion.inside_initialize? or ad_group.inside_initialize? end end |
Instance Attribute Details
#ad_group ⇒ Object (readonly)
Returns the value of attribute ad_group.
28 29 30 |
# File 'lib/sem4r/ad_param/ad_param.rb', line 28 def ad_group @ad_group end |
#criterion ⇒ Object (readonly)
Returns the value of attribute criterion.
29 30 31 |
# File 'lib/sem4r/ad_param/ad_param.rb', line 29 def criterion @criterion end |
Class Method Details
.from_element(ad_group, el) ⇒ Object
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/sem4r/ad_param/ad_param.rb', line 90 def self.from_element(ad_group, el) criterion_id = el.at_xpath("criterionId").text.strip.to_i criterion = ad_group.find_criterion(criterion_id) new(ad_group, criterion) do # ad_param don't have id so use @saved to indicate if readed from xml @saved = true index el.at_xpath("paramIndex").text.strip.to_i text el.at_xpath("insertionText").text.strip end end |
Instance Method Details
#_xml(t) ⇒ Object
adGroupId Id of ad_group This field is required and should not be null. criterionId The id of the Keyword criterion that this ad parameter applies to.
The keyword must be associated with the same ad_group as this AdParam.
This field is required and should not be null.
insertionText Numeric value or currency value (eg. 15, $99.99) to insert into the ad text
This field is required and should not be null when it is contained
within Operators : SET. The length of this string should be
between 1 and 25, inclusive.
paramIndex
66 67 68 69 70 71 |
# File 'lib/sem4r/ad_param/ad_param.rb', line 66 def _xml(t) t.adGroupId @ad_group.id t.criterionId @criterion.id t.insertionText @text t.paramIndex @index end |
#save ⇒ Object
101 102 103 104 105 106 107 108 109 |
# File 'lib/sem4r/ad_param/ad_param.rb', line 101 def save return if @saved o = AdParamOperation.new.set( self ) = service.ad_param.mutate( credentials, o.to_xml("operations") ) add_counters( .counters ) # ignore response ad_param doesn't have id @saved = true self end |
#saved? ⇒ Boolean
47 48 49 |
# File 'lib/sem4r/ad_param/ad_param.rb', line 47 def saved? @saved end |
#to_s ⇒ Object
51 52 53 |
# File 'lib/sem4r/ad_param/ad_param.rb', line 51 def to_s "#{@id} #{@index} #{@text}" end |
#to_xml(tag) ⇒ Object
85 86 87 |
# File 'lib/sem4r/ad_param/ad_param.rb', line 85 def to_xml(tag) xml(Builder::XmlMarkup.new, tag) end |
#xml(t, tag = nil) ⇒ Object
Marshall to xml
77 78 79 80 81 82 83 |
# File 'lib/sem4r/ad_param/ad_param.rb', line 77 def xml(t, tag = nil) if tag t.__send__(tag) { |t| _xml(t) } else _xml(t) end end |