urbanairship 5.4.0 → 5.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG +30 -0
- data/docs/ab_tests.rst +162 -0
- data/docs/automations.rst +212 -0
- data/docs/create_and_send.rst +551 -0
- data/docs/examples.rst +8 -8
- data/docs/index.rst +4 -0
- data/lib/urbanairship.rb +11 -0
- data/lib/urbanairship/ab_tests/ab_test.rb +89 -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/common.rb +2 -0
- data/lib/urbanairship/devices/create_and_send.rb +96 -0
- data/lib/urbanairship/devices/email.rb +30 -40
- data/lib/urbanairship/devices/email_notification.rb +92 -0
- data/lib/urbanairship/devices/mms_notification.rb +107 -0
- data/lib/urbanairship/devices/open_channel.rb +89 -44
- data/lib/urbanairship/devices/segment.rb +6 -9
- data/lib/urbanairship/devices/sms.rb +15 -18
- data/lib/urbanairship/devices/sms_notification.rb +54 -0
- data/lib/urbanairship/devices/static_lists.rb +6 -7
- data/lib/urbanairship/push/push.rb +19 -9
- data/lib/urbanairship/version.rb +1 -1
- data/urbanairship.gemspec +1 -1
- metadata +19 -7
data/docs/examples.rst
CHANGED
@@ -37,12 +37,12 @@ Complex audience with platform specifics
|
|
37
37
|
)
|
38
38
|
push.notification = UA.notification(
|
39
39
|
ios: UA.ios(
|
40
|
-
alert: "
|
40
|
+
alert: "Serena Williams wins U.S. Open",
|
41
41
|
badge: "+1",
|
42
42
|
extra: {"articleid" => "123456"}
|
43
43
|
),
|
44
44
|
android: UA.android(
|
45
|
-
alert: "Breaking Android News!
|
45
|
+
alert: "Breaking Android News! Serena Williams wins U.S. Open!",
|
46
46
|
extra: {"articleid" => "http://m.example.com/123456"}
|
47
47
|
),
|
48
48
|
amazon: UA.amazon(
|
@@ -64,7 +64,7 @@ Single iOS push
|
|
64
64
|
push = airship.create_push
|
65
65
|
push.audience = UA.ios_channel('channel-id')
|
66
66
|
push.notification = UA.notification(
|
67
|
-
ios: UA.ios(alert="
|
67
|
+
ios: UA.ios(alert="Your package is on its way!")
|
68
68
|
)
|
69
69
|
push.device_types = UA.device_types(['ios'])
|
70
70
|
push.send_push
|
@@ -78,10 +78,10 @@ Single iOS Rich Push with notification
|
|
78
78
|
push = airship.create_push
|
79
79
|
push.audience = UA.ios_channel('channel-id')
|
80
80
|
push.notification = UA.notification(
|
81
|
-
ios: UA.ios(alert="
|
81
|
+
ios: UA.ios(alert="Your package is on its way!")
|
82
82
|
)
|
83
83
|
push.device_types = UA.device_types(['ios'])
|
84
|
-
push.message = UA.message(title: "
|
84
|
+
push.message = UA.message(title: "Your package is on the way!", body: "<h1>Please complete our survey</h1>")
|
85
85
|
push.send_push
|
86
86
|
|
87
87
|
|
@@ -94,8 +94,8 @@ Rich Push with extra and without notification
|
|
94
94
|
push.audience = UA.all
|
95
95
|
push.device_types = UA.all
|
96
96
|
push.message = UA.message(
|
97
|
-
title: "
|
98
|
-
body: "<h1>
|
97
|
+
title: "Your package is on its way!",
|
98
|
+
body: "<h1>Would you please complete our customer survey?</h1>",
|
99
99
|
extra: {"articleid" => "http://m.example.com/123456"}
|
100
100
|
)
|
101
101
|
push.send_push
|
@@ -112,7 +112,7 @@ Scheduled iOS Push
|
|
112
112
|
sched.push = airship.create_push
|
113
113
|
sched.push.audience = UA.ios_channel('channel-id')
|
114
114
|
sched.push.notification = UA.notification(
|
115
|
-
ios: UA.ios(alert: "
|
115
|
+
ios: UA.ios(alert: "Your package is on its way!"))
|
116
116
|
sched.push.device_types = UA.device_types(['ios'])
|
117
117
|
|
118
118
|
sched.send_push
|
data/docs/index.rst
CHANGED
data/lib/urbanairship.rb
CHANGED
@@ -6,6 +6,10 @@ require 'urbanairship/devices/segment'
|
|
6
6
|
require 'urbanairship/devices/channel_uninstall'
|
7
7
|
require 'urbanairship/devices/sms'
|
8
8
|
require 'urbanairship/devices/email'
|
9
|
+
require 'urbanairship/devices/email_notification'
|
10
|
+
require 'urbanairship/devices/sms_notification'
|
11
|
+
require 'urbanairship/devices/mms_notification'
|
12
|
+
require 'urbanairship/devices/create_and_send'
|
9
13
|
require 'urbanairship/client'
|
10
14
|
require 'urbanairship/common'
|
11
15
|
require 'urbanairship/configuration'
|
@@ -19,6 +23,11 @@ require 'urbanairship/devices/open_channel'
|
|
19
23
|
require 'urbanairship/reports/response_statistics'
|
20
24
|
require 'urbanairship/devices/static_lists'
|
21
25
|
require 'urbanairship/push/location'
|
26
|
+
require 'urbanairship/automations/pipeline'
|
27
|
+
require 'urbanairship/automations/automation'
|
28
|
+
require 'urbanairship/ab_tests/variant'
|
29
|
+
require 'urbanairship/ab_tests/experiment'
|
30
|
+
require 'urbanairship/ab_tests/ab_test'
|
22
31
|
|
23
32
|
module Urbanairship
|
24
33
|
extend Urbanairship::Push::Audience
|
@@ -28,6 +37,8 @@ module Urbanairship
|
|
28
37
|
include Urbanairship::Devices
|
29
38
|
include Urbanairship::Reports
|
30
39
|
include Urbanairship::Push
|
40
|
+
include Urbanairship::Automations
|
41
|
+
include Urbanairship::AbTests
|
31
42
|
|
32
43
|
class << self
|
33
44
|
attr_accessor :configuration
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'urbanairship'
|
3
|
+
require 'urbanairship/ab_tests/experiment'
|
4
|
+
|
5
|
+
module Urbanairship
|
6
|
+
module AbTests
|
7
|
+
class AbTest
|
8
|
+
include Urbanairship::Common
|
9
|
+
include Urbanairship::Loggable
|
10
|
+
attr_accessor :limit,
|
11
|
+
:offset,
|
12
|
+
:experiment_object,
|
13
|
+
:experiment_id
|
14
|
+
|
15
|
+
def initialize(client: required('client'))
|
16
|
+
@client = client
|
17
|
+
end
|
18
|
+
|
19
|
+
def list_ab_test
|
20
|
+
response = @client.send_request(
|
21
|
+
method: 'GET',
|
22
|
+
url: EXPERIMENTS_URL + format_url_with_params
|
23
|
+
)
|
24
|
+
logger.info("Looking up A/B Tests for project")
|
25
|
+
response
|
26
|
+
end
|
27
|
+
|
28
|
+
def create_ab_test
|
29
|
+
response = @client.send_request(
|
30
|
+
method: 'POST',
|
31
|
+
body: JSON.dump(experiment_object),
|
32
|
+
url: EXPERIMENTS_URL,
|
33
|
+
content_type: 'application/json'
|
34
|
+
)
|
35
|
+
logger.info("Created A/B Test")
|
36
|
+
response
|
37
|
+
end
|
38
|
+
|
39
|
+
def list_scheduled_ab_test
|
40
|
+
response = @client.send_request(
|
41
|
+
method: 'GET',
|
42
|
+
url: EXPERIMENTS_URL + 'scheduled' + format_url_with_params
|
43
|
+
)
|
44
|
+
logger.info("Looking up scheduled A/B Tests for project")
|
45
|
+
response
|
46
|
+
end
|
47
|
+
|
48
|
+
def delete_ab_test
|
49
|
+
fail ArgumentError, 'experiment_id must be set to delete individual A/B test' if @experiment_id.nil?
|
50
|
+
response = @client.send_request(
|
51
|
+
method: 'DELETE',
|
52
|
+
url: EXPERIMENTS_URL + 'scheduled/' + experiment_id
|
53
|
+
)
|
54
|
+
logger.info("Deleting A/B test with ID #{experiment_id}")
|
55
|
+
response
|
56
|
+
end
|
57
|
+
|
58
|
+
def validate_ab_test
|
59
|
+
response = @client.send_request(
|
60
|
+
method: 'POST',
|
61
|
+
body: JSON.dump(experiment_object),
|
62
|
+
url: EXPERIMENTS_URL + 'validate',
|
63
|
+
content_type: 'application/json'
|
64
|
+
)
|
65
|
+
logger.info("Validating A/B Test")
|
66
|
+
response
|
67
|
+
end
|
68
|
+
|
69
|
+
def lookup_ab_test
|
70
|
+
fail ArgumentError, 'experiment_id must be set to lookup individual A/B Test' if @experiment_id.nil?
|
71
|
+
response = @client.send_request(
|
72
|
+
method: 'GET',
|
73
|
+
url: EXPERIMENTS_URL + experiment_id
|
74
|
+
)
|
75
|
+
logger.info("Looking up A/B test with ID #{experiment_id}")
|
76
|
+
response
|
77
|
+
end
|
78
|
+
|
79
|
+
def format_url_with_params
|
80
|
+
params = []
|
81
|
+
params << ['limit', limit] if limit
|
82
|
+
params << ['offset', offset] if offset
|
83
|
+
query = URI.encode_www_form(params)
|
84
|
+
'?' + query
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'urbanairship'
|
2
|
+
|
3
|
+
module Urbanairship
|
4
|
+
module AbTests
|
5
|
+
class Experiment
|
6
|
+
include Urbanairship::Common
|
7
|
+
include Urbanairship::Loggable
|
8
|
+
attr_accessor :audience,
|
9
|
+
:campaigns,
|
10
|
+
:control,
|
11
|
+
:created_at,
|
12
|
+
:description,
|
13
|
+
:device_types,
|
14
|
+
:id,
|
15
|
+
:name,
|
16
|
+
:push_id,
|
17
|
+
:variants
|
18
|
+
|
19
|
+
def initialize(client: required('client'))
|
20
|
+
@client = client
|
21
|
+
@variants = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def payload
|
25
|
+
fail ArgumentError, 'audience is required for experiment' if @audience.nil?
|
26
|
+
fail ArgumentError, 'device_types is required for experiment' if @device_types.nil?
|
27
|
+
fail ArgumentError, 'variant cannot be empty for experiment' if @variants.empty?
|
28
|
+
|
29
|
+
{
|
30
|
+
'name': name,
|
31
|
+
'description': description,
|
32
|
+
'control': control,
|
33
|
+
'audience': audience,
|
34
|
+
'device_types': device_types,
|
35
|
+
'campaigns': campaigns,
|
36
|
+
'variants': variants,
|
37
|
+
'id': id,
|
38
|
+
'created_at': created_at,
|
39
|
+
'push_id': push_id
|
40
|
+
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'urbanairship'
|
2
|
+
|
3
|
+
module Urbanairship
|
4
|
+
module AbTests
|
5
|
+
class Variant
|
6
|
+
include Urbanairship::Common
|
7
|
+
include Urbanairship::Loggable
|
8
|
+
attr_accessor :description,
|
9
|
+
:id,
|
10
|
+
:name,
|
11
|
+
:push,
|
12
|
+
:schedule,
|
13
|
+
:weight
|
14
|
+
|
15
|
+
def initialize(client: required('client'))
|
16
|
+
@client = client
|
17
|
+
end
|
18
|
+
|
19
|
+
def payload
|
20
|
+
fail ArgumentError, 'a push must be added to create a variant' if @push.nil?
|
21
|
+
|
22
|
+
{
|
23
|
+
'description': description,
|
24
|
+
'id': id,
|
25
|
+
'name': name,
|
26
|
+
'push': push,
|
27
|
+
'schedule': schedule,
|
28
|
+
'weight': weight
|
29
|
+
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'urbanairship'
|
3
|
+
require 'urbanairship/automations/pipeline'
|
4
|
+
|
5
|
+
module Urbanairship
|
6
|
+
module Automations
|
7
|
+
class Automation
|
8
|
+
include Urbanairship::Common
|
9
|
+
include Urbanairship::Loggable
|
10
|
+
attr_accessor :limit,
|
11
|
+
:enabled,
|
12
|
+
:offset,
|
13
|
+
:start,
|
14
|
+
:pipeline_id,
|
15
|
+
:pipeline_object
|
16
|
+
|
17
|
+
def initialize(client: required('client'))
|
18
|
+
@client = client
|
19
|
+
end
|
20
|
+
|
21
|
+
def create_automation
|
22
|
+
response = @client.send_request(
|
23
|
+
method: 'POST',
|
24
|
+
body: JSON.dump(pipeline_object),
|
25
|
+
url: PIPELINES_URL,
|
26
|
+
content_type: 'application/json'
|
27
|
+
)
|
28
|
+
logger.info("Created Automation")
|
29
|
+
response
|
30
|
+
end
|
31
|
+
|
32
|
+
def list_automations
|
33
|
+
response = @client.send_request(
|
34
|
+
method: 'GET',
|
35
|
+
url: PIPELINES_URL + format_url_with_params
|
36
|
+
)
|
37
|
+
logger.info("Looking up automations for project")
|
38
|
+
response
|
39
|
+
end
|
40
|
+
|
41
|
+
def list_deleted_automations
|
42
|
+
response = @client.send_request(
|
43
|
+
method: 'GET',
|
44
|
+
url: PIPELINES_URL + 'deleted' + format_url_with_params
|
45
|
+
)
|
46
|
+
logger.info("Looking up deleted automations for project")
|
47
|
+
response
|
48
|
+
end
|
49
|
+
|
50
|
+
def validate_automation
|
51
|
+
response = @client.send_request(
|
52
|
+
method: 'POST',
|
53
|
+
body: JSON.dump(pipeline_object),
|
54
|
+
url: PIPELINES_URL + 'validate',
|
55
|
+
content_type: 'application/json'
|
56
|
+
)
|
57
|
+
logger.info("Validating Automation")
|
58
|
+
response
|
59
|
+
end
|
60
|
+
|
61
|
+
def lookup_automation
|
62
|
+
fail ArgumentError, 'pipeline_id must be set to lookup individual automation' if @pipeline_id.nil?
|
63
|
+
response = @client.send_request(
|
64
|
+
method: 'GET',
|
65
|
+
url: PIPELINES_URL + pipeline_id
|
66
|
+
)
|
67
|
+
logger.info("Looking up automation with id #{pipeline_id}")
|
68
|
+
response
|
69
|
+
end
|
70
|
+
|
71
|
+
def update_automation
|
72
|
+
fail ArgumentError, 'pipeline_id must be set to update individual automation' if @pipeline_id.nil?
|
73
|
+
|
74
|
+
response = @client.send_request(
|
75
|
+
method: 'PUT',
|
76
|
+
body: JSON.dump(pipeline_object),
|
77
|
+
url: PIPELINES_URL + pipeline_id,
|
78
|
+
content_type: 'application/json'
|
79
|
+
)
|
80
|
+
logger.info("Validating Automation")
|
81
|
+
response
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete_automation
|
85
|
+
fail ArgumentError, 'pipeline_id must be set to delete individual automation' if @pipeline_id.nil?
|
86
|
+
response = @client.send_request(
|
87
|
+
method: 'DELETE',
|
88
|
+
url: PIPELINES_URL + pipeline_id
|
89
|
+
)
|
90
|
+
logger.info("Deleting automation with id #{pipeline_id}")
|
91
|
+
response
|
92
|
+
end
|
93
|
+
|
94
|
+
def format_url_with_params
|
95
|
+
params = []
|
96
|
+
params << ['limit', limit] if limit
|
97
|
+
params << ['enabled', enabled] if enabled
|
98
|
+
params << ['offset', offset] if offset
|
99
|
+
params << ['start', start] if start
|
100
|
+
query = URI.encode_www_form(params)
|
101
|
+
'?' + query
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'urbanairship'
|
2
|
+
|
3
|
+
module Urbanairship
|
4
|
+
module Automations
|
5
|
+
class Pipeline
|
6
|
+
include Urbanairship::Common
|
7
|
+
include Urbanairship::Loggable
|
8
|
+
attr_accessor :activation_time,
|
9
|
+
:cancellation_trigger,
|
10
|
+
:condition,
|
11
|
+
:constraint,
|
12
|
+
:creation_time,
|
13
|
+
:deactivation_time,
|
14
|
+
:historical_trigger,
|
15
|
+
:immediate_trigger,
|
16
|
+
:last_modified_time,
|
17
|
+
:name,
|
18
|
+
:status,
|
19
|
+
:timing,
|
20
|
+
:url,
|
21
|
+
:enabled,
|
22
|
+
:outcome
|
23
|
+
|
24
|
+
def initialize(client: required('client'))
|
25
|
+
@client = client
|
26
|
+
end
|
27
|
+
|
28
|
+
def payload
|
29
|
+
fail ArgumentError, 'enabled must be set to create pipeline payload' if @enabled.nil?
|
30
|
+
fail ArgumentError, 'outcome must be set to create pipeline payload' if @outcome.nil?
|
31
|
+
{
|
32
|
+
activation_time: activation_time,
|
33
|
+
cancellation_trigger: cancellation_trigger,
|
34
|
+
condition: condition,
|
35
|
+
constraint: constraint,
|
36
|
+
creation_time: creation_time,
|
37
|
+
deactivation_time: deactivation_time,
|
38
|
+
enabled: enabled,
|
39
|
+
historical_trigger: historical_trigger,
|
40
|
+
immediate_trigger: immediate_trigger,
|
41
|
+
last_modified_time: last_modified_time,
|
42
|
+
name: name,
|
43
|
+
outcome: outcome,
|
44
|
+
status: status,
|
45
|
+
timing: timing,
|
46
|
+
url: url
|
47
|
+
}.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/urbanairship/common.rb
CHANGED
@@ -19,6 +19,8 @@ module Urbanairship
|
|
19
19
|
PIPELINES_URL = BASE_URL + '/pipelines/'
|
20
20
|
FEEDS_URL = BASE_URL + '/feeds/'
|
21
21
|
LOCATION_URL = BASE_URL + '/location/'
|
22
|
+
CREATE_AND_SEND_URL = BASE_URL + '/create-and-send/'
|
23
|
+
EXPERIMENTS_URL = BASE_URL + '/experiments/'
|
22
24
|
|
23
25
|
# Helper method for required keyword args in Ruby 2.0 that is compatible with 2.1+
|
24
26
|
# @example
|
@@ -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
|
+
url: CREATE_AND_SEND_URL,
|
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
|
+
url: CREATE_AND_SEND_URL + '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
|
+
url: SCHEDULES_URL + '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
|