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,107 @@
|
|
1
|
+
require 'urbanairship'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Urbanairship
|
5
|
+
module Devices
|
6
|
+
class MmsNotification
|
7
|
+
include Urbanairship::Common
|
8
|
+
include Urbanairship::Loggable
|
9
|
+
|
10
|
+
attr_accessor :fallback_text,
|
11
|
+
:shorten_links,
|
12
|
+
:content_length,
|
13
|
+
:content_type,
|
14
|
+
:url,
|
15
|
+
:text,
|
16
|
+
:subject,
|
17
|
+
:template_id,
|
18
|
+
:slide_1_text
|
19
|
+
|
20
|
+
def initialize(client: required('client'))
|
21
|
+
@client = client
|
22
|
+
end
|
23
|
+
|
24
|
+
def validate_url
|
25
|
+
unless ['.jpg', '.gif', '.png', 'jpeg'].include?(@url[-4..-1])
|
26
|
+
fail ArgumentError, 'url must end in .gif, .jpg, .png, or .jpeg'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def mms_override
|
31
|
+
fail ArgumentError, 'fallback_text is needed for MMS override' if fallback_text.nil?
|
32
|
+
fail ArgumentError, 'content_length is needed for MMS override' if content_length.nil?
|
33
|
+
fail ArgumentError, 'content_type is needed for MMS override' if content_type.nil?
|
34
|
+
fail ArgumentError, 'url is needed for MMS override' if url.nil?
|
35
|
+
|
36
|
+
validate_url
|
37
|
+
|
38
|
+
override = {"mms": {
|
39
|
+
"subject": subject,
|
40
|
+
"fallback_text": fallback_text,
|
41
|
+
"shorten_links": shorten_links,
|
42
|
+
"slides": [
|
43
|
+
{
|
44
|
+
"text": text,
|
45
|
+
"media": {
|
46
|
+
"url": url,
|
47
|
+
"content_type": content_type,
|
48
|
+
"content_length": content_length
|
49
|
+
}
|
50
|
+
}
|
51
|
+
]
|
52
|
+
}
|
53
|
+
}
|
54
|
+
override
|
55
|
+
end
|
56
|
+
|
57
|
+
def mms_template_with_id
|
58
|
+
fail ArgumentError, 'content_length is needed for MMS Inline Template with ID' if content_length.nil?
|
59
|
+
fail ArgumentError, 'content_type is needed for MMS Inline Template with ID' if content_type.nil?
|
60
|
+
fail ArgumentError, 'url is needed for MMS Inline Template with ID' if url.nil?
|
61
|
+
fail ArgumentError, 'template_id is needed for MMS Inline Template with ID' if template_id.nil?
|
62
|
+
|
63
|
+
{"mms": {
|
64
|
+
"template": {
|
65
|
+
"template_id": template_id
|
66
|
+
},
|
67
|
+
"shorten_links": true,
|
68
|
+
"slides": [
|
69
|
+
{
|
70
|
+
"media": {
|
71
|
+
"url": url,
|
72
|
+
"content_type": content_type,
|
73
|
+
"content_length": content_length
|
74
|
+
}
|
75
|
+
}
|
76
|
+
]
|
77
|
+
}
|
78
|
+
}
|
79
|
+
end
|
80
|
+
|
81
|
+
def mms_inline_template
|
82
|
+
fail ArgumentError, 'slide_1_text text is needed for MMS with inline template' if text.nil?
|
83
|
+
|
84
|
+
{"mms": {
|
85
|
+
"template": {
|
86
|
+
"fields": {
|
87
|
+
"subject": subject,
|
88
|
+
"fallback_text": fallback_text,
|
89
|
+
"slide_1_text": text
|
90
|
+
}
|
91
|
+
},
|
92
|
+
"slides": [
|
93
|
+
{
|
94
|
+
"media": {
|
95
|
+
"url": url,
|
96
|
+
"content_type": content_type,
|
97
|
+
"content_length": content_length
|
98
|
+
}
|
99
|
+
}
|
100
|
+
]
|
101
|
+
}
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'urbanairship'
|
2
2
|
|
3
|
-
|
4
3
|
module Urbanairship
|
5
4
|
module Devices
|
6
5
|
class NamedUser
|
@@ -13,6 +12,17 @@ module Urbanairship
|
|
13
12
|
@named_user_id = nil
|
14
13
|
end
|
15
14
|
|
15
|
+
def update_attributes(attributes: required('attributes'))
|
16
|
+
response = @client.send_request(
|
17
|
+
method: 'POST',
|
18
|
+
body: Urbanairship::Attributes.new(attributes).payload.to_json,
|
19
|
+
path: named_users_path("#{@named_user_id}/attributes"),
|
20
|
+
content_type: CONTENT_TYPE,
|
21
|
+
)
|
22
|
+
logger.info { "Updated attributes for named_user #{@named_user_id}" }
|
23
|
+
response
|
24
|
+
end
|
25
|
+
|
16
26
|
def associate(channel_id: required('channel_id'), device_type: nil)
|
17
27
|
fail ArgumentError,
|
18
28
|
'named_user_id is required for association' if @named_user_id.nil?
|
@@ -20,13 +30,13 @@ module Urbanairship
|
|
20
30
|
payload = {}
|
21
31
|
payload['channel_id'] = channel_id
|
22
32
|
payload['device_type'] = device_type unless device_type.nil?
|
23
|
-
payload['named_user_id'] = @named_user_id
|
33
|
+
payload['named_user_id'] = @named_user_id.to_s
|
24
34
|
|
25
35
|
response = @client.send_request(
|
26
36
|
method: 'POST',
|
27
37
|
body: JSON.dump(payload),
|
28
|
-
|
29
|
-
content_type:
|
38
|
+
path: named_users_path('associate'),
|
39
|
+
content_type: CONTENT_TYPE
|
30
40
|
)
|
31
41
|
logger.info { "Associated channel_id #{channel_id} with named_user #{@named_user_id}" }
|
32
42
|
response
|
@@ -40,8 +50,8 @@ module Urbanairship
|
|
40
50
|
response = @client.send_request(
|
41
51
|
method: 'POST',
|
42
52
|
body: JSON.dump(payload),
|
43
|
-
|
44
|
-
content_type:
|
53
|
+
path: named_users_path('disassociate'),
|
54
|
+
content_type: CONTENT_TYPE
|
45
55
|
)
|
46
56
|
logger.info { "Dissociated channel_id #{channel_id}" }
|
47
57
|
response
|
@@ -51,8 +61,8 @@ module Urbanairship
|
|
51
61
|
fail ArgumentError,
|
52
62
|
'named_user_id is required for lookup' if @named_user_id.nil?
|
53
63
|
response = @client.send_request(
|
54
|
-
|
55
|
-
|
64
|
+
method: 'GET',
|
65
|
+
path: named_users_path('?id=' + @named_user_id),
|
56
66
|
)
|
57
67
|
logger.info { "Retrieved information on named_user_id #{@named_user_id}" }
|
58
68
|
response
|
@@ -65,7 +75,7 @@ module Urbanairship
|
|
65
75
|
|
66
76
|
def initialize(client: required('client'))
|
67
77
|
super(client: client)
|
68
|
-
@
|
78
|
+
@path = named_users_path('tags/')
|
69
79
|
end
|
70
80
|
|
71
81
|
def set_audience(user_ids: required('user_ids'))
|
@@ -79,7 +89,7 @@ module Urbanairship
|
|
79
89
|
|
80
90
|
def initialize(client: required('client'))
|
81
91
|
super(client: client)
|
82
|
-
@
|
92
|
+
@next_page_path = named_users_path
|
83
93
|
@data_attribute = 'named_users'
|
84
94
|
end
|
85
95
|
end
|
@@ -101,8 +111,8 @@ module Urbanairship
|
|
101
111
|
response = @client.send_request(
|
102
112
|
method: 'POST',
|
103
113
|
body: JSON.dump(payload),
|
104
|
-
|
105
|
-
content_type:
|
114
|
+
path: named_users_path('uninstall'),
|
115
|
+
content_type: CONTENT_TYPE
|
106
116
|
)
|
107
117
|
logger.info { "Uninstalled named_user_ids #{@named_user_ids} " }
|
108
118
|
response
|
@@ -5,101 +5,145 @@ module Urbanairship
|
|
5
5
|
class OpenChannel
|
6
6
|
include Urbanairship::Common
|
7
7
|
include Urbanairship::Loggable
|
8
|
-
attr_accessor :channel_id,
|
9
|
-
:
|
10
|
-
|
8
|
+
attr_accessor :channel_id,
|
9
|
+
:open_platform,
|
10
|
+
:opt_in,
|
11
|
+
:address,
|
12
|
+
:tags,
|
13
|
+
:identifiers,
|
14
|
+
:template_id,
|
15
|
+
:alert,
|
16
|
+
:extra,
|
17
|
+
:media_attachment,
|
18
|
+
:summary,
|
19
|
+
:title,
|
20
|
+
:template_id,
|
21
|
+
:fields,
|
22
|
+
:interactive,
|
23
|
+
:platform_alert
|
24
|
+
|
11
25
|
def initialize(client: required('client'))
|
12
26
|
@client = client
|
13
|
-
@channel_id = nil
|
14
|
-
@open_platform = nil
|
15
|
-
@opt_in = nil
|
16
|
-
@address = nil
|
17
|
-
@tags = nil
|
18
|
-
@identifiers = nil
|
19
27
|
end
|
20
|
-
|
28
|
+
|
21
29
|
def create()
|
22
|
-
fail TypeError, 'address must be set to create open channel' unless
|
23
|
-
fail TypeError, 'open_platform must be set to create open channel' unless
|
24
|
-
fail TypeError, 'opt_in must be boolean' unless [true, false].include?
|
25
|
-
|
30
|
+
fail TypeError, 'address must be set to create open channel' unless address.is_a? String
|
31
|
+
fail TypeError, 'open_platform must be set to create open channel' unless open_platform.is_a? String
|
32
|
+
fail TypeError, 'opt_in must be boolean' unless [true, false].include? opt_in
|
33
|
+
|
26
34
|
channel_data = {
|
27
35
|
'type': 'open',
|
28
|
-
'open': {:open_platform_name =>
|
29
|
-
'opt_in':
|
30
|
-
'address':
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
if @identifiers
|
37
|
-
channel_data[:open][:identifiers] = @identifiers
|
38
|
-
end
|
39
|
-
|
36
|
+
'open': {:open_platform_name => open_platform},
|
37
|
+
'opt_in': opt_in,
|
38
|
+
'address': address,
|
39
|
+
'tags': tags
|
40
|
+
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
41
|
+
|
42
|
+
set_identifiers
|
43
|
+
|
40
44
|
body = {'channel': channel_data}
|
41
|
-
|
45
|
+
|
42
46
|
response = @client.send_request(
|
43
47
|
method: 'POST',
|
44
|
-
|
48
|
+
path: open_channel_path,
|
45
49
|
body: JSON.dump(body),
|
46
50
|
content_type: 'application/json'
|
47
51
|
)
|
48
|
-
logger.info("Registering open channel with address: #{
|
52
|
+
logger.info("Registering open channel with address: #{address}")
|
49
53
|
response
|
50
54
|
end
|
51
|
-
|
55
|
+
|
52
56
|
def update(set_tags: required('set_tags'))
|
53
57
|
fail ArgumentError, 'set_tags must be boolean' unless [true, false].include? set_tags
|
54
|
-
fail ArgumentError, 'set_tags cannot be true when tags are not set' unless set_tags == true &&
|
55
|
-
fail TypeError, 'opt_in must be boolean' unless [true, false].include?
|
56
|
-
fail TypeError, 'address or channel_id must not be nil' unless
|
57
|
-
fail TypeError, 'open_platform cannot be nil' unless
|
58
|
-
fail TypeErorr, 'address must not be nil if opt_in is true' unless
|
59
|
-
|
58
|
+
fail ArgumentError, 'set_tags cannot be true when tags are not set' unless set_tags == true && tags != nil
|
59
|
+
fail TypeError, 'opt_in must be boolean' unless [true, false].include? opt_in
|
60
|
+
fail TypeError, 'address or channel_id must not be nil' unless address.is_a? String || channel_id.is_a?(String)
|
61
|
+
fail TypeError, 'open_platform cannot be nil' unless open_platform.is_a? String
|
62
|
+
fail TypeErorr, 'address must not be nil if opt_in is true' unless opt_in.is_a? TrueClass
|
63
|
+
|
60
64
|
channel_data = {
|
61
65
|
'type': 'open',
|
62
|
-
'open': {'open_platform_name':
|
63
|
-
'opt_in':
|
64
|
-
'set_tags': set_tags
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
end
|
73
|
-
if @tags
|
74
|
-
channel_data['tags'] = @tags
|
75
|
-
end
|
76
|
-
if @identifiers
|
77
|
-
channel_data['open']['identifiers'] = @identifiers
|
78
|
-
end
|
79
|
-
|
66
|
+
'open': {'open_platform_name': open_platform},
|
67
|
+
'opt_in': opt_in,
|
68
|
+
'set_tags': set_tags,
|
69
|
+
'channel_id': channel_id,
|
70
|
+
'address': address,
|
71
|
+
'tags': tags
|
72
|
+
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
73
|
+
|
74
|
+
set_identifiers
|
75
|
+
|
80
76
|
body = {'channel': channel_data}
|
81
|
-
|
77
|
+
|
82
78
|
response = @client.send_request(
|
83
79
|
method: 'POST',
|
84
|
-
|
80
|
+
path: open_channel_path,
|
85
81
|
body: JSON.dump(body),
|
86
82
|
content_type: 'application/json'
|
87
83
|
)
|
88
|
-
logger.info("Updating open channel with address #{
|
84
|
+
logger.info("Updating open channel with address #{address}")
|
89
85
|
response
|
90
86
|
end
|
91
|
-
|
87
|
+
|
92
88
|
def lookup(channel_id: required('channel_id'))
|
93
89
|
fail ArgumentError, 'channel_id needs to be a string' unless channel_id.is_a? String
|
94
|
-
|
90
|
+
|
95
91
|
response = @client.send_request(
|
96
92
|
method: 'GET',
|
97
|
-
|
93
|
+
path: channel_path(channel_id)
|
98
94
|
)
|
99
95
|
logger.info("Looking up info on device token #{channel_id}")
|
100
96
|
response
|
101
97
|
end
|
98
|
+
|
99
|
+
def notification_with_template_id
|
100
|
+
fail TypeError, 'open_platform cannot be nil' if open_platform.nil?
|
101
|
+
|
102
|
+
if alert
|
103
|
+
payload = {
|
104
|
+
"open::#{open_platform}":{
|
105
|
+
'template': {
|
106
|
+
'template_id': template_id,
|
107
|
+
'fields': {
|
108
|
+
'alert': alert
|
109
|
+
}
|
110
|
+
}
|
111
|
+
}
|
112
|
+
}
|
113
|
+
else
|
114
|
+
payload = {
|
115
|
+
"open::#{open_platform}":{
|
116
|
+
'template': {
|
117
|
+
'template_id': template_id,
|
118
|
+
}
|
119
|
+
}
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
payload
|
124
|
+
end
|
125
|
+
|
126
|
+
def open_channel_override
|
127
|
+
fail TypeError, 'open_platform cannot be nil' if open_platform.nil?
|
128
|
+
payload = {
|
129
|
+
'alert': platform_alert,
|
130
|
+
'extra': extra,
|
131
|
+
'media_attachment': media_attachment,
|
132
|
+
'summary': summary,
|
133
|
+
'title': title,
|
134
|
+
'interactive': interactive
|
135
|
+
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
136
|
+
|
137
|
+
{'alert': alert,
|
138
|
+
"open::#{open_platform}": payload}
|
139
|
+
end
|
140
|
+
|
141
|
+
def set_identifiers
|
142
|
+
if identifiers
|
143
|
+
channel_data[:open][:identifiers] = identifiers
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
102
147
|
end
|
103
148
|
end
|
104
149
|
end
|
105
|
-
|
@@ -12,9 +12,6 @@ module Urbanairship
|
|
12
12
|
|
13
13
|
def initialize(client: required('client'))
|
14
14
|
@client = client
|
15
|
-
@display_name = nil
|
16
|
-
@criteria = nil
|
17
|
-
@id = nil
|
18
15
|
end
|
19
16
|
|
20
17
|
# Build a Segment from the display_name and criteria attributes
|
@@ -25,13 +22,13 @@ module Urbanairship
|
|
25
22
|
fail ArgumentError,
|
26
23
|
'Both display_name and criteria must be set to a value' if display_name.nil? or criteria.nil?
|
27
24
|
payload = {
|
28
|
-
:
|
29
|
-
:
|
25
|
+
'display_name': display_name,
|
26
|
+
'criteria': criteria
|
30
27
|
}
|
31
28
|
response = @client.send_request(
|
32
29
|
method: 'POST',
|
33
30
|
body: JSON.dump(payload),
|
34
|
-
|
31
|
+
path: segments_path,
|
35
32
|
content_type: 'application/json'
|
36
33
|
)
|
37
34
|
logger.info { "Successful segment creation: #{@display_name}" }
|
@@ -48,7 +45,7 @@ module Urbanairship
|
|
48
45
|
'id must be set to a valid string' if id.nil?
|
49
46
|
response = @client.send_request(
|
50
47
|
method: 'GET',
|
51
|
-
|
48
|
+
path: segments_path(id)
|
52
49
|
)
|
53
50
|
logger.info("Retrieved segment information for #{id}")
|
54
51
|
@id = id
|
@@ -67,12 +64,12 @@ module Urbanairship
|
|
67
64
|
'Either display_name or criteria must be set to a value' if display_name.nil? and criteria.nil?
|
68
65
|
|
69
66
|
data = {}
|
70
|
-
data['display_name'] =
|
71
|
-
data['criteria'] =
|
67
|
+
data['display_name'] = display_name
|
68
|
+
data['criteria'] = criteria
|
72
69
|
response = @client.send_request(
|
73
70
|
method: 'PUT',
|
74
71
|
body: JSON.dump(data),
|
75
|
-
|
72
|
+
path: segments_path(@id),
|
76
73
|
content_type: 'application/json'
|
77
74
|
)
|
78
75
|
logger.info { "Successful segment update: #{@display_name}" }
|
@@ -83,13 +80,11 @@ module Urbanairship
|
|
83
80
|
#
|
84
81
|
# @ returns [Object] response HTTP response
|
85
82
|
def delete
|
86
|
-
fail ArgumentError,
|
87
|
-
'id cannot be nil' if @id.nil?
|
83
|
+
fail ArgumentError, 'id cannot be nil' if id.nil?
|
88
84
|
|
89
|
-
url = SEGMENTS_URL + @id
|
90
85
|
response = @client.send_request(
|
91
86
|
method: 'DELETE',
|
92
|
-
|
87
|
+
path: segments_path(id)
|
93
88
|
)
|
94
89
|
logger.info { "Successful segment deletion: #{@display_name}" }
|
95
90
|
response
|
@@ -101,7 +96,7 @@ module Urbanairship
|
|
101
96
|
|
102
97
|
def initialize(client: required('client'))
|
103
98
|
super(client: client)
|
104
|
-
@
|
99
|
+
@next_page_path = segments_path
|
105
100
|
@data_attribute = 'segments'
|
106
101
|
end
|
107
102
|
end
|
@@ -5,48 +5,76 @@ module Urbanairship
|
|
5
5
|
class Sms
|
6
6
|
include Urbanairship::Common
|
7
7
|
include Urbanairship::Loggable
|
8
|
-
attr_accessor :msisdn,
|
8
|
+
attr_accessor :msisdn,
|
9
|
+
:sender,
|
10
|
+
:opted_in,
|
11
|
+
:sender,
|
12
|
+
:locale_country,
|
13
|
+
:locale_language,
|
14
|
+
:timezone,
|
15
|
+
:channel_id
|
9
16
|
|
10
17
|
def initialize(client: required('client'))
|
11
18
|
@client = client
|
12
|
-
@sender = nil
|
13
|
-
@msisdn = nil
|
14
|
-
@opted_in = nil
|
15
19
|
end
|
16
20
|
|
17
21
|
def register
|
18
|
-
fail ArgumentError, 'sender must be set to register sms channel' if
|
19
|
-
fail ArgumentError, 'msisdn must be set to register sms channel' if
|
22
|
+
fail ArgumentError, 'sender must be set to register sms channel' if sender.nil?
|
23
|
+
fail ArgumentError, 'msisdn must be set to register sms channel' if msisdn.nil?
|
20
24
|
|
21
25
|
payload = {
|
22
|
-
'msisdn':
|
23
|
-
'sender':
|
24
|
-
'opted_in':
|
26
|
+
'msisdn': msisdn,
|
27
|
+
'sender': sender,
|
28
|
+
'opted_in': opted_in
|
25
29
|
}
|
26
30
|
|
27
31
|
response = @client.send_request(
|
28
32
|
method: 'POST',
|
29
33
|
body: JSON.dump(payload),
|
30
|
-
|
34
|
+
path: channel_path('sms'),
|
31
35
|
content_type: 'application/json'
|
32
36
|
)
|
33
37
|
logger.info("Registering SMS channel with msisdn #{@msisdn}")
|
34
38
|
response
|
35
39
|
end
|
36
40
|
|
41
|
+
def update
|
42
|
+
fail ArgumentError, 'sender must be set to update sms channel' if sender.nil?
|
43
|
+
fail ArgumentError, 'msisdn must be set to update sms channel' if msisdn.nil?
|
44
|
+
fail ArgumentError, 'channel_id must be set to update sms channel' if channel_id.nil?
|
45
|
+
|
46
|
+
payload = {
|
47
|
+
'msisdn': msisdn,
|
48
|
+
'sender': sender,
|
49
|
+
'opted_in': opted_in,
|
50
|
+
'locale_country': locale_country,
|
51
|
+
'locale_language': locale_language,
|
52
|
+
'timezone': timezone
|
53
|
+
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
54
|
+
|
55
|
+
response = @client.send_request(
|
56
|
+
method: 'PUT',
|
57
|
+
body: JSON.dump(payload),
|
58
|
+
path: channel_path('sms/' + channel_id),
|
59
|
+
content_type: 'application/json'
|
60
|
+
)
|
61
|
+
logger.info("Updating SMS channel with msisdn #{@channel_id}")
|
62
|
+
response
|
63
|
+
end
|
64
|
+
|
37
65
|
def opt_out
|
38
|
-
fail ArgumentError, 'sender must be set to
|
39
|
-
fail ArgumentError, 'msisdn must be set to
|
66
|
+
fail ArgumentError, 'sender must be set to opt out sms channel' if sender.nil?
|
67
|
+
fail ArgumentError, 'msisdn must be set to opt out sms channel' if msisdn.nil?
|
40
68
|
|
41
69
|
payload = {
|
42
|
-
'msisdn':
|
43
|
-
'sender':
|
70
|
+
'msisdn': msisdn,
|
71
|
+
'sender': sender,
|
44
72
|
}
|
45
73
|
|
46
74
|
response = @client.send_request(
|
47
75
|
method: 'POST',
|
48
76
|
body: JSON.dump(payload),
|
49
|
-
|
77
|
+
path: channel_path('sms/opt-out'),
|
50
78
|
content_type: 'application/json'
|
51
79
|
)
|
52
80
|
logger.info("Opting Out of SMS messages for #{@msisdn}")
|
@@ -54,18 +82,18 @@ module Urbanairship
|
|
54
82
|
end
|
55
83
|
|
56
84
|
def uninstall
|
57
|
-
fail ArgumentError, 'sender must be set to
|
58
|
-
fail ArgumentError, 'msisdn must be set to
|
85
|
+
fail ArgumentError, 'sender must be set to uninstall sms channel' if sender.nil?
|
86
|
+
fail ArgumentError, 'msisdn must be set to uninstall sms channel' if msisdn.nil?
|
59
87
|
|
60
88
|
payload = {
|
61
|
-
'msisdn':
|
62
|
-
'sender':
|
89
|
+
'msisdn': msisdn,
|
90
|
+
'sender': sender,
|
63
91
|
}
|
64
92
|
|
65
93
|
response = @client.send_request(
|
66
94
|
method: 'POST',
|
67
95
|
body: JSON.dump(payload),
|
68
|
-
|
96
|
+
path: channel_path('sms/uninstall'),
|
69
97
|
content_type: 'application/json'
|
70
98
|
)
|
71
99
|
logger.info("Uninstalling SMS channel for #{@msisdn}")
|
@@ -73,12 +101,12 @@ module Urbanairship
|
|
73
101
|
end
|
74
102
|
|
75
103
|
def lookup
|
76
|
-
fail ArgumentError,'msisdn is required for lookup' if
|
77
|
-
fail ArgumentError,'sender is required for lookup' if
|
104
|
+
fail ArgumentError,'msisdn is required for lookup' if msisdn.nil?
|
105
|
+
fail ArgumentError,'sender is required for lookup' if sender.nil?
|
78
106
|
|
79
107
|
response = @client.send_request(
|
80
108
|
method: 'GET',
|
81
|
-
|
109
|
+
path: channel_path('sms/' + @msisdn + '/' + @sender)
|
82
110
|
)
|
83
111
|
logger.info { "Retrieved information for msisdn #{@msisdn}" }
|
84
112
|
response
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'urbanairship'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Urbanairship
|
5
|
+
module Devices
|
6
|
+
class SmsNotification
|
7
|
+
include Urbanairship::Common
|
8
|
+
include Urbanairship::Loggable
|
9
|
+
|
10
|
+
attr_accessor :sms_alert,
|
11
|
+
:generic_alert,
|
12
|
+
:expiry,
|
13
|
+
:shorten_links,
|
14
|
+
:template_id
|
15
|
+
|
16
|
+
def initialize(client: required('client'))
|
17
|
+
@client = client
|
18
|
+
end
|
19
|
+
|
20
|
+
def sms_notification_override
|
21
|
+
{
|
22
|
+
"alert": generic_alert,
|
23
|
+
"sms": {
|
24
|
+
"alert": sms_alert,
|
25
|
+
"expiry": expiry,
|
26
|
+
"shorten_links": shorten_links
|
27
|
+
}
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def sms_inline_template
|
32
|
+
inline_template = {
|
33
|
+
"sms": {
|
34
|
+
"template": {}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
if @template_id
|
39
|
+
inline_template[:sms][:template][:template_id] = @template_id
|
40
|
+
end
|
41
|
+
|
42
|
+
if @sms_alert
|
43
|
+
inline_fields= {
|
44
|
+
"fields": {"alert": @sms_alert}
|
45
|
+
}
|
46
|
+
inline_template[:sms][:template] = inline_fields
|
47
|
+
end
|
48
|
+
|
49
|
+
inline_template
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|