urbanairship 5.2.0 → 9.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/CONTRIBUTING.md +1 -1
- data/.github/ISSUE_TEMPLATE.md +2 -2
- data/.github/PULL_REQUEST_TEMPLATE.md +9 -4
- data/.github/SUPPORT.md +3 -3
- data/.github/workflows/ci.yaml +26 -0
- data/.github/workflows/release.yaml +30 -0
- data/.gitignore +2 -0
- data/CHANGELOG +198 -51
- data/LICENSE +1 -1
- data/README.rst +159 -57
- data/docs/ab_tests.rst +162 -0
- data/docs/attributes.rst +73 -0
- data/docs/automations.rst +212 -0
- data/docs/channel_uninstall.rst +1 -1
- data/docs/conf.py +11 -6
- data/docs/create_and_send.rst +551 -0
- data/docs/devices.rst +1 -1
- data/docs/examples.rst +10 -10
- data/docs/index.rst +23 -19
- data/docs/named_user.rst +27 -5
- data/docs/push.rst +37 -18
- data/docs/reports.rst +9 -9
- data/docs/segment.rst +5 -5
- data/docs/sms.rst +19 -0
- data/docs/static_lists.rst +4 -4
- data/docs/tag_lists.rst +76 -0
- data/docs/tags.rst +1 -1
- data/example/pusher.rb +3 -7
- data/lib/urbanairship/ab_tests/ab_test.rb +88 -0
- data/lib/urbanairship/ab_tests/experiment.rb +45 -0
- data/lib/urbanairship/ab_tests/variant.rb +34 -0
- data/lib/urbanairship/automations/automation.rb +105 -0
- data/lib/urbanairship/automations/pipeline.rb +52 -0
- data/lib/urbanairship/client.rb +57 -14
- data/lib/urbanairship/common.rb +110 -41
- data/lib/urbanairship/configuration.rb +3 -1
- data/lib/urbanairship/custom_events/custom_event.rb +60 -0
- data/lib/urbanairship/custom_events/payload.rb +89 -0
- data/lib/urbanairship/devices/attribute.rb +54 -0
- data/lib/urbanairship/devices/attributes.rb +53 -0
- data/lib/urbanairship/devices/channel_tags.rb +2 -2
- data/lib/urbanairship/devices/channel_uninstall.rb +10 -10
- data/lib/urbanairship/devices/create_and_send.rb +96 -0
- data/lib/urbanairship/devices/devicelist.rb +28 -7
- data/lib/urbanairship/devices/email.rb +33 -43
- data/lib/urbanairship/devices/email_notification.rb +92 -0
- data/lib/urbanairship/devices/mms_notification.rb +107 -0
- data/lib/urbanairship/devices/named_user.rb +22 -12
- data/lib/urbanairship/devices/open_channel.rb +105 -61
- data/lib/urbanairship/devices/segment.rb +10 -15
- data/lib/urbanairship/devices/sms.rb +51 -23
- data/lib/urbanairship/devices/sms_notification.rb +54 -0
- data/lib/urbanairship/devices/static_lists.rb +18 -19
- data/lib/urbanairship/devices/tag_lists.rb +82 -0
- data/lib/urbanairship/oauth.rb +129 -0
- data/lib/urbanairship/push/audience.rb +0 -61
- data/lib/urbanairship/push/payload.rb +78 -8
- data/lib/urbanairship/push/push.rb +23 -13
- data/lib/urbanairship/push/schedule.rb +9 -0
- data/lib/urbanairship/reports/response_statistics.rb +42 -31
- data/lib/urbanairship/version.rb +1 -1
- data/lib/urbanairship.rb +20 -1
- data/urbanairship.gemspec +8 -6
- metadata +74 -15
- data/.travis.yml +0 -4
- data/docs/location.rst +0 -127
- data/lib/urbanairship/push/location.rb +0 -103
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'urbanairship'
|
2
|
+
require 'urbanairship/common'
|
3
|
+
|
4
|
+
module Urbanairship
|
5
|
+
module CustomEvents
|
6
|
+
module Payload
|
7
|
+
include Urbanairship::Common
|
8
|
+
|
9
|
+
def custom_events(
|
10
|
+
body: required('body'),
|
11
|
+
occurred: required('occurred'),
|
12
|
+
user: required('user')
|
13
|
+
)
|
14
|
+
compact_helper({
|
15
|
+
body: body,
|
16
|
+
occurred: format_timestamp(occurred),
|
17
|
+
user: user
|
18
|
+
})
|
19
|
+
end
|
20
|
+
|
21
|
+
# Body specific portion of CustomEvent Object
|
22
|
+
def custom_events_body(
|
23
|
+
interaction_id: nil, interaction_type: nil, name: required('name'),
|
24
|
+
properties: nil, session_id: nil, transaction: nil, value: nil
|
25
|
+
)
|
26
|
+
|
27
|
+
validates_name_format(name)
|
28
|
+
validates_value_format(value)
|
29
|
+
|
30
|
+
compact_helper({
|
31
|
+
interaction_id: interaction_id,
|
32
|
+
interaction_type: interaction_type,
|
33
|
+
name: name,
|
34
|
+
properties: properties,
|
35
|
+
session_id: session_id,
|
36
|
+
transaction: transaction,
|
37
|
+
value: value
|
38
|
+
})
|
39
|
+
end
|
40
|
+
|
41
|
+
# User specific portion of CustomEvent Object
|
42
|
+
def custom_events_user(
|
43
|
+
amazon_channel: nil, android_channel: nil, channel: nil,
|
44
|
+
ios_channel: nil, named_user_id: nil, web_channel: nil
|
45
|
+
)
|
46
|
+
res = compact_helper({
|
47
|
+
amazon_channel: amazon_channel,
|
48
|
+
android_channel: android_channel,
|
49
|
+
channel: channel,
|
50
|
+
ios_channel: ios_channel,
|
51
|
+
named_user_id: named_user_id,
|
52
|
+
web_channel: web_channel,
|
53
|
+
})
|
54
|
+
|
55
|
+
fail ArgumentError, 'at least one user identifier must be defined' if res.empty?
|
56
|
+
|
57
|
+
res
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
# Formatters
|
62
|
+
# ------------------------------------------------------------------------
|
63
|
+
|
64
|
+
def format_timestamp(timestamp)
|
65
|
+
return timestamp if timestamp.is_a?(String)
|
66
|
+
|
67
|
+
timestamp.strftime('%Y-%m-%dT%H:%M:%S')
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
# Validators
|
72
|
+
# ------------------------------------------------------------------------
|
73
|
+
|
74
|
+
NAME_REGEX = /^[a-z0-9_\-]+$/
|
75
|
+
def validates_name_format(name)
|
76
|
+
return if name =~ NAME_REGEX
|
77
|
+
|
78
|
+
fail ArgumentError, 'invalid "name": it must follows this pattern /^[a-z0-9_\-]+$/'
|
79
|
+
end
|
80
|
+
|
81
|
+
def validates_value_format(value)
|
82
|
+
return if value.nil?
|
83
|
+
return if value.is_a?(Numeric)
|
84
|
+
|
85
|
+
fail ArgumentError, 'invalid "value": must be a number'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'urbanairship'
|
2
|
+
|
3
|
+
module Urbanairship
|
4
|
+
module Devices
|
5
|
+
class Attribute
|
6
|
+
include Urbanairship::Common
|
7
|
+
include Urbanairship::Loggable
|
8
|
+
attr_accessor :attribute,
|
9
|
+
:operator,
|
10
|
+
:precision,
|
11
|
+
:value
|
12
|
+
|
13
|
+
def initialize(client: required('client'))
|
14
|
+
@client = client
|
15
|
+
end
|
16
|
+
|
17
|
+
def payload
|
18
|
+
if precision
|
19
|
+
date_attribute
|
20
|
+
elsif value.is_a? String
|
21
|
+
text_attribute
|
22
|
+
elsif value.is_a? Integer
|
23
|
+
number_attribute
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def number_attribute
|
28
|
+
{
|
29
|
+
'attribute': attribute,
|
30
|
+
'operator': operator,
|
31
|
+
'value': value
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def text_attribute
|
36
|
+
{
|
37
|
+
'attribute': attribute,
|
38
|
+
'operator': operator,
|
39
|
+
'value': value
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def date_attribute
|
44
|
+
{
|
45
|
+
'attribute': attribute,
|
46
|
+
'operator': operator,
|
47
|
+
'precision': precision,
|
48
|
+
'value': value
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
module Urbanairship
|
3
|
+
module Devices
|
4
|
+
class Attributes
|
5
|
+
|
6
|
+
SET = 'set'
|
7
|
+
REMOVE = 'remove'
|
8
|
+
|
9
|
+
def initialize(attributes)
|
10
|
+
@attributes = attributes
|
11
|
+
end
|
12
|
+
|
13
|
+
def payload
|
14
|
+
@payload ||= { attributes: attributes_list }
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def attributes_list
|
20
|
+
@attributes.map{ |attribute| attribute_payload(attribute) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def attribute_payload(attribute)
|
24
|
+
if REMOVE == attribute[:action]
|
25
|
+
remove_payload(attribute)
|
26
|
+
else
|
27
|
+
set_payload(attribute)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def set_payload(attribute)
|
32
|
+
{
|
33
|
+
action: SET,
|
34
|
+
key: attribute[:key],
|
35
|
+
value: attribute[:value],
|
36
|
+
timestamp: (attribute[:timestamp] || timestamp).iso8601,
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
def remove_payload(attribute)
|
41
|
+
{
|
42
|
+
action: REMOVE,
|
43
|
+
key: attribute[:key],
|
44
|
+
timestamp: (attribute[:timestamp] || timestamp).iso8601,
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def timestamp
|
49
|
+
@timestamp ||= Time.now.utc
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -15,7 +15,7 @@ module Urbanairship
|
|
15
15
|
@add_group = {}
|
16
16
|
@remove_group = {}
|
17
17
|
@set_group = {}
|
18
|
-
@
|
18
|
+
@path = channel_path('tags/')
|
19
19
|
end
|
20
20
|
|
21
21
|
def set_audience(ios: nil, android: nil, amazon: nil)
|
@@ -62,7 +62,7 @@ module Urbanairship
|
|
62
62
|
response = @client.send_request(
|
63
63
|
method: 'POST',
|
64
64
|
body: JSON.dump(payload),
|
65
|
-
|
65
|
+
path: @path,
|
66
66
|
content_type: 'application/json'
|
67
67
|
)
|
68
68
|
logger.info("Set tags for audience: #{@audience}")
|
@@ -23,7 +23,7 @@ module Urbanairship
|
|
23
23
|
response = @client.send_request(
|
24
24
|
method: 'POST',
|
25
25
|
body: JSON.dump(channels),
|
26
|
-
|
26
|
+
path: channel_path('uninstall/'),
|
27
27
|
content_type: 'application/json'
|
28
28
|
)
|
29
29
|
|
@@ -31,33 +31,33 @@ module Urbanairship
|
|
31
31
|
response
|
32
32
|
end
|
33
33
|
end
|
34
|
-
|
35
|
-
|
34
|
+
|
35
|
+
|
36
36
|
class OpenChannelUninstall
|
37
37
|
include Urbanairship::Common
|
38
38
|
include Urbanairship::Loggable
|
39
39
|
attr_reader :client
|
40
|
-
|
40
|
+
|
41
41
|
def initialize(client: required('client'))
|
42
42
|
@client = client
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
def uninstall(address: required('address'),
|
46
46
|
open_platform: required('open_platform'))
|
47
|
-
|
47
|
+
|
48
48
|
body = {
|
49
49
|
address: address,
|
50
50
|
open_platform_name: open_platform
|
51
51
|
}
|
52
|
-
|
52
|
+
|
53
53
|
response = @client.send_request(
|
54
54
|
method: 'POST',
|
55
55
|
body: JSON.dump(body),
|
56
|
-
|
56
|
+
path: open_channel_path('uninstall/'),
|
57
57
|
content_type: 'application/json'
|
58
58
|
)
|
59
|
-
|
60
|
-
logger.info { "Successfully
|
59
|
+
|
60
|
+
logger.info { "Successfully uninstalled open channel with address: #{address}"}
|
61
61
|
response
|
62
62
|
end
|
63
63
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'urbanairship'
|
2
|
+
require 'urbanairship/devices/email_notification'
|
3
|
+
|
4
|
+
module Urbanairship
|
5
|
+
module Devices
|
6
|
+
class CreateAndSend
|
7
|
+
include Urbanairship::Common
|
8
|
+
include Urbanairship::Loggable
|
9
|
+
attr_accessor :addresses,
|
10
|
+
:device_types,
|
11
|
+
:notification,
|
12
|
+
:campaigns,
|
13
|
+
:name,
|
14
|
+
:scheduled_time
|
15
|
+
|
16
|
+
def initialize(client: required('client'))
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def validate_address
|
21
|
+
@addresses.each do |address|
|
22
|
+
unless address.include?(:ua_address) or address.include?(:ua_msisdn && :ua_opted_in && :ua_sender)
|
23
|
+
fail ArgumentError, 'Missing a component in address portion of the object'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def payload
|
29
|
+
fail ArgumentError, 'addresses must be set for defining payload' if @addresses.nil?
|
30
|
+
fail ArgumentError, 'device type array must be set for defining payload' if @device_types.nil?
|
31
|
+
fail ArgumentError, 'notification object must be set for defining payload' if @notification.nil?
|
32
|
+
|
33
|
+
validate_address
|
34
|
+
|
35
|
+
full_payload = {
|
36
|
+
'audience': {
|
37
|
+
'create_and_send': addresses
|
38
|
+
},
|
39
|
+
'device_types': device_types,
|
40
|
+
'notification': notification,
|
41
|
+
}
|
42
|
+
|
43
|
+
if campaigns
|
44
|
+
campaign_object = {'categories': campaigns}
|
45
|
+
full_payload[:campaigns] = campaign_object
|
46
|
+
end
|
47
|
+
|
48
|
+
full_payload
|
49
|
+
end
|
50
|
+
|
51
|
+
def create_and_send
|
52
|
+
response = @client.send_request(
|
53
|
+
method: 'POST',
|
54
|
+
body: JSON.dump(payload),
|
55
|
+
path: create_and_send_path,
|
56
|
+
content_type: 'application/json'
|
57
|
+
)
|
58
|
+
logger.info("Running create and send for addresses #{@addresses}")
|
59
|
+
response
|
60
|
+
end
|
61
|
+
|
62
|
+
def validate
|
63
|
+
response = @client.send_request(
|
64
|
+
method: 'POST',
|
65
|
+
body: JSON.dump(payload),
|
66
|
+
path: create_and_send_path('validate'),
|
67
|
+
content_type: 'application/json'
|
68
|
+
)
|
69
|
+
logger.info("Validating payload for create and send")
|
70
|
+
response
|
71
|
+
end
|
72
|
+
|
73
|
+
def schedule
|
74
|
+
fail ArgumentError, 'scheduled time must be set to run an operation' if @scheduled_time.nil?
|
75
|
+
|
76
|
+
scheduled_payload = {
|
77
|
+
"schedule": {
|
78
|
+
"scheduled_time": scheduled_time
|
79
|
+
},
|
80
|
+
"name": name,
|
81
|
+
"push": payload
|
82
|
+
}
|
83
|
+
|
84
|
+
response = @client.send_request(
|
85
|
+
method: 'POST',
|
86
|
+
body: JSON.dump(scheduled_payload),
|
87
|
+
path: schedules_path('create-and-send'),
|
88
|
+
content_type: 'application/json'
|
89
|
+
)
|
90
|
+
logger.info("Scheduling create and send operation with name #{@name}")
|
91
|
+
response
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -7,6 +7,8 @@ module Urbanairship
|
|
7
7
|
include Urbanairship::Common
|
8
8
|
include Urbanairship::Loggable
|
9
9
|
attr_writer :client
|
10
|
+
attr_accessor :audience,
|
11
|
+
:attributes
|
10
12
|
|
11
13
|
def initialize(client: required('client'))
|
12
14
|
@client = client
|
@@ -15,17 +17,36 @@ module Urbanairship
|
|
15
17
|
def lookup(uuid: required('uuid'))
|
16
18
|
response = @client.send_request(
|
17
19
|
method: 'GET',
|
18
|
-
|
20
|
+
path: channel_path(uuid)
|
19
21
|
)
|
20
22
|
logger.info("Retrieved channel information for #{uuid}")
|
21
23
|
response['body']['channel']
|
22
24
|
end
|
25
|
+
|
26
|
+
def payload
|
27
|
+
{
|
28
|
+
'audience': audience,
|
29
|
+
'attributes': [
|
30
|
+
attributes
|
31
|
+
]
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
35
|
+
def set_attributes
|
36
|
+
response = @client.send_request(
|
37
|
+
method: 'POST',
|
38
|
+
body: JSON.dump(payload),
|
39
|
+
path: channel_path('attributes'),
|
40
|
+
content_type: 'application/json'
|
41
|
+
)
|
42
|
+
response
|
43
|
+
end
|
23
44
|
end
|
24
45
|
|
25
46
|
class ChannelList < Urbanairship::Common::PageIterator
|
26
47
|
def initialize(client: required('client'))
|
27
48
|
super(client: client)
|
28
|
-
@
|
49
|
+
@next_page_path = channel_path
|
29
50
|
@data_attribute = 'channels'
|
30
51
|
end
|
31
52
|
end
|
@@ -43,7 +64,7 @@ module Urbanairship
|
|
43
64
|
|
44
65
|
resp = @client.send_request(
|
45
66
|
method: 'GET',
|
46
|
-
|
67
|
+
path: device_token_path(token)
|
47
68
|
)
|
48
69
|
logger.info("Looking up info on device token #{token}")
|
49
70
|
resp
|
@@ -56,7 +77,7 @@ module Urbanairship
|
|
56
77
|
|
57
78
|
def initialize(client: required('client'))
|
58
79
|
super(client: client)
|
59
|
-
@
|
80
|
+
@next_page_path = device_token_path
|
60
81
|
@data_attribute = 'device_tokens'
|
61
82
|
end
|
62
83
|
end
|
@@ -74,7 +95,7 @@ module Urbanairship
|
|
74
95
|
|
75
96
|
resp = @client.send_request(
|
76
97
|
method: 'GET',
|
77
|
-
|
98
|
+
path: apid_path(apid)
|
78
99
|
)
|
79
100
|
logger.info("Retrieved info on apid #{apid}")
|
80
101
|
resp
|
@@ -84,9 +105,9 @@ module Urbanairship
|
|
84
105
|
class APIDList < Urbanairship::Common::PageIterator
|
85
106
|
def initialize(client: required('client'))
|
86
107
|
super(client: client)
|
87
|
-
@
|
108
|
+
@next_page_path = apid_path
|
88
109
|
@data_attribute = 'apids'
|
89
110
|
end
|
90
111
|
end
|
91
112
|
end
|
92
|
-
end
|
113
|
+
end
|
@@ -19,16 +19,6 @@ module Urbanairship
|
|
19
19
|
|
20
20
|
def initialize(client: required('client'))
|
21
21
|
@client = client
|
22
|
-
@address = nil
|
23
|
-
@commercial_opted_in = nil
|
24
|
-
@commercial_opted_out = nil
|
25
|
-
@locale_country = nil
|
26
|
-
@locale_language = nil
|
27
|
-
@timezone = nil
|
28
|
-
@transactional_opted_in = nil
|
29
|
-
@transactional_opted_out = nil
|
30
|
-
@type = nil
|
31
|
-
@channel_id = nil
|
32
22
|
end
|
33
23
|
|
34
24
|
def register
|
@@ -36,25 +26,25 @@ module Urbanairship
|
|
36
26
|
|
37
27
|
payload = {
|
38
28
|
'channel': {
|
39
|
-
'address':
|
40
|
-
'commercial_opted_in':
|
41
|
-
'commercial_opted_out':
|
42
|
-
'locale_country':
|
43
|
-
'locale_language':
|
44
|
-
'timezone':
|
45
|
-
'transactional_opted_in':
|
46
|
-
'transactional_opted_out':
|
47
|
-
'type':
|
29
|
+
'address': address,
|
30
|
+
'commercial_opted_in': commercial_opted_in,
|
31
|
+
'commercial_opted_out': commercial_opted_out,
|
32
|
+
'locale_country': locale_country,
|
33
|
+
'locale_language': locale_language,
|
34
|
+
'timezone': timezone,
|
35
|
+
'transactional_opted_in': transactional_opted_in,
|
36
|
+
'transactional_opted_out': transactional_opted_out,
|
37
|
+
'type': type
|
48
38
|
}
|
49
39
|
}
|
50
40
|
|
51
41
|
response = @client.send_request(
|
52
42
|
method: 'POST',
|
53
43
|
body: JSON.dump(payload),
|
54
|
-
|
44
|
+
path: channel_path('email'),
|
55
45
|
content_type: 'application/json'
|
56
46
|
)
|
57
|
-
logger.info("Registering email channel with address #{
|
47
|
+
logger.info("Registering email channel with address #{address}")
|
58
48
|
response
|
59
49
|
end
|
60
50
|
|
@@ -62,16 +52,16 @@ module Urbanairship
|
|
62
52
|
fail ArgumentError, 'address must be set to register email channel' if @address.nil?
|
63
53
|
|
64
54
|
payload = {
|
65
|
-
'email_address':
|
55
|
+
'email_address': address
|
66
56
|
}
|
67
57
|
|
68
58
|
response = @client.send_request(
|
69
59
|
method: 'POST',
|
70
60
|
body: JSON.dump(payload),
|
71
|
-
|
61
|
+
path: channel_path('email/uninstall'),
|
72
62
|
content_type: 'application/json'
|
73
63
|
)
|
74
|
-
logger.info("Uninstalling email channel with address #{
|
64
|
+
logger.info("Uninstalling email channel with address #{address}")
|
75
65
|
response
|
76
66
|
end
|
77
67
|
|
@@ -80,32 +70,32 @@ module Urbanairship
|
|
80
70
|
|
81
71
|
response = @client.send_request(
|
82
72
|
method: 'GET',
|
83
|
-
|
73
|
+
path: channel_path('email/' + address)
|
84
74
|
)
|
85
|
-
logger.info("Looking up email channel with address #{
|
75
|
+
logger.info("Looking up email channel with address #{address}")
|
86
76
|
response
|
87
77
|
end
|
88
78
|
|
89
79
|
def update
|
90
|
-
fail ArgumentError, 'address must be set to update email channel' if
|
91
|
-
|
92
|
-
channel_data = {
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
payload = {channel: channel_data}
|
80
|
+
fail ArgumentError, 'address must be set to update email channel' if channel_id.nil?
|
81
|
+
|
82
|
+
channel_data = {
|
83
|
+
'address': address,
|
84
|
+
'commercial_opted_in': commercial_opted_in,
|
85
|
+
'commercial_opted_out': commercial_opted_out,
|
86
|
+
'localte_country': locale_country,
|
87
|
+
'locale_language': locale_language,
|
88
|
+
'timezone': timezone,
|
89
|
+
'transactional_opted_in': transactional_opted_in,
|
90
|
+
'transactional_opted_out': transactional_opted_out,
|
91
|
+
'type': type
|
92
|
+
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
93
|
+
|
94
|
+
payload = {'channel': channel_data}
|
105
95
|
|
106
96
|
response = @client.send_request(
|
107
97
|
method: 'PUT',
|
108
|
-
|
98
|
+
path: channel_path('email/' + channel_id),
|
109
99
|
body: JSON.dump(payload),
|
110
100
|
content_type: 'application/json'
|
111
101
|
)
|
@@ -119,7 +109,7 @@ module Urbanairship
|
|
119
109
|
|
120
110
|
def initialize(client: required('client'))
|
121
111
|
super(client: client)
|
122
|
-
@
|
112
|
+
@path = channel_path('email/tags')
|
123
113
|
end
|
124
114
|
|
125
115
|
def set_audience(email_address: required('email_address'))
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'urbanairship'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Urbanairship
|
5
|
+
module Devices
|
6
|
+
class EmailNotification
|
7
|
+
include Urbanairship::Common
|
8
|
+
include Urbanairship::Loggable
|
9
|
+
attr_accessor :bcc,
|
10
|
+
:bypass_opt_in_level,
|
11
|
+
:html_body,
|
12
|
+
:message_type,
|
13
|
+
:plaintext_body,
|
14
|
+
:reply_to,
|
15
|
+
:sender_address,
|
16
|
+
:sender_name,
|
17
|
+
:subject,
|
18
|
+
:template_id,
|
19
|
+
:variable_details,
|
20
|
+
:click_tracking,
|
21
|
+
:open_tracking
|
22
|
+
|
23
|
+
def initialize(client: required('client'))
|
24
|
+
@client = client
|
25
|
+
end
|
26
|
+
|
27
|
+
def email_override
|
28
|
+
fail ArgumentError, 'message_type is needed for email override' if @message_type.nil?
|
29
|
+
fail ArgumentError, 'plaintext_body is needed for email override' if @plaintext_body.nil?
|
30
|
+
fail ArgumentError, 'reply_to is needed for email override' if @reply_to.nil?
|
31
|
+
fail ArgumentError, 'sender_address is needed for email override' if @sender_address.nil?
|
32
|
+
fail ArgumentError, 'sender_name is needed for email override' if @sender_name.nil?
|
33
|
+
fail ArgumentError, 'subject is needed for email override' if @subject.nil?
|
34
|
+
|
35
|
+
override = {
|
36
|
+
bcc: bcc,
|
37
|
+
bypass_opt_in_level: bypass_opt_in_level,
|
38
|
+
click_tracking: click_tracking,
|
39
|
+
html_body: html_body,
|
40
|
+
message_type: message_type,
|
41
|
+
open_tracking: open_tracking,
|
42
|
+
plaintext_body: plaintext_body,
|
43
|
+
reply_to: reply_to,
|
44
|
+
sender_address: sender_address,
|
45
|
+
sender_name: sender_name,
|
46
|
+
subject: subject
|
47
|
+
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
48
|
+
|
49
|
+
{'email': override}
|
50
|
+
end
|
51
|
+
|
52
|
+
def email_with_inline_template
|
53
|
+
fail ArgumentError, 'message_type is needed for email with inline template' if @message_type.nil?
|
54
|
+
fail ArgumentError, 'reply_to is needed for email with inline template' if @reply_to.nil?
|
55
|
+
fail ArgumentError, 'sender_address is needed for email with inline template' if @sender_address.nil?
|
56
|
+
fail ArgumentError, 'sender_name is needed for email with inline template' if @sender_name.nil?
|
57
|
+
|
58
|
+
inline_template = {
|
59
|
+
bcc: bcc,
|
60
|
+
click_tracking: click_tracking,
|
61
|
+
message_type: message_type,
|
62
|
+
open_tracking: open_tracking,
|
63
|
+
reply_to: reply_to,
|
64
|
+
sender_address: sender_address,
|
65
|
+
sender_name: sender_name,
|
66
|
+
template: define_template_object
|
67
|
+
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
68
|
+
|
69
|
+
{'email': inline_template}
|
70
|
+
end
|
71
|
+
|
72
|
+
def define_template_object
|
73
|
+
fail ArgumentError, 'Must choose between template_id or fields object' if template_id && plaintext_body && subject
|
74
|
+
template_portion = {
|
75
|
+
template_id: template_id,
|
76
|
+
fields: define_fields,
|
77
|
+
variable_details: variable_details
|
78
|
+
}.delete_if {|key, value| value.nil?}
|
79
|
+
end
|
80
|
+
|
81
|
+
def define_fields
|
82
|
+
if subject && plaintext_body
|
83
|
+
{
|
84
|
+
subject: subject,
|
85
|
+
plaintext_body: plaintext_body
|
86
|
+
}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|