iterable-api-client 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +733 -1
- data/lib/iterable.rb +61 -1
- data/lib/iterable/api_resource.rb +39 -0
- data/lib/iterable/campaigns.rb +68 -0
- data/lib/iterable/channels.rb +24 -0
- data/lib/iterable/commerce.rb +53 -0
- data/lib/iterable/config.rb +39 -0
- data/lib/iterable/csv_exporter.rb +19 -0
- data/lib/iterable/device.rb +74 -0
- data/lib/iterable/email.rb +28 -0
- data/lib/iterable/email_templates.rb +54 -0
- data/lib/iterable/events.rb +59 -0
- data/lib/iterable/experiments.rb +50 -0
- data/lib/iterable/export.rb +124 -0
- data/lib/iterable/json_exporter.rb +23 -0
- data/lib/iterable/lists.rb +89 -0
- data/lib/iterable/message_types.rb +31 -0
- data/lib/iterable/metadata.rb +24 -0
- data/lib/iterable/metadata_table.rb +93 -0
- data/lib/iterable/push_templates.rb +54 -0
- data/lib/iterable/request.rb +100 -0
- data/lib/iterable/response.rb +46 -0
- data/lib/iterable/templates.rb +37 -0
- data/lib/iterable/users.rb +190 -0
- data/lib/iterable/workflows.rb +30 -0
- metadata +39 -2
- metadata.gz.sig +0 -0
@@ -0,0 +1,59 @@
|
|
1
|
+
module Iterable
|
2
|
+
##
|
3
|
+
#
|
4
|
+
# Interact with /events API endpoints
|
5
|
+
#
|
6
|
+
# @example Creating events endpoint object
|
7
|
+
# # With default config
|
8
|
+
# campaigns = Iterable::Events.new
|
9
|
+
# campaigns.all
|
10
|
+
#
|
11
|
+
# # With custom config
|
12
|
+
# conf = Iterable::Config.new(token: 'new-token')
|
13
|
+
# campaigns = Iterable::Events.new(config)
|
14
|
+
class Events < ApiResource
|
15
|
+
##
|
16
|
+
#
|
17
|
+
# Get all events for a user by email
|
18
|
+
#
|
19
|
+
# @param email [String] Email of user to find events for
|
20
|
+
# @param limit [Integer] Limit of events to return, max 200 default 30
|
21
|
+
#
|
22
|
+
# @return [Iterable::Response] A response object
|
23
|
+
def for_email(email, limit = 30)
|
24
|
+
Iterable.request(conf, "/events/#{email}", limit: limit).get
|
25
|
+
end
|
26
|
+
|
27
|
+
##
|
28
|
+
#
|
29
|
+
# Track an event
|
30
|
+
#
|
31
|
+
# @param name [String] Required name of event
|
32
|
+
# @param email [String] Email of user to track event for
|
33
|
+
# @param attrs [Hash] Event values and fields to include
|
34
|
+
#
|
35
|
+
# @return [Iterable::Response] A response object
|
36
|
+
def track(name, email = nil, attrs = {})
|
37
|
+
attrs[:eventName] = name
|
38
|
+
attrs[:email] = email
|
39
|
+
Iterable.request(conf, '/events/track').post(attrs)
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
#
|
44
|
+
# Track an event
|
45
|
+
#
|
46
|
+
# @param campaign_id [String] Campaign ID of the push event to track
|
47
|
+
# @param message_id [String] Message ID of the push event to track
|
48
|
+
# @param email [String] Email of user to track push event for
|
49
|
+
# @param attrs [Hash] Event values and fields to include
|
50
|
+
#
|
51
|
+
# @return [Iterable::Response] A response object
|
52
|
+
def track_push_open(campaign_id, message_id, email, attrs = {})
|
53
|
+
attrs[:campaignId] = campaign_id
|
54
|
+
attrs[:messageId] = message_id
|
55
|
+
attrs[:email] = email
|
56
|
+
Iterable.request(conf, '/events/trackPushOpen').post(attrs)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Iterable
|
2
|
+
##
|
3
|
+
#
|
4
|
+
# Interact with /experiments API endpoints
|
5
|
+
#
|
6
|
+
# @example Creating experiments endpoint object
|
7
|
+
# # With default config
|
8
|
+
# templates = Iterable::Experiments.new [1, 2, 3]
|
9
|
+
# templates.get
|
10
|
+
#
|
11
|
+
# # With custom config
|
12
|
+
# conf = Iterable::Config.new(token: 'new-token')
|
13
|
+
# templates = Iterable::Experiments.new([1, 2, 3], config)
|
14
|
+
class Experiments < ApiResource
|
15
|
+
attr_reader :experiment_ids
|
16
|
+
##
|
17
|
+
#
|
18
|
+
# Initialize Experiments with an array of experiment ids
|
19
|
+
#
|
20
|
+
# @param experiment_ids [Array[Integer]] Array of experiment_id Integers
|
21
|
+
# @param conf [Iterable::Config] A config to optionally pass for requests
|
22
|
+
#
|
23
|
+
# @return [Iterable::Experiments]
|
24
|
+
def initialize(experiment_ids = [], conf = nil)
|
25
|
+
@experiment_ids = experiment_ids
|
26
|
+
super conf
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
#
|
31
|
+
# Get metrics for experiments
|
32
|
+
#
|
33
|
+
# @params campaign_ids [Array] Array of campaignIds to optionally query for
|
34
|
+
# @param start_time [Date|Time] Start of metrics to query for
|
35
|
+
# @param end_time [Date|Time] End of metrics to query for
|
36
|
+
#
|
37
|
+
# @return [Iterable::Response] A response object
|
38
|
+
def metrics(campaign_ids = [], start_time = nil, end_time = nil)
|
39
|
+
params = {
|
40
|
+
experimentId: @experiment_ids,
|
41
|
+
campaignId: campaign_ids
|
42
|
+
}
|
43
|
+
if start_time
|
44
|
+
params[:startTime] = start_time.to_date.strftime(Iterable::DATE_FORMAT)
|
45
|
+
params[:endTime] = end_time.to_date.strftime(Iterable::DATE_FORMAT)
|
46
|
+
end
|
47
|
+
Iterable.request(conf, '/experiments/metrics', params).get
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
module Iterable
|
2
|
+
##
|
3
|
+
#
|
4
|
+
# Interact with /export API endpoints
|
5
|
+
#
|
6
|
+
# @example Creating an export endpoint object
|
7
|
+
# # With default config
|
8
|
+
# export = Iterable::Export.new
|
9
|
+
# export = Iterable::Export.new Iterable::Export::EMAIL_SEND_TYPE
|
10
|
+
# export.all
|
11
|
+
#
|
12
|
+
# # With custom config
|
13
|
+
# conf = Iterable::Config.new(token: 'new-token')
|
14
|
+
# export = Iterable::Export.new(Iterable::Export::EMAIL_SEND_TYPE, nil, nil, nil, config)
|
15
|
+
class Export < ApiResource
|
16
|
+
DATE_FORMAT = '%Y-%m-%d %H:%M:%S'.freeze
|
17
|
+
DATA_TYPES = [
|
18
|
+
EMAIL_SEND_TYPE = 'emailSend'.freeze,
|
19
|
+
EMAIL_OPEN_TYPE = 'emailOpen'.freeze,
|
20
|
+
EMAIL_CLICK_TYPE = 'emailClick'.freeze,
|
21
|
+
EMAIL_UNSUBSCRIBE_TYPE = 'emailUnSubscribe'.freeze,
|
22
|
+
EMAIL_SUBSCRIBE_TYPE = 'emailSubscribe'.freeze,
|
23
|
+
EMAIL_BOUNCE_TYPE = 'emailBounce'.freeze,
|
24
|
+
EMAIL_COMPLAINT_TYPE = 'emailComplaint'.freeze,
|
25
|
+
PUSH_SEND_TYPE = 'pushSend'.freeze,
|
26
|
+
PUSH_BOUNCE_TYPE = 'pushBounce'.freeze,
|
27
|
+
PUSH_OPEN_TYPE = 'pushOpen'.freeze,
|
28
|
+
SMS_SEND_TYPE = 'smsSend'.freeze,
|
29
|
+
SMS_BOUNCE_TYPE = 'smsBounce'.freeze,
|
30
|
+
SMS_RECEIVED_TYPE = 'smsReceived'.freeze,
|
31
|
+
IN_APP_OPEN_TYPE = 'inAppOpen'.freeze,
|
32
|
+
IN_APP_CLICK_TYPE = 'inAppClick'.freeze,
|
33
|
+
WEB_PUSH_SEND_TYPE = 'webPushSend'.freeze,
|
34
|
+
HOSTED_UNSUBSCRIBE_CLICK_TYPE = 'hostedUnsubscribeClick'.freeze,
|
35
|
+
PURCHASE_TYPE = 'purchase'.freeze,
|
36
|
+
CUSTOM_EVENT_TYPE = 'customEvent'.freeze,
|
37
|
+
USER_TYPE = 'user'.freeze
|
38
|
+
].freeze
|
39
|
+
|
40
|
+
RANGES = [
|
41
|
+
TODAY = 'Today'.freeze,
|
42
|
+
YESTERDAY = 'Yesterday'.freeze,
|
43
|
+
BEFORE_TODAY = 'BeforeToday'.freeze,
|
44
|
+
ALL = 'All'.freeze
|
45
|
+
].freeze
|
46
|
+
|
47
|
+
attr_reader :data_type, :only_fields, :omit_fields, :campaign_id
|
48
|
+
|
49
|
+
##
|
50
|
+
#
|
51
|
+
# Initialize an [Iterable::Export] object to export data from Iterable
|
52
|
+
#
|
53
|
+
# @param data_type [String] The type of data to export, one of [Iterable::Export::DATA_TYPES]
|
54
|
+
# @param only_fields [Array[String]] Array of fields to only export
|
55
|
+
# @param omit_fields [Array[String]] Array of fields to omit
|
56
|
+
# @param data_fields [Hash] Additional device data fields
|
57
|
+
# @param conf [Iterable::Config] A config to optionally pass for requests
|
58
|
+
#
|
59
|
+
# @return [Iterable::Export]
|
60
|
+
def initialize(data_type, only_fields = [], omit_fields = [], campaign_id = nil, conf = nil)
|
61
|
+
@data_type = data_type
|
62
|
+
@only_fields = only_fields
|
63
|
+
@omit_fields = omit_fields
|
64
|
+
@campaign_id = campaign_id
|
65
|
+
super conf
|
66
|
+
end
|
67
|
+
|
68
|
+
##
|
69
|
+
# The format of the exporter to be implemented by a subclass
|
70
|
+
#
|
71
|
+
# @example Formats are currently csv or json
|
72
|
+
#
|
73
|
+
# @return [Exception] Raises an exception
|
74
|
+
def format
|
75
|
+
raise '#format must be implemented in child class'
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
#
|
80
|
+
# Export data between a start and end time
|
81
|
+
#
|
82
|
+
# @param start_time [Time] The start time of the data to export
|
83
|
+
# @param end_time [Time] The end time of the data to export
|
84
|
+
#
|
85
|
+
# @return [Iterable::Response] A response object
|
86
|
+
def export(start_time, end_time)
|
87
|
+
params = {
|
88
|
+
startDateTime: start_time.strftime(Iterable::Export::DATE_FORMAT),
|
89
|
+
endDateTime: end_time.strftime(Iterable::Export::DATE_FORMAT)
|
90
|
+
}
|
91
|
+
Iterable.request(conf, base_path, request_params(params)).get
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
#
|
96
|
+
# Export data given a valid range constant [Iterable::Export::RANGES]
|
97
|
+
#
|
98
|
+
# @param range [Iterable::Export::RANGES] A valid range to export data for
|
99
|
+
#
|
100
|
+
# @return [Iterable::Response] A response object
|
101
|
+
def export_range(range = Iterable::Export::TODAY)
|
102
|
+
params = { range: range }
|
103
|
+
Iterable.request(conf, base_path, request_params(params)).get
|
104
|
+
end
|
105
|
+
|
106
|
+
protected
|
107
|
+
|
108
|
+
def base_path
|
109
|
+
"/export/data.#{format}"
|
110
|
+
end
|
111
|
+
|
112
|
+
def request_params(params = {})
|
113
|
+
default_params.merge params
|
114
|
+
end
|
115
|
+
|
116
|
+
def default_params
|
117
|
+
params = { dataTypeName: @data_type }
|
118
|
+
params[:onlyFields] = @only_fields if @only_fields && @only_fields.length.positive?
|
119
|
+
params[:omitFields] = @omit_fields.join(',') if @omit_fields && @omit_fields.length.positive?
|
120
|
+
params[:campaignId] = @campaign_id if @campaign_id
|
121
|
+
params
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Iterable
|
2
|
+
##
|
3
|
+
#
|
4
|
+
# Subclass of [Iterable::Export] for JSON exporting of data
|
5
|
+
#
|
6
|
+
# @example Creating a JSON Exporter
|
7
|
+
# # With default config
|
8
|
+
# exporter = Iterable::JsonExporter.new Iterable::Export::EMAIL_SEND_TYPE
|
9
|
+
# exporter.export
|
10
|
+
#
|
11
|
+
# # With custom config
|
12
|
+
# conf = Iterable::Config.new(token: 'new-token')
|
13
|
+
# exporter = Iterable::JsonExporter.new(Iterable::Export::EMAIL_SEND_TYPE, nil, nil, nil, config)
|
14
|
+
class JsonExporter < Export
|
15
|
+
##
|
16
|
+
# Format to use for exporting
|
17
|
+
#
|
18
|
+
# @return [String] Format of export
|
19
|
+
def format
|
20
|
+
'json'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Iterable
|
2
|
+
##
|
3
|
+
#
|
4
|
+
# Interact with /lists API endpoints
|
5
|
+
#
|
6
|
+
# @example Creating list endpoint object
|
7
|
+
# # With default config
|
8
|
+
# lists = Iterable::Lists.new
|
9
|
+
# lists.all
|
10
|
+
#
|
11
|
+
# # With custom config
|
12
|
+
# conf = Iterable::Config.new(token: 'new-token')
|
13
|
+
# lists = Iterable::Lists.new(config)
|
14
|
+
class Lists < ApiResource
|
15
|
+
##
|
16
|
+
#
|
17
|
+
# Get all lists
|
18
|
+
#
|
19
|
+
# @return [Iterable::Response] A response object
|
20
|
+
def all
|
21
|
+
Iterable.request(conf, '/lists').get
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
#
|
26
|
+
# Create a new list with a name
|
27
|
+
#
|
28
|
+
# @param name [String] The name of the list to create
|
29
|
+
#
|
30
|
+
# @return [Iterable::Response] A response object
|
31
|
+
def create(name)
|
32
|
+
Iterable.request(conf, '/lists').post(name: name)
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
#
|
37
|
+
# Delete an existing list given a list id
|
38
|
+
#
|
39
|
+
# @param name [String|Integer] The id of the list to delete
|
40
|
+
#
|
41
|
+
# @return [Iterable::Response] A response object
|
42
|
+
def delete(list_id)
|
43
|
+
Iterable.request(conf, "/lists/#{list_id}").delete
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
#
|
48
|
+
# Get users for a list
|
49
|
+
#
|
50
|
+
# @param list_id [String|Integer] The id of the list
|
51
|
+
#
|
52
|
+
# @return [Iterable::Response] A response object
|
53
|
+
def users(list_id)
|
54
|
+
Iterable.request(conf, '/lists/getUsers', listId: list_id).get
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
#
|
59
|
+
# Subscribe users to a list
|
60
|
+
#
|
61
|
+
# @param list_id [String|Integer] The id of the list
|
62
|
+
# @param subscribes [Array[Hash]] An array of hashes of user emails and data fields
|
63
|
+
#
|
64
|
+
# @return [Iterable::Response] A response object
|
65
|
+
def subscribe(list_id, subscribers = [])
|
66
|
+
attrs = {
|
67
|
+
listId: list_id,
|
68
|
+
subscribers: subscribers
|
69
|
+
}
|
70
|
+
Iterable.request(conf, '/lists/subscribe').post(attrs)
|
71
|
+
end
|
72
|
+
|
73
|
+
##
|
74
|
+
#
|
75
|
+
# Subscribe users to a list
|
76
|
+
#
|
77
|
+
# @param list_id [String|Integer] The id of the list
|
78
|
+
# @param subscribes [Array[Hash]] An array of hashes with an email
|
79
|
+
#
|
80
|
+
# @return [Iterable::Response] A response object
|
81
|
+
def unsubscribe(list_id, subscribers = [])
|
82
|
+
attrs = {
|
83
|
+
listId: list_id,
|
84
|
+
subscribers: subscribers
|
85
|
+
}
|
86
|
+
Iterable.request(conf, '/lists/unsubscribe').post(attrs)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Iterable
|
2
|
+
##
|
3
|
+
#
|
4
|
+
# Interact with /messageTypes API endpoints
|
5
|
+
#
|
6
|
+
# @example Creating message_types endpoint object
|
7
|
+
# # With default config
|
8
|
+
# message_types = Iterable::MessageTypes.new
|
9
|
+
# message_types.all
|
10
|
+
#
|
11
|
+
# # With custom config
|
12
|
+
# conf = Iterable::Config.new(token: 'new-token')
|
13
|
+
# message_types = Iterable::MessageTypes.new(config)
|
14
|
+
class MessageTypes < ApiResource
|
15
|
+
# Message mediums
|
16
|
+
MEDIUMS = [
|
17
|
+
EMAIL_MEDIUM = 'Email'.freeze,
|
18
|
+
PUSH_MEDIUM = 'Push'.freeze,
|
19
|
+
IN_APP_MEDIUM = 'InApp'.freeze,
|
20
|
+
SMS_MEDIUM = 'SMS'.freeze
|
21
|
+
].freeze
|
22
|
+
##
|
23
|
+
#
|
24
|
+
# Get all message_types
|
25
|
+
#
|
26
|
+
# @return [Iterable::Response] A response object
|
27
|
+
def all
|
28
|
+
Iterable.request(conf, '/messageTypes').get
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Iterable
|
2
|
+
##
|
3
|
+
#
|
4
|
+
# Interact with /metadata API endpoints
|
5
|
+
#
|
6
|
+
# @example Creating metadata endpoint object
|
7
|
+
# # With default config
|
8
|
+
# templates = Iterable::Metadata.new
|
9
|
+
# templates.get
|
10
|
+
#
|
11
|
+
# # With custom config
|
12
|
+
# conf = Iterable::Config.new(token: 'new-token')
|
13
|
+
# templates = Iterable::Metadata.new(config)
|
14
|
+
class Metadata < ApiResource
|
15
|
+
##
|
16
|
+
#
|
17
|
+
# Get metadata
|
18
|
+
#
|
19
|
+
# @return [Iterable::Response] A response object
|
20
|
+
def get
|
21
|
+
Iterable.request(conf, '/metadata').get
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
module Iterable
|
2
|
+
##
|
3
|
+
#
|
4
|
+
# Interact with /metadata/{table} API endpoints
|
5
|
+
#
|
6
|
+
# @example Creating metadata table endpoint object
|
7
|
+
# # With default config
|
8
|
+
# templates = Iterable::MetadataTable.new "table-name"
|
9
|
+
# templates.get
|
10
|
+
#
|
11
|
+
# # With custom config
|
12
|
+
# conf = Iterable::Config.new(token: 'new-token')
|
13
|
+
# templates = Iterable::MetadataTable.new("table-name", config)
|
14
|
+
class MetadataTable < ApiResource
|
15
|
+
attr_reader :name
|
16
|
+
##
|
17
|
+
#
|
18
|
+
# Initialize a MetadataTable with a table name
|
19
|
+
#
|
20
|
+
# @param name [String] The name of the table to interact with
|
21
|
+
# @param conf [Iterable::Config] A config to optionally pass for requests
|
22
|
+
#
|
23
|
+
# @return [Iterable::MetadataTable]
|
24
|
+
def initialize(name, conf = nil)
|
25
|
+
@name = name
|
26
|
+
super conf
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
#
|
31
|
+
# Get metadata table keys
|
32
|
+
#
|
33
|
+
# @params next_marker [String] next result set id if more hits exist
|
34
|
+
#
|
35
|
+
# @return [Iterable::Response] A response object
|
36
|
+
def list_keys(next_marker = nil)
|
37
|
+
params = {}
|
38
|
+
params['nextMarker'] = next_marker if next_marker
|
39
|
+
Iterable.request(conf, base_path, params).get
|
40
|
+
end
|
41
|
+
|
42
|
+
##
|
43
|
+
#
|
44
|
+
# Delete metadata table
|
45
|
+
#
|
46
|
+
# @return [Iterable::Response] A response object
|
47
|
+
def delete
|
48
|
+
Iterable.request(conf, base_path).delete
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
#
|
53
|
+
# Add metadata for table
|
54
|
+
#
|
55
|
+
# @param key [String] Key of metadata to add
|
56
|
+
# @param value [Hash] Value of metadata key as a hash of key/value data
|
57
|
+
#
|
58
|
+
# @return [Iterable::Response] A response object
|
59
|
+
def add(key, value = {})
|
60
|
+
Iterable.request(conf, base_path(key)).put(value: value)
|
61
|
+
end
|
62
|
+
|
63
|
+
##
|
64
|
+
#
|
65
|
+
# Get metadata key for table
|
66
|
+
#
|
67
|
+
# @param key [String] Key of metadata to get
|
68
|
+
#
|
69
|
+
# @return [Iterable::Response] A response object
|
70
|
+
def get(key)
|
71
|
+
Iterable.request(conf, base_path(key)).get
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
#
|
76
|
+
# Remove metadata key for table
|
77
|
+
#
|
78
|
+
# @param key [String] Key of metadata to delete
|
79
|
+
#
|
80
|
+
# @return [Iterable::Response] A response object
|
81
|
+
def remove(key)
|
82
|
+
Iterable.request(conf, base_path(key)).delete
|
83
|
+
end
|
84
|
+
|
85
|
+
private
|
86
|
+
|
87
|
+
def base_path(key = nil)
|
88
|
+
path = "/metadata/#{@name}"
|
89
|
+
path += "/#{key}" if key
|
90
|
+
path
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|