class Iterable::Export

Interact with /export API endpoints

@example Creating an export endpoint object

# With default config
export = Iterable::Export.new
export = Iterable::Export.new Iterable::Export::EMAIL_SEND_TYPE
export.all

# With custom config
conf = Iterable::Config.new(token: 'new-token')
export = Iterable::Export.new(Iterable::Export::EMAIL_SEND_TYPE, nil, nil, nil, config)

Constants

DATA_TYPES
DATE_FORMAT
RANGES

Attributes

campaign_id[R]
data_type[R]
omit_fields[R]
only_fields[R]

Public Class Methods

new(data_type, only_fields = [], omit_fields = [], campaign_id = nil, conf = nil) click to toggle source

Initialize an [Iterable::Export] object to export data from Iterable

@param data_type [String] The type of data to export, one of [Iterable::Export::DATA_TYPES] @param only_fields [Array] Array of fields to only export @param omit_fields [Array] Array of fields to omit @param data_fields [Hash] Additional device data fields @param conf [Iterable::Config] A config to optionally pass for requests

@return [Iterable::Export]

Calls superclass method Iterable::ApiResource::new
# File lib/iterable/export.rb, line 60
def initialize(data_type, only_fields = [], omit_fields = [], campaign_id = nil, conf = nil)
  @data_type = data_type
  @only_fields = only_fields
  @omit_fields = omit_fields
  @campaign_id = campaign_id
  super conf
end

Public Instance Methods

export(start_time, end_time) click to toggle source

Export data between a start and end time

@param start_time [Time] The start time of the data to export @param end_time [Time] The end time of the data to export

@return [Iterable::Response] A response object

# File lib/iterable/export.rb, line 86
def export(start_time, end_time)
  params = {
    startDateTime: start_time.strftime(Iterable::Export::DATE_FORMAT),
    endDateTime: end_time.strftime(Iterable::Export::DATE_FORMAT)
  }
  Iterable.request(conf, base_path, request_params(params)).get
end
export_range(range = Iterable::Export::TODAY) click to toggle source

Export data given a valid range constant [Iterable::Export::RANGES]

@param range [Iterable::Export::RANGES] A valid range to export data for

@return [Iterable::Response] A response object

# File lib/iterable/export.rb, line 101
def export_range(range = Iterable::Export::TODAY)
  params = { range: range }
  Iterable.request(conf, base_path, request_params(params)).get
end
format() click to toggle source

The format of the exporter to be implemented by a subclass

@example Formats are currently csv or json

@return [Exception] Raises an exception

# File lib/iterable/export.rb, line 74
def format
  raise '#format must be implemented in child class'
end

Protected Instance Methods

base_path() click to toggle source
# File lib/iterable/export.rb, line 108
def base_path
  "/export/data.#{format}"
end
default_params() click to toggle source
# File lib/iterable/export.rb, line 116
def default_params
  params = { dataTypeName: @data_type }
  params[:onlyFields] = @only_fields if @only_fields && @only_fields.length.positive?
  params[:omitFields] = @omit_fields.join(',') if @omit_fields && @omit_fields.length.positive?
  params[:campaignId] = @campaign_id if @campaign_id
  params
end
request_params(params = {}) click to toggle source
# File lib/iterable/export.rb, line 112
def request_params(params = {})
  default_params.merge params
end