Class: WhatCounts::List

Inherits:
Object
  • Object
show all
Defined in:
lib/whatcounts/list.rb

Defined Under Namespace

Classes: MissingRequiredListOptionError, UnknownListOptionError

Constant Summary collapse

REQUIRED_OPTIONS =

Options which are required for new/create

[:name]
VALID_OPTIONS =

List of options which this class will accept

OPTIONS_TO_HTTP_PARAMS_MAP.keys
SUBSCRIBE_OPTIONS_TO_HTTP_PARAMS_MAP =
{:list => :list_id, :format => :format,
:force_subscribe => :force_sub, :data => :data }
SUBSCRIBE_REQUIRED_OPTIONS =
[:list]
SUBSCRIBE_IRREGULAR_OPTIONS =
[:data]
LAUNCH_OPTIONS_TO_HTTP_PARAMS_MAP =
{:list => :list_id, :template => :template_id,
:subject => :subject, :format => :format,
:segmentation_id => :segmentation_id, :campaign_alias => :campaign_alias, 
:send_rss => :target_rss, :virtual_mta => :vmta, 
:goodmail_token => :gm_token_type, :notification_email => :notify_email }
LAUNCH_REQUIRED_OPTIONS =
[:list]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ List

Returns a new instance of List.



25
26
27
28
29
# File 'lib/whatcounts/list.rb', line 25

def initialize(options)
  options.each_key {|o| raise UnknownOptionError,"Unknown option #{o}" unless VALID_OPTIONS.include? o}
  REQUIRED_OPTIONS.each {|o| raise MissingRequiredOptionError,"Missing required option #{o}" unless options.has_key? o}
  options.each_pair {|k,v| self.send :"#{k}=",v}
end

Class Method Details

.create!(options) ⇒ Object



51
52
53
54
# File 'lib/whatcounts/list.rb', line 51

def create!(options)
  o = self.new options
  o.create!
end

Instance Method Details

#add_recipients!(recipient_ary) ⇒ Object



61
62
63
64
65
# File 'lib/whatcounts/list.rb', line 61

def add_recipients!(recipient_ary)
  options = {:list => @id, :format => 99, :force_subscribe => 1}
  options[:data] = (['email']+recipient_ary).join('^')
  res = WhatCounts::HttpClient.execute('sub',convert_to_whatcounts_parameters(options,SUBSCRIBE_OPTIONS_TO_HTTP_PARAMS_MAP,SUBSCRIBE_IRREGULAR_OPTIONS))
end

#create!Object



31
32
33
34
35
36
37
38
39
# File 'lib/whatcounts/list.rb', line 31

def create!
  res = WhatCounts::HttpClient.execute('excreatelist',self)
  if res.success?
    self.instance_variable_set(:@id,res.body.to_i) 
    return self
  else
    raise CreationError, res.body # this is actually the message of why it failed
  end
end

#idObject



41
# File 'lib/whatcounts/list.rb', line 41

def id; @id end

#launch!(options = {}) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/whatcounts/list.rb', line 73

def launch!(options={})
  # options.each_key {|o| raise UnknownListOptionError,"Unknown option #{o}" unless VALID_OPTIONS.include? o}
  options = {:list => @id, :format => 99}.merge(options)
  res = WhatCounts::HttpClient.execute('launch',convert_to_whatcounts_parameters(options,LAUNCH_OPTIONS_TO_HTTP_PARAMS_MAP))
  if res.success?
    return res
  else
    puts res.url
    raise DeployError, res.body
  end
end

#to_param_stringObject



42
43
44
45
46
47
48
# File 'lib/whatcounts/list.rb', line 42

def to_param_string
  @param_string ||= OPTIONS_TO_HTTP_PARAMS_MAP.keys.inject([]) do |acc,k|
    val = self.send :"#{k}"
    acc << "#{OPTIONS_TO_HTTP_PARAMS_MAP[k]}=#{CGI.escape(val.to_s)}" unless val.nil?
    acc
  end.join("&")
end