Class: Adapi::Ad

Inherits:
Api
  • Object
show all
Defined in:
lib/adapi/ad.rb

Overview

Ad == AdGroupAd wraps all types of ads: text ads, image ads…

Direct Known Subclasses

TextAd

Defined Under Namespace

Classes: TextAd

Constant Summary

Constants inherited from Api

Adapi::Api::API_EXCEPTIONS, Adapi::Api::LOGGER

Instance Attribute Summary collapse

Attributes inherited from Api

#adwords, #params, #service, #status, #version, #xsi_type

Instance Method Summary collapse

Methods inherited from Api

#[], #[]=, #check_for_errors, create, #mutate, #new?, #persisted?, #store_errors, to_micro_units, #to_param, update

Constructor Details

#initialize(params = {}) ⇒ Ad

Returns a new instance of Ad.



22
23
24
25
26
27
28
29
30
# File 'lib/adapi/ad.rb', line 22

def initialize(params = {})
  params[:service_name] = :AdGroupAdService

  %w{ id ad_group_id url display_url status }.each do |param_name|
    self.send "#{param_name}=", params[param_name.to_sym]
  end

  super(params)
end

Instance Attribute Details

#ad_group_idObject

REFACTOR attributes



11
12
13
# File 'lib/adapi/ad.rb', line 11

def ad_group_id
  @ad_group_id
end

#approval_statusObject

REFACTOR attributes



11
12
13
# File 'lib/adapi/ad.rb', line 11

def approval_status
  @approval_status
end

#disapproval_reasonsObject

REFACTOR attributes



11
12
13
# File 'lib/adapi/ad.rb', line 11

def disapproval_reasons
  @disapproval_reasons
end

#display_urlObject

REFACTOR attributes



11
12
13
# File 'lib/adapi/ad.rb', line 11

def display_url
  @display_url
end

#idObject

REFACTOR attributes



11
12
13
# File 'lib/adapi/ad.rb', line 11

def id
  @id
end

#trademark_disapprovedObject

REFACTOR attributes



11
12
13
# File 'lib/adapi/ad.rb', line 11

def trademark_disapproved
  @trademark_disapproved
end

#urlObject

REFACTOR attributes



11
12
13
# File 'lib/adapi/ad.rb', line 11

def url
  @url
end

Instance Method Details

#attributesObject

PS: create won’t work with id and ad_group_id ‘id’ => id, ‘ad_group_id’ => ad_group_id,



18
19
20
# File 'lib/adapi/ad.rb', line 18

def attributes
  super.merge( id: id, ad_group_id: ad_group_id, url: url, display_url: display_url )
end

#delete(params = {}) ⇒ Object

FIXME add validations



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/adapi/ad.rb', line 48

def delete(params = {})
  operations = params[:ad_ids].map do |ad_id|
    {
      :operator => 'REMOVE',
      :operand => {
        :ad_group_id => params[:ad_group_id],
        :ad => { :id => ad_id, :xsi_type => 'Ad' }
      }
    }
  end

  response = self.mutate(operations)

  (response and response[:value]) ? true : false
end

#destroyObject

deletes ad TODO call by delete method



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/adapi/ad.rb', line 35

def destroy
  response = self.mutate(
    :operator => 'REMOVE',
    :operand => {
      :ad_group_id => @ad_group_id,
      :ad => { :id => @id, :xsi_type => 'Ad' }
    }
  )

  (response and response[:value]) ? true : false
end