Class: Sem4r::BulkMutateJob

Inherits:
Object
  • Object
show all
Includes:
Sem4rSoap::SoapAttributes
Defined in:
lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sem4rSoap::SoapAttributes

#_from_element, #_to_s, #_to_xml, included

Constructor Details

#initialize(&block) ⇒ BulkMutateJob

Returns a new instance of BulkMutateJob.



36
37
38
39
40
41
42
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 36

def initialize(&block)
  @operations = []
  @num_parts  = 1
  if block_given?
    block.arity < 1 ? instance_eval(&block) : block.call(self)
  end
end

Instance Attribute Details

#campaign_idObject

Returns the value of attribute campaign_id.



30
31
32
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 30

def campaign_id
  @campaign_id
end

#idObject (readonly)

Returns the value of attribute id.



29
30
31
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 29

def id
  @id
end

#num_partsObject

Returns the value of attribute num_parts.



32
33
34
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 32

def num_parts
  @num_parts
end

#operationsObject (readonly)

Returns the value of attribute operations.



31
32
33
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 31

def operations
  @operations
end

Class Method Details

.from_element(el) ⇒ Object



101
102
103
104
105
106
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 101

def self.from_element(el)
  new do
    @id = el.at_xpath("id").text.strip.to_i
    status el.at_xpath("status").text
  end
end

Instance Method Details

#_xml(t) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 66

def _xml(t)
  if @id
    t.id id
  else
    t.request do |t|
      t.partIndex 0

      t.operationStreams do |t|
        t.scopingEntityId do |t|
          t.type "CAMPAIGN_ID"
          t.value campaign_id
        end
        @operations.each { |operation| operation.xml(t, "operations") } if @operations
      end
    end
    t.numRequestParts num_parts
  end
end

#add(something) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 53

def add(something)
  case something
    when AdGroupTextAd
      ad_operation = AdGroupAdOperation.add something
    else
      raise "how you suppose I must do when incounter a #{something.class}?"
  end
  self
end

#add_operation(operation) ⇒ Object



44
45
46
47
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 44

def add_operation(operation)
  @operations << operation
  self
end

#empty?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 49

def empty?
  @operations.empty?
end

#to_sObject



108
109
110
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 108

def to_s
  "#{@id} #{status}"
end

#to_xml(tag = "operand") ⇒ Object



97
98
99
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 97

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

#xml(t, tag = nil) ⇒ Object

Marshal to xml using Builder



89
90
91
92
93
94
95
# File 'lib/sem4r/bulk_mutate_job/bulk_mutate_job.rb', line 89

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