Class: Adcloud::Campaign

Inherits:
Entity
  • Object
show all
Defined in:
lib/adcloud/campaign.rb

Constant Summary collapse

TYPES =
{
  cpc: 2,
  cpx: 3,
  cpx_plus: 4,
  cpm: 5,
  fixed_daily_costs: 6
}
DELIVERY_TYPES =
{
  topic: 1,
  channel: 2
}

Constants inherited from Entity

Entity::MAX_PER_PAGE

Instance Attribute Summary

Attributes inherited from Entity

#errors

Instance Method Summary collapse

Methods inherited from Entity

all, all!, api_name, #connection, #create, create, #destroy, find, find_by_name, #meta, #update

Instance Method Details

#end!Object



70
71
72
73
# File 'lib/adcloud/campaign.rb', line 70

def end!
  result = connection.put("campaigns/#{self.id}/end")
  result && result["_meta"] && result["_meta"]["status"] == 200 || false
end

#offer!Object



75
76
77
78
# File 'lib/adcloud/campaign.rb', line 75

def offer!
  result = connection.put("campaigns/#{self.id}/offer")
  result && result["_meta"] && result["_meta"]["status"] == 200 || false
end

#request_approval!Object



65
66
67
68
# File 'lib/adcloud/campaign.rb', line 65

def request_approval!
  result = connection.put("campaigns/#{self.id}/request_approval")
  result && result["_meta"] && result["_meta"]["status"] == 200 || false
end

#valid?Boolean

Returns True when campaign is valid - otherwise false.

Returns:

  • (Boolean)

    True when campaign is valid - otherwise false



81
82
83
84
# File 'lib/adcloud/campaign.rb', line 81

def valid?
  self.validate
  self.errors.empty?
end

#validatevoid

This method returns an undefined value.

Returns Validate the campaign against the api.



56
57
58
59
60
61
62
63
# File 'lib/adcloud/campaign.rb', line 56

def validate
  result = connection.get('campaigns/validate', { campaign: self.attributes_for_create })
  if result && result["_meta"] && result["_meta"]["status"] == 226
    @errors = self.errors.merge(result["_meta"]["details"])
  else
    raise AdcloudUnknownAPIError::InvalidApiResponse.new('Empty response for campaign validation')
  end
end