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) ⇒ Export

rubocop:disable Metrics/ParameterLists



72
73
74
75
76
77
78
# File 'lib/iterable/export.rb', line 72

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.



49
50
51
# File 'lib/iterable/export.rb', line 49

def campaign_id
  @campaign_id
end

#data_typeObject (readonly)

Returns the value of attribute data_type.



49
50
51
# File 'lib/iterable/export.rb', line 49

def data_type
  @data_type
end

#omit_fieldsObject (readonly)

Returns the value of attribute omit_fields.



49
50
51
# File 'lib/iterable/export.rb', line 49

def omit_fields
  @omit_fields
end

#only_fieldsObject (readonly)

Returns the value of attribute only_fields.



49
50
51
# File 'lib/iterable/export.rb', line 49

def only_fields
  @only_fields
end

Instance Method Details

#export(start_time, end_time) ⇒ Object



105
106
107
108
109
110
111
# File 'lib/iterable/export.rb', line 105

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) ⇒ Object



125
126
127
128
# File 'lib/iterable/export.rb', line 125

def export_range(range = Iterable::Export::TODAY)
  params = { range: range }
  Iterable.request(conf, base_path, request_params(params)).get
end

#formatObject



87
88
89
# File 'lib/iterable/export.rb', line 87

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