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
@@ -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
|
@@ -44,7 +44,7 @@ module Urbanairship
|
|
44
44
|
campaign_object = {'categories': campaigns}
|
45
45
|
full_payload[:campaigns] = campaign_object
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
full_payload
|
49
49
|
end
|
50
50
|
|
@@ -52,7 +52,7 @@ module Urbanairship
|
|
52
52
|
response = @client.send_request(
|
53
53
|
method: 'POST',
|
54
54
|
body: JSON.dump(payload),
|
55
|
-
|
55
|
+
path: create_and_send_path,
|
56
56
|
content_type: 'application/json'
|
57
57
|
)
|
58
58
|
logger.info("Running create and send for addresses #{@addresses}")
|
@@ -63,7 +63,7 @@ module Urbanairship
|
|
63
63
|
response = @client.send_request(
|
64
64
|
method: 'POST',
|
65
65
|
body: JSON.dump(payload),
|
66
|
-
|
66
|
+
path: create_and_send_path('validate'),
|
67
67
|
content_type: 'application/json'
|
68
68
|
)
|
69
69
|
logger.info("Validating payload for create and send")
|
@@ -84,7 +84,7 @@ module Urbanairship
|
|
84
84
|
response = @client.send_request(
|
85
85
|
method: 'POST',
|
86
86
|
body: JSON.dump(scheduled_payload),
|
87
|
-
|
87
|
+
path: schedules_path('create-and-send'),
|
88
88
|
content_type: 'application/json'
|
89
89
|
)
|
90
90
|
logger.info("Scheduling create and send operation with name #{@name}")
|
@@ -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
|
@@ -41,7 +41,7 @@ module Urbanairship
|
|
41
41
|
response = @client.send_request(
|
42
42
|
method: 'POST',
|
43
43
|
body: JSON.dump(payload),
|
44
|
-
|
44
|
+
path: channel_path('email'),
|
45
45
|
content_type: 'application/json'
|
46
46
|
)
|
47
47
|
logger.info("Registering email channel with address #{address}")
|
@@ -58,7 +58,7 @@ module Urbanairship
|
|
58
58
|
response = @client.send_request(
|
59
59
|
method: 'POST',
|
60
60
|
body: JSON.dump(payload),
|
61
|
-
|
61
|
+
path: channel_path('email/uninstall'),
|
62
62
|
content_type: 'application/json'
|
63
63
|
)
|
64
64
|
logger.info("Uninstalling email channel with address #{address}")
|
@@ -70,7 +70,7 @@ module Urbanairship
|
|
70
70
|
|
71
71
|
response = @client.send_request(
|
72
72
|
method: 'GET',
|
73
|
-
|
73
|
+
path: channel_path('email/' + address)
|
74
74
|
)
|
75
75
|
logger.info("Looking up email channel with address #{address}")
|
76
76
|
response
|
@@ -95,7 +95,7 @@ module Urbanairship
|
|
95
95
|
|
96
96
|
response = @client.send_request(
|
97
97
|
method: 'PUT',
|
98
|
-
|
98
|
+
path: channel_path('email/' + channel_id),
|
99
99
|
body: JSON.dump(payload),
|
100
100
|
content_type: 'application/json'
|
101
101
|
)
|
@@ -109,7 +109,7 @@ module Urbanairship
|
|
109
109
|
|
110
110
|
def initialize(client: required('client'))
|
111
111
|
super(client: client)
|
112
|
-
@
|
112
|
+
@path = channel_path('email/tags')
|
113
113
|
end
|
114
114
|
|
115
115
|
def set_audience(email_address: required('email_address'))
|
@@ -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
|