urbanairship 5.7.0 → 8.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/PULL_REQUEST_TEMPLATE.md +2 -2
- data/.travis.yml +2 -2
- data/CHANGELOG +33 -0
- data/README.rst +95 -38
- data/docs/attributes.rst +73 -0
- data/docs/index.rst +3 -0
- data/docs/named_user.rst +22 -0
- data/docs/push.rst +24 -0
- data/docs/sms.rst +19 -0
- data/docs/static_lists.rst +2 -2
- data/lib/urbanairship.rb +7 -0
- data/lib/urbanairship/ab_tests/ab_test.rb +8 -9
- data/lib/urbanairship/automations/automation.rb +11 -11
- data/lib/urbanairship/client.rb +34 -12
- data/lib/urbanairship/common.rb +110 -43
- data/lib/urbanairship/configuration.rb +2 -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 +4 -4
- data/lib/urbanairship/devices/devicelist.rb +28 -7
- data/lib/urbanairship/devices/email.rb +5 -5
- data/lib/urbanairship/devices/named_user.rb +22 -12
- data/lib/urbanairship/devices/open_channel.rb +22 -23
- data/lib/urbanairship/devices/segment.rb +6 -8
- data/lib/urbanairship/devices/sms.rb +40 -9
- data/lib/urbanairship/devices/static_lists.rb +12 -12
- data/lib/urbanairship/push/location.rb +18 -18
- data/lib/urbanairship/push/push.rb +5 -5
- 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/urbanairship.gemspec +1 -0
- metadata +25 -6
@@ -5,11 +5,11 @@ module Urbanairship
|
|
5
5
|
class OpenChannel
|
6
6
|
include Urbanairship::Common
|
7
7
|
include Urbanairship::Loggable
|
8
|
-
attr_accessor :channel_id,
|
9
|
-
:open_platform,
|
10
|
-
:opt_in,
|
8
|
+
attr_accessor :channel_id,
|
9
|
+
:open_platform,
|
10
|
+
:opt_in,
|
11
11
|
:address,
|
12
|
-
:tags,
|
12
|
+
:tags,
|
13
13
|
:identifiers,
|
14
14
|
:template_id,
|
15
15
|
:alert,
|
@@ -21,16 +21,16 @@ module Urbanairship
|
|
21
21
|
:fields,
|
22
22
|
:interactive,
|
23
23
|
:platform_alert
|
24
|
-
|
24
|
+
|
25
25
|
def initialize(client: required('client'))
|
26
26
|
@client = client
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def create()
|
30
30
|
fail TypeError, 'address must be set to create open channel' unless address.is_a? String
|
31
31
|
fail TypeError, 'open_platform must be set to create open channel' unless open_platform.is_a? String
|
32
32
|
fail TypeError, 'opt_in must be boolean' unless [true, false].include? opt_in
|
33
|
-
|
33
|
+
|
34
34
|
channel_data = {
|
35
35
|
'type': 'open',
|
36
36
|
'open': {:open_platform_name => open_platform},
|
@@ -38,21 +38,21 @@ module Urbanairship
|
|
38
38
|
'address': address,
|
39
39
|
'tags': tags
|
40
40
|
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
41
|
-
|
41
|
+
|
42
42
|
set_identifiers
|
43
|
-
|
43
|
+
|
44
44
|
body = {'channel': channel_data}
|
45
|
-
|
45
|
+
|
46
46
|
response = @client.send_request(
|
47
47
|
method: 'POST',
|
48
|
-
|
48
|
+
path: open_channel_path,
|
49
49
|
body: JSON.dump(body),
|
50
50
|
content_type: 'application/json'
|
51
51
|
)
|
52
52
|
logger.info("Registering open channel with address: #{address}")
|
53
53
|
response
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
def update(set_tags: required('set_tags'))
|
57
57
|
fail ArgumentError, 'set_tags must be boolean' unless [true, false].include? set_tags
|
58
58
|
fail ArgumentError, 'set_tags cannot be true when tags are not set' unless set_tags == true && tags != nil
|
@@ -60,7 +60,7 @@ module Urbanairship
|
|
60
60
|
fail TypeError, 'address or channel_id must not be nil' unless address.is_a? String || channel_id.is_a?(String)
|
61
61
|
fail TypeError, 'open_platform cannot be nil' unless open_platform.is_a? String
|
62
62
|
fail TypeErorr, 'address must not be nil if opt_in is true' unless opt_in.is_a? TrueClass
|
63
|
-
|
63
|
+
|
64
64
|
channel_data = {
|
65
65
|
'type': 'open',
|
66
66
|
'open': {'open_platform_name': open_platform},
|
@@ -70,34 +70,34 @@ module Urbanairship
|
|
70
70
|
'address': address,
|
71
71
|
'tags': tags
|
72
72
|
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
73
|
-
|
73
|
+
|
74
74
|
set_identifiers
|
75
|
-
|
75
|
+
|
76
76
|
body = {'channel': channel_data}
|
77
|
-
|
77
|
+
|
78
78
|
response = @client.send_request(
|
79
79
|
method: 'POST',
|
80
|
-
|
80
|
+
path: open_channel_path,
|
81
81
|
body: JSON.dump(body),
|
82
82
|
content_type: 'application/json'
|
83
83
|
)
|
84
84
|
logger.info("Updating open channel with address #{address}")
|
85
85
|
response
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
def lookup(channel_id: required('channel_id'))
|
89
89
|
fail ArgumentError, 'channel_id needs to be a string' unless channel_id.is_a? String
|
90
|
-
|
90
|
+
|
91
91
|
response = @client.send_request(
|
92
92
|
method: 'GET',
|
93
|
-
|
93
|
+
path: channel_path(channel_id)
|
94
94
|
)
|
95
95
|
logger.info("Looking up info on device token #{channel_id}")
|
96
96
|
response
|
97
97
|
end
|
98
98
|
|
99
99
|
def notification_with_template_id
|
100
|
-
fail TypeError, 'open_platform cannot be nil' if open_platform.nil?
|
100
|
+
fail TypeError, 'open_platform cannot be nil' if open_platform.nil?
|
101
101
|
|
102
102
|
if alert
|
103
103
|
payload = {
|
@@ -124,7 +124,7 @@ module Urbanairship
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def open_channel_override
|
127
|
-
fail TypeError, 'open_platform cannot be nil' if open_platform.nil?
|
127
|
+
fail TypeError, 'open_platform cannot be nil' if open_platform.nil?
|
128
128
|
payload = {
|
129
129
|
'alert': platform_alert,
|
130
130
|
'extra': extra,
|
@@ -147,4 +147,3 @@ module Urbanairship
|
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end
|
150
|
-
|
@@ -28,7 +28,7 @@ module Urbanairship
|
|
28
28
|
response = @client.send_request(
|
29
29
|
method: 'POST',
|
30
30
|
body: JSON.dump(payload),
|
31
|
-
|
31
|
+
path: segments_path,
|
32
32
|
content_type: 'application/json'
|
33
33
|
)
|
34
34
|
logger.info { "Successful segment creation: #{@display_name}" }
|
@@ -45,7 +45,7 @@ module Urbanairship
|
|
45
45
|
'id must be set to a valid string' if id.nil?
|
46
46
|
response = @client.send_request(
|
47
47
|
method: 'GET',
|
48
|
-
|
48
|
+
path: segments_path(id)
|
49
49
|
)
|
50
50
|
logger.info("Retrieved segment information for #{id}")
|
51
51
|
@id = id
|
@@ -69,7 +69,7 @@ module Urbanairship
|
|
69
69
|
response = @client.send_request(
|
70
70
|
method: 'PUT',
|
71
71
|
body: JSON.dump(data),
|
72
|
-
|
72
|
+
path: segments_path(@id),
|
73
73
|
content_type: 'application/json'
|
74
74
|
)
|
75
75
|
logger.info { "Successful segment update: #{@display_name}" }
|
@@ -80,13 +80,11 @@ module Urbanairship
|
|
80
80
|
#
|
81
81
|
# @ returns [Object] response HTTP response
|
82
82
|
def delete
|
83
|
-
fail ArgumentError,
|
84
|
-
'id cannot be nil' if id.nil?
|
83
|
+
fail ArgumentError, 'id cannot be nil' if id.nil?
|
85
84
|
|
86
|
-
url = SEGMENTS_URL + id
|
87
85
|
response = @client.send_request(
|
88
86
|
method: 'DELETE',
|
89
|
-
|
87
|
+
path: segments_path(id)
|
90
88
|
)
|
91
89
|
logger.info { "Successful segment deletion: #{@display_name}" }
|
92
90
|
response
|
@@ -98,7 +96,7 @@ module Urbanairship
|
|
98
96
|
|
99
97
|
def initialize(client: required('client'))
|
100
98
|
super(client: client)
|
101
|
-
@
|
99
|
+
@next_page_path = segments_path
|
102
100
|
@data_attribute = 'segments'
|
103
101
|
end
|
104
102
|
end
|
@@ -5,7 +5,14 @@ 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
|
@@ -24,16 +31,40 @@ module Urbanairship
|
|
24
31
|
response = @client.send_request(
|
25
32
|
method: 'POST',
|
26
33
|
body: JSON.dump(payload),
|
27
|
-
|
34
|
+
path: channel_path('sms'),
|
28
35
|
content_type: 'application/json'
|
29
36
|
)
|
30
37
|
logger.info("Registering SMS channel with msisdn #{@msisdn}")
|
31
38
|
response
|
32
39
|
end
|
33
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
|
+
|
34
65
|
def opt_out
|
35
|
-
fail ArgumentError, 'sender must be set to
|
36
|
-
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?
|
37
68
|
|
38
69
|
payload = {
|
39
70
|
'msisdn': msisdn,
|
@@ -43,7 +74,7 @@ module Urbanairship
|
|
43
74
|
response = @client.send_request(
|
44
75
|
method: 'POST',
|
45
76
|
body: JSON.dump(payload),
|
46
|
-
|
77
|
+
path: channel_path('sms/opt-out'),
|
47
78
|
content_type: 'application/json'
|
48
79
|
)
|
49
80
|
logger.info("Opting Out of SMS messages for #{@msisdn}")
|
@@ -51,8 +82,8 @@ module Urbanairship
|
|
51
82
|
end
|
52
83
|
|
53
84
|
def uninstall
|
54
|
-
fail ArgumentError, 'sender must be set to
|
55
|
-
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?
|
56
87
|
|
57
88
|
payload = {
|
58
89
|
'msisdn': msisdn,
|
@@ -62,7 +93,7 @@ module Urbanairship
|
|
62
93
|
response = @client.send_request(
|
63
94
|
method: 'POST',
|
64
95
|
body: JSON.dump(payload),
|
65
|
-
|
96
|
+
path: channel_path('sms/uninstall'),
|
66
97
|
content_type: 'application/json'
|
67
98
|
)
|
68
99
|
logger.info("Uninstalling SMS channel for #{@msisdn}")
|
@@ -75,7 +106,7 @@ module Urbanairship
|
|
75
106
|
|
76
107
|
response = @client.send_request(
|
77
108
|
method: 'GET',
|
78
|
-
|
109
|
+
path: channel_path('sms/' + @msisdn + '/' + @sender)
|
79
110
|
)
|
80
111
|
logger.info { "Retrieved information for msisdn #{@msisdn}" }
|
81
112
|
response
|
@@ -13,16 +13,16 @@ module Urbanairship
|
|
13
13
|
@client = client
|
14
14
|
end
|
15
15
|
|
16
|
-
def create(description: nil,
|
16
|
+
def create(description: nil, extra: nil)
|
17
17
|
fail ArgumentError, 'Name must be set' if name.nil?
|
18
18
|
payload = {'name': name}
|
19
19
|
payload['description'] = description unless description.nil?
|
20
|
-
payload['
|
20
|
+
payload['extra'] = extra unless extra.nil?
|
21
21
|
|
22
22
|
response = @client.send_request(
|
23
23
|
method: 'POST',
|
24
24
|
body: JSON.dump(payload),
|
25
|
-
|
25
|
+
path: lists_path,
|
26
26
|
content_type: 'application/json'
|
27
27
|
)
|
28
28
|
logger.info("Created static list for #{@name}")
|
@@ -35,7 +35,7 @@ module Urbanairship
|
|
35
35
|
response = @client.send_request(
|
36
36
|
method: 'PUT',
|
37
37
|
body: csv_file,
|
38
|
-
|
38
|
+
path: lists_path(@name + '/csv/'),
|
39
39
|
content_type: 'text/csv',
|
40
40
|
encoding: gzip
|
41
41
|
)
|
@@ -43,7 +43,7 @@ module Urbanairship
|
|
43
43
|
response = @client.send_request(
|
44
44
|
method: 'PUT',
|
45
45
|
body: csv_file,
|
46
|
-
|
46
|
+
path: lists_path(@name + '/csv/'),
|
47
47
|
content_type: 'text/csv'
|
48
48
|
)
|
49
49
|
end
|
@@ -51,17 +51,17 @@ module Urbanairship
|
|
51
51
|
response
|
52
52
|
end
|
53
53
|
|
54
|
-
def update(description: nil,
|
54
|
+
def update(description: nil, extra: nil)
|
55
55
|
fail ArgumentError, 'Name must be set' if name.nil?
|
56
56
|
fail ArgumentError,
|
57
|
-
'Either description or extras must be set to a value' if description.nil? and
|
57
|
+
'Either description or extras must be set to a value' if description.nil? and extra.nil?
|
58
58
|
payload = {}
|
59
59
|
payload['description'] = description unless description.nil?
|
60
|
-
payload['
|
60
|
+
payload['extra'] = extra unless extra.nil?
|
61
61
|
response = @client.send_request(
|
62
62
|
method: 'PUT',
|
63
63
|
body: JSON.dump(payload),
|
64
|
-
|
64
|
+
path: lists_path(@name),
|
65
65
|
content_type: 'application/json'
|
66
66
|
)
|
67
67
|
logger.info("Updating the metadata for list #{@name}")
|
@@ -72,7 +72,7 @@ module Urbanairship
|
|
72
72
|
fail ArgumentError, 'Name must be set' if name.nil?
|
73
73
|
response = @client.send_request(
|
74
74
|
method: 'GET',
|
75
|
-
|
75
|
+
path: lists_path(@name)
|
76
76
|
)
|
77
77
|
logger.info("Retrieving info for list #{@name}")
|
78
78
|
response
|
@@ -82,7 +82,7 @@ module Urbanairship
|
|
82
82
|
fail ArgumentError, 'Name must be set' if name.nil?
|
83
83
|
response = @client.send_request(
|
84
84
|
method: 'DELETE',
|
85
|
-
|
85
|
+
path: lists_path(@name)
|
86
86
|
)
|
87
87
|
logger.info("Deleted list #{@name}")
|
88
88
|
response
|
@@ -92,7 +92,7 @@ module Urbanairship
|
|
92
92
|
class StaticLists < Urbanairship::Common::PageIterator
|
93
93
|
def initialize(client: required('client'))
|
94
94
|
super(client: client)
|
95
|
-
@
|
95
|
+
@next_page_path = lists_path
|
96
96
|
@data_attribute = 'lists'
|
97
97
|
end
|
98
98
|
end
|
@@ -14,11 +14,11 @@ module Urbanairship
|
|
14
14
|
def name_lookup(name: required('name'), type: nil)
|
15
15
|
fail ArgumentError, 'name needs to be a string' unless name.is_a? String
|
16
16
|
fail ArgumentError, 'type needs to be a string' unless type.nil? or type.is_a? String
|
17
|
-
|
18
|
-
|
17
|
+
path = location_path('?q=' + name)
|
18
|
+
path += '&type=' + type unless type.nil?
|
19
19
|
resp = @client.send_request(
|
20
20
|
method: 'GET',
|
21
|
-
|
21
|
+
path: path
|
22
22
|
)
|
23
23
|
logger.info("Retrieved location information for #{name}")
|
24
24
|
resp
|
@@ -28,11 +28,11 @@ module Urbanairship
|
|
28
28
|
fail ArgumentError,
|
29
29
|
'latitude and longitude need to be numbers' unless latitude.is_a? Numeric and longitude.is_a? Numeric
|
30
30
|
fail ArgumentError, 'type needs to be a string' unless type.nil? or type.is_a? String
|
31
|
-
|
32
|
-
|
31
|
+
path = location_path(latitude.to_s + ',' + longitude.to_s)
|
32
|
+
path += '?type=' + type unless type.nil?
|
33
33
|
resp = @client.send_request(
|
34
34
|
method: 'GET',
|
35
|
-
|
35
|
+
path: path
|
36
36
|
)
|
37
37
|
logger.info("Retrieved location information for latitude #{latitude} and longitude #{longitude}")
|
38
38
|
resp
|
@@ -45,11 +45,11 @@ module Urbanairship
|
|
45
45
|
'lat1, long1, lat2, and long2 need to be numbers' unless lat1.is_a? Numeric and long2.is_a? Numeric\
|
46
46
|
and lat2.is_a? Numeric and long2.is_a? Numeric
|
47
47
|
fail ArgumentError, 'type needs to be a string' unless type.nil? or type.is_a? String
|
48
|
-
|
49
|
-
|
48
|
+
path = location_path(lat1.to_s + ',' + long1.to_s + ',' + lat2.to_s + ',' + long2.to_s)
|
49
|
+
path += '?type=' + type unless type.nil?
|
50
50
|
resp = @client.send_request(
|
51
51
|
method: 'GET',
|
52
|
-
|
52
|
+
path: path
|
53
53
|
)
|
54
54
|
logger.info("Retrieved location information for bounding box with lat1 #{lat1}, long1 #{long1}," +
|
55
55
|
" lat2 #{lat2}, and long2 #{long2}")
|
@@ -58,20 +58,20 @@ module Urbanairship
|
|
58
58
|
|
59
59
|
def alias_lookup(from_alias: required('from_alias'))
|
60
60
|
fail ArgumentError, 'from_alias needs to be a string or an array of strings' unless from_alias.is_a? String or from_alias.is_a? Array
|
61
|
-
|
61
|
+
path = location_path('from-alias?')
|
62
62
|
if from_alias.is_a? Array
|
63
63
|
from_alias.each do |a|
|
64
64
|
fail ArgumentError, 'from_alias needs to be a string or an array of strings' unless a.is_a? String
|
65
|
-
|
65
|
+
path += a + '&'
|
66
66
|
end
|
67
|
-
|
67
|
+
path = path.chop
|
68
68
|
else
|
69
|
-
|
69
|
+
path += from_alias
|
70
70
|
end
|
71
71
|
|
72
72
|
resp = @client.send_request(
|
73
73
|
method: 'GET',
|
74
|
-
|
74
|
+
path: path
|
75
75
|
)
|
76
76
|
logger.info("Retrieved location info from alias #{from_alias}")
|
77
77
|
resp
|
@@ -81,10 +81,10 @@ module Urbanairship
|
|
81
81
|
fail ArgumentError, 'polygon_id needs to be a string' unless polygon_id.is_a? String
|
82
82
|
fail ArgumentError, 'zoom needs to be an integer' unless zoom.is_a? Integer
|
83
83
|
|
84
|
-
|
84
|
+
path = location_path(polygon_id + '?zoom=' + zoom.to_s)
|
85
85
|
resp = @client.send_request(
|
86
86
|
method: 'GET',
|
87
|
-
|
87
|
+
path: path
|
88
88
|
)
|
89
89
|
logger.info("Retrieved location info for polygon #{polygon_id} and zoom level #{zoom}")
|
90
90
|
resp
|
@@ -93,11 +93,11 @@ module Urbanairship
|
|
93
93
|
def date_ranges
|
94
94
|
resp = @client.send_request(
|
95
95
|
method: 'GET',
|
96
|
-
|
96
|
+
path: segments_path('dates/')
|
97
97
|
)
|
98
98
|
logger.info('Retrieved location date ranges')
|
99
99
|
resp
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
103
|
-
end
|
103
|
+
end
|