Class: Iterable::Campaigns

Inherits:
ApiResource show all
Defined in:
lib/iterable/campaigns.rb

Overview

Interact with /campaigns API endpoints

Examples:

Creating campaigns endpoint object

# With default config
campaigns = Iterable::Campaigns.new
campaigns.all

# With custom config
conf = Iterable::Config.new(token: 'new-token')
campaigns = Iterable::Campaigns.new(config)

Instance Attribute Summary

Attributes inherited from ApiResource

#conf

Instance Method Summary collapse

Methods inherited from ApiResource

#default_config, default_config, #initialize

Constructor Details

This class inherits a constructor from Iterable::ApiResource

Instance Method Details

#allIterable::Response

Get all campaigns

Returns:



20
21
22
# File 'lib/iterable/campaigns.rb', line 20

def all
  Iterable.request(conf, '/campaigns').get
end

#create(name, template_id, list_ids = [], attrs = {}) ⇒ Iterable::Response

Create a new campaign. Requires a name, templateId and at least one listId

Parameters:

  • name (String)

    The name of the campaign

  • template_id (Integer)

    The templateId to use for the campaign

  • list_ids (Array) (defaults to: [])

    Array of listIds to use for the campaign

  • attrs (Hash) (defaults to: {})

    Any other campaign attributes to set

Returns:



34
35
36
37
# File 'lib/iterable/campaigns.rb', line 34

def create(name, template_id, list_ids = [], attrs = {})
  body = attrs.merge(name: name, templateId: template_id, listIds: list_ids)
  Iterable.request(conf, '/campaigns/create').post(body)
end

#metrics(campaign_ids = [], start_time = nil, end_time = nil) ⇒ Iterable::Response

Export metrics in CSV format for one or more campaigns

Parameters:

  • name (Array)

    An array of campaign ids, must have at least one

  • start_time (Date|Time) (defaults to: nil)

    Start of metrics to query for

  • end_time (Date|Time) (defaults to: nil)

    End of metrics to query for

Returns:



59
60
61
62
63
64
65
66
# File 'lib/iterable/campaigns.rb', line 59

def metrics(campaign_ids = [], start_time = nil, end_time = nil)
  params = { campaignId: campaign_ids }
  if start_time
    params[:startTime] = start_time.to_date.strftime(Iterable::DATE_FORMAT)
    params[:endTime] = end_time.to_date.strftime(Iterable::DATE_FORMAT)
  end
  Iterable.request(conf, '/campaigns/metrics', params).get
end

#recurring(campaign_id) ⇒ Iterable::Response

Get recurring child campaigns for a campaign

Parameters:

  • campaign_id (Integer)

    Root campaign ID to get child recurring campaigns for

Returns:



46
47
48
# File 'lib/iterable/campaigns.rb', line 46

def recurring(campaign_id)
  Iterable.request(conf, "/campaigns/recurring/#{campaign_id}/childCampaigns").get
end