Class: Videojuicer::Campaign::CampaignPolicy

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/videojuicer/campaign_policy.rb

Instance Attribute Summary collapse

Attributes included from Videojuicer::Configurable

#local_config

Instance Method Summary collapse

Methods included from Resource

#destroy, #errors, #errors=, #errors_on, included, #new_record?, #reload, #save, #update_attributes, #valid?, #validate_response

Methods included from Resource::Relationships::BelongsTo

included

Methods included from Resource::PropertyRegistry

#attr_get, #attr_set, #attributes, #attributes=, #coerce_value, #default_attributes, included, inherited, #initialize, #returnable_attributes

Methods included from Resource::Inferrable

included

Methods included from OAuth::ProxyFactory

#proxy_for

Methods included from Videojuicer::Configurable

#api_version, #config, #configure!, #consumer_key, #consumer_secret, #host, #port, #protocol, #scope, #seed_name, #token, #token_secret, #user_id

Instance Attribute Details

#criteriaObject

Returns the value of attribute criteria.



16
17
18
# File 'lib/videojuicer/campaign_policy.rb', line 16

def criteria
  @criteria
end

Instance Method Details

#add_criteria(*criteria) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/videojuicer/campaign_policy.rb', line 57

def add_criteria(*criteria)
  responses = criteria.map do |criterion|
    proxy_for(config).post("#{path_for_dependents}#{criterion.class.base_path}", {:criterion => criterion.attributes})
  end
  self.reload
  responses
end

#add_promo(*promos) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/videojuicer/campaign_policy.rb', line 95

def add_promo(*promos)
  responses = promos.map do |promo|
    proxy_for(config).post("#{path_for_dependents}#{promo.class.base_path}", {:promo => promo.attributes})
  end
  self.reload
  responses
end

#path_for_dependentsObject



111
112
113
# File 'lib/videojuicer/campaign_policy.rb', line 111

def path_for_dependents
  self.class.compile_route(self.class.nesting_route,{:campaign_policy_id => self.id, :campaign_id => self.campaign_id})
end

#promosObject



83
84
85
# File 'lib/videojuicer/campaign_policy.rb', line 83

def promos
  @promos.values.flatten
end

#promos=(object_hash = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
# File 'lib/videojuicer/campaign_policy.rb', line 73

def promos=(object_hash={})
  @promos = {}
  object_hash.map do |type_sym, promos|
    @promos[type_sym.to_sym] = 
    promos.map do |promo|
      Videojuicer::Promo.model_map[type_sym.to_sym].new(promo)
    end
  end
end

#remove_criteria(*criteria) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/videojuicer/campaign_policy.rb', line 65

def remove_criteria(*criteria)
  responses = criteria.map do |criterion|
    proxy_for(config).delete("#{path_for_dependents}#{criterion.class.base_path}", {:criterion => criterion.attributes})
  end
  self.reload
  responses
end

#remove_promo(*promos) ⇒ Object



103
104
105
106
107
108
109
# File 'lib/videojuicer/campaign_policy.rb', line 103

def remove_promo(*promos)
  responses = promos.map do |promo|
    proxy_for(config).delete("#{path_for_dependents}#{promo.class.base_path}", {:promo => promo.attributes})
  end
  self.reload
  responses
end