Class: Mailchimp::Campaigns

Inherits:
Object
  • Object
show all
Defined in:
lib/mailchimp/api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(master) ⇒ Campaigns



1270
1271
1272
# File 'lib/mailchimp/api.rb', line 1270

def initialize(master)
    @master = master
end

Instance Attribute Details

#masterObject

Returns the value of attribute master.



1268
1269
1270
# File 'lib/mailchimp/api.rb', line 1268

def master
  @master
end

Instance Method Details

#content(cid, options = []) ⇒ Hash

Get the content (both html and text) for a campaign either as it would appear in the campaign archive or as the raw, original content



1285
1286
1287
1288
# File 'lib/mailchimp/api.rb', line 1285

def content(cid, options=[])
    _params = {:cid => cid, :options => options}
    return @master.call 'campaigns/content', _params
end

#create(type, options, content, segment_opts = nil, type_opts = nil) ⇒ Hash

Create a new draft campaign to send. You can not have more than 32,000 campaigns in your account.



1383
1384
1385
1386
# File 'lib/mailchimp/api.rb', line 1383

def create(type, options, content, segment_opts=nil, type_opts=nil)
    _params = {:type => type, :options => options, :content => content, :segment_opts => segment_opts, :type_opts => type_opts}
    return @master.call 'campaigns/create', _params
end

#delete(cid) ⇒ Hash

Delete a campaign. Seriously, "poof, gone!" - be careful! Seriously, no one can undelete these.



1392
1393
1394
1395
# File 'lib/mailchimp/api.rb', line 1392

def delete(cid)
    _params = {:cid => cid}
    return @master.call 'campaigns/delete', _params
end

#list(filters = [], start = 0, limit = 25, sort_field = 'create_time', sort_dir = 'DESC') ⇒ Hash

Get the list of campaigns and their details matching the specified filters



1464
1465
1466
1467
# File 'lib/mailchimp/api.rb', line 1464

def list(filters=[], start=0, limit=25, sort_field='create_time', sort_dir='DESC')
    _params = {:filters => filters, :start => start, :limit => limit, :sort_field => sort_field, :sort_dir => sort_dir}
    return @master.call 'campaigns/list', _params
end

#pause(cid) ⇒ Hash

Pause an AutoResponder or RSS campaign from sending



1473
1474
1475
1476
# File 'lib/mailchimp/api.rb', line 1473

def pause(cid)
    _params = {:cid => cid}
    return @master.call 'campaigns/pause', _params
end

#ready(cid) ⇒ Hash

Returns information on whether a campaign is ready to send and possible issues we may have detected with it - very similar to the confirmation step in the app.



1481
1482
1483
1484
# File 'lib/mailchimp/api.rb', line 1481

def ready(cid)
    _params = {:cid => cid}
    return @master.call 'campaigns/ready', _params
end

#replicate(cid) ⇒ Hash

Replicate a campaign.



1489
1490
1491
1492
# File 'lib/mailchimp/api.rb', line 1489

def replicate(cid)
    _params = {:cid => cid}
    return @master.call 'campaigns/replicate', _params
end

#resume(cid) ⇒ Hash

Resume sending an AutoResponder or RSS campaign



1498
1499
1500
1501
# File 'lib/mailchimp/api.rb', line 1498

def resume(cid)
    _params = {:cid => cid}
    return @master.call 'campaigns/resume', _params
end

#schedule(cid, schedule_time, schedule_time_b = nil) ⇒ Hash

Schedule a campaign to be sent in the future



1509
1510
1511
1512
# File 'lib/mailchimp/api.rb', line 1509

def schedule(cid, schedule_time, schedule_time_b=nil)
    _params = {:cid => cid, :schedule_time => schedule_time, :schedule_time_b => schedule_time_b}
    return @master.call 'campaigns/schedule', _params
end

#schedule_batch(cid, schedule_time, num_batches = 2, stagger_mins = 5) ⇒ Hash

Schedule a campaign to be sent in batches sometime in the future. Only valid for "regular" campaigns



1521
1522
1523
1524
# File 'lib/mailchimp/api.rb', line 1521

def schedule_batch(cid, schedule_time, num_batches=2, stagger_mins=5)
    _params = {:cid => cid, :schedule_time => schedule_time, :num_batches => num_batches, :stagger_mins => stagger_mins}
    return @master.call 'campaigns/schedule-batch', _params
end

#segment_test(list_id, options) ⇒ Hash

Allows one to test their segmentation rules before creating a campaign using them



1533
1534
1535
1536
# File 'lib/mailchimp/api.rb', line 1533

def segment_test(list_id, options)
    _params = {:list_id => list_id, :options => options}
    return @master.call 'campaigns/segment-test', _params
end

#send(cid) ⇒ Hash

Send a given campaign immediately. For RSS campaigns, this will "start" them.



1542
1543
1544
1545
# File 'lib/mailchimp/api.rb', line 1542

def send(cid)
    _params = {:cid => cid}
    return @master.call 'campaigns/send', _params
end

#send_test(cid, test_emails = [], send_type = 'html') ⇒ Hash

Send a test of this campaign to the provided email addresses



1553
1554
1555
1556
# File 'lib/mailchimp/api.rb', line 1553

def send_test(cid, test_emails=[], send_type='html')
    _params = {:cid => cid, :test_emails => test_emails, :send_type => send_type}
    return @master.call 'campaigns/send-test', _params
end

#template_content(cid) ⇒ Hash

Get the HTML template content sections for a campaign. Note that this will return very jagged, non-standard results based on the template a campaign is using. You only want to use this if you want to allow editing template sections in your application.



1561
1562
1563
1564
# File 'lib/mailchimp/api.rb', line 1561

def template_content(cid)
    _params = {:cid => cid}
    return @master.call 'campaigns/template-content', _params
end

#unschedule(cid) ⇒ Hash

Unschedule a campaign that is scheduled to be sent in the future



1570
1571
1572
1573
# File 'lib/mailchimp/api.rb', line 1570

def unschedule(cid)
    _params = {:cid => cid}
    return @master.call 'campaigns/unschedule', _params
end

#update(cid, name, value) ⇒ Hash

Update just about any setting besides type for a campaign that has not been sent. See campaign/create for details. Caveats:

  • If you set a new list_id, all segmentation options will be deleted and must be re-added.
  • If you set template_id, you need to follow that up by setting it's 'content'
  • If you set segment_opts, you should have tested your options against campaign/segment-test().
  • To clear/unset segment_opts, pass an empty string or array as the value. Various wrappers may require one or the other.



1585
1586
1587
1588
# File 'lib/mailchimp/api.rb', line 1585

def update(cid, name, value)
    _params = {:cid => cid, :name => name, :value => value}
    return @master.call 'campaigns/update', _params
end