Class: Iterable::Export

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

Overview

Interact with /export API endpoints

Examples:

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)

Direct Known Subclasses

CsvExporter, JsonExporter

Constant Summary collapse

DATE_FORMAT =
'%Y-%m-%d %H:%M:%S'.freeze
DATA_TYPES =
[
  EMAIL_SEND_TYPE = 'emailSend'.freeze,
  EMAIL_OPEN_TYPE = 'emailOpen'.freeze,
  EMAIL_CLICK_TYPE = 'emailClick'.freeze,
  EMAIL_UNSUBSCRIBE_TYPE = 'emailUnSubscribe'.freeze,
  EMAIL_SUBSCRIBE_TYPE = 'emailSubscribe'.freeze,
  EMAIL_BOUNCE_TYPE = 'emailBounce'.freeze,
  EMAIL_COMPLAINT_TYPE = 'emailComplaint'.freeze,
  PUSH_SEND_TYPE = 'pushSend'.freeze,
  PUSH_BOUNCE_TYPE = 'pushBounce'.freeze,
  PUSH_OPEN_TYPE = 'pushOpen'.freeze,
  SMS_SEND_TYPE = 'smsSend'.freeze,
  SMS_BOUNCE_TYPE = 'smsBounce'.freeze,
  SMS_RECEIVED_TYPE = 'smsReceived'.freeze,
  IN_APP_OPEN_TYPE = 'inAppOpen'.freeze,
  IN_APP_CLICK_TYPE = 'inAppClick'.freeze,
  WEB_PUSH_SEND_TYPE = 'webPushSend'.freeze,
  HOSTED_UNSUBSCRIBE_CLICK_TYPE = 'hostedUnsubscribeClick'.freeze,
  PURCHASE_TYPE = 'purchase'.freeze,
  CUSTOM_EVENT_TYPE = 'customEvent'.freeze,
  USER_TYPE = 'user'.freeze
].freeze
RANGES =
[
  TODAY = 'Today'.freeze,
  YESTERDAY = 'Yesterday'.freeze,
  BEFORE_TODAY = 'BeforeToday'.freeze,
  ALL = 'All'.freeze
].freeze

Instance Attribute Summary collapse

Attributes inherited from ApiResource

#conf

Instance Method Summary collapse

Methods inherited from ApiResource

default_config, #default_config

Constructor Details

#initialize(data_type, only_fields = [], omit_fields = [], campaign_id = nil, conf = nil) ⇒ Iterable::Export

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

Parameters:

  • data_type (String)

    The type of data to export, one of [Iterable::Export::DATA_TYPES]

  • only_fields (Array[String]) (defaults to: [])

    Array of fields to only export

  • omit_fields (Array[String]) (defaults to: [])

    Array of fields to omit

  • data_fields (Hash)

    Additional device data fields

  • conf (Iterable::Config) (defaults to: nil)

    A config to optionally pass for requests



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

def initialize(data_type, only_fields = [], omit_fields = [], campaign_id = nil, conf = nil) # rubocop:disable Metrics/ParameterLists
  @data_type = data_type
  @only_fields = only_fields
  @omit_fields = omit_fields
  @campaign_id = campaign_id
  super conf
end

Instance Attribute Details

#campaign_idObject (readonly)

Returns the value of attribute campaign_id.



47
48
49
# File 'lib/iterable/export.rb', line 47

def campaign_id
  @campaign_id
end

#data_typeObject (readonly)

Returns the value of attribute data_type.



47
48
49
# File 'lib/iterable/export.rb', line 47

def data_type
  @data_type
end

#omit_fieldsObject (readonly)

Returns the value of attribute omit_fields.



47
48
49
# File 'lib/iterable/export.rb', line 47

def omit_fields
  @omit_fields
end

#only_fieldsObject (readonly)

Returns the value of attribute only_fields.



47
48
49
# File 'lib/iterable/export.rb', line 47

def only_fields
  @only_fields
end

Instance Method Details

#export(start_time, end_time) ⇒ Iterable::Response

Export data between a start and end time

Parameters:

  • start_time (Time)

    The start time of the data to export

  • end_time (Time)

    The end time of the data to export

Returns:



86
87
88
89
90
91
92
# 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) ⇒ Iterable::Response

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

Parameters:

Returns:



101
102
103
104
# 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

#formatException

The format of the exporter to be implemented by a subclass

Examples:

Formats are currently csv or json

Returns:

  • (Exception)

    Raises an exception



74
75
76
# File 'lib/iterable/export.rb', line 74

def format
  raise '#format must be implemented in child class'
end