urbanairship 5.6.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +30 -0
  3. data/README.rst +1 -0
  4. data/docs/ab_tests.rst +162 -0
  5. data/docs/attributes.rst +52 -0
  6. data/docs/automations.rst +212 -0
  7. data/docs/index.rst +3 -0
  8. data/docs/push.rst +24 -0
  9. data/docs/sms.rst +19 -0
  10. data/docs/static_lists.rst +2 -2
  11. data/lib/urbanairship.rb +12 -0
  12. data/lib/urbanairship/ab_tests/ab_test.rb +88 -0
  13. data/lib/urbanairship/ab_tests/experiment.rb +45 -0
  14. data/lib/urbanairship/ab_tests/variant.rb +34 -0
  15. data/lib/urbanairship/automations/automation.rb +105 -0
  16. data/lib/urbanairship/automations/pipeline.rb +52 -0
  17. data/lib/urbanairship/client.rb +22 -9
  18. data/lib/urbanairship/common.rb +63 -16
  19. data/lib/urbanairship/configuration.rb +2 -1
  20. data/lib/urbanairship/custom_events/custom_event.rb +60 -0
  21. data/lib/urbanairship/custom_events/payload.rb +89 -0
  22. data/lib/urbanairship/devices/attribute.rb +54 -0
  23. data/lib/urbanairship/devices/channel_tags.rb +1 -1
  24. data/lib/urbanairship/devices/channel_uninstall.rb +10 -10
  25. data/lib/urbanairship/devices/create_and_send.rb +4 -4
  26. data/lib/urbanairship/devices/devicelist.rb +28 -7
  27. data/lib/urbanairship/devices/email.rb +5 -5
  28. data/lib/urbanairship/devices/email_notification.rb +11 -4
  29. data/lib/urbanairship/devices/named_user.rb +6 -6
  30. data/lib/urbanairship/devices/open_channel.rb +22 -23
  31. data/lib/urbanairship/devices/segment.rb +5 -5
  32. data/lib/urbanairship/devices/sms.rb +40 -9
  33. data/lib/urbanairship/devices/static_lists.rb +12 -12
  34. data/lib/urbanairship/push/location.rb +7 -7
  35. data/lib/urbanairship/push/push.rb +23 -13
  36. data/lib/urbanairship/push/schedule.rb +9 -0
  37. data/lib/urbanairship/reports/response_statistics.rb +9 -9
  38. data/lib/urbanairship/version.rb +1 -1
  39. metadata +16 -5
@@ -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
- url: CHANNEL_URL + uuid
20
+ url: channel_url(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
+ url: channel_url('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
- @next_page = CHANNEL_URL
49
+ @next_page = channel_url
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
- url: DEVICE_TOKEN_URL + token
67
+ url: device_token_url(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
- @next_page = DEVICE_TOKEN_URL
80
+ @next_page = device_token_url
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
- url: APID_URL + apid
98
+ url: apid_url(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
- @next_page = APID_URL
108
+ @next_page = apid_url
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
- url: CHANNEL_URL + 'email',
44
+ url: channel_url('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
- url: CHANNEL_URL + 'email/uninstall',
61
+ url: channel_url('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
- url: CHANNEL_URL + 'email/' + address
73
+ url: channel_url('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
- url: CHANNEL_URL + 'email/' + channel_id,
98
+ url: channel_url('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
- @url = CHANNEL_URL + 'email/tags'
112
+ @url = channel_url('email/tags')
113
113
  end
114
114
 
115
115
  def set_audience(email_address: required('email_address'))
@@ -70,16 +70,23 @@ module Urbanairship
70
70
  end
71
71
 
72
72
  def define_template_object
73
+ fail ArgumentError, 'Must choose between template_id or fields object' if template_id && plaintext_body && subject
73
74
  template_portion = {
74
75
  template_id: template_id,
75
- fields: {
76
- subject: subject,
77
- plaintext_body: plaintext_body
78
- },
76
+ fields: define_fields,
79
77
  variable_details: variable_details
80
78
  }.delete_if {|key, value| value.nil?}
81
79
  end
82
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
+
83
90
  end
84
91
  end
85
92
  end
@@ -25,7 +25,7 @@ module Urbanairship
25
25
  response = @client.send_request(
26
26
  method: 'POST',
27
27
  body: JSON.dump(payload),
28
- url: NAMED_USER_URL + '/associate',
28
+ url: named_users_url('/associate'),
29
29
  content_type: 'application/json'
30
30
  )
31
31
  logger.info { "Associated channel_id #{channel_id} with named_user #{@named_user_id}" }
@@ -40,7 +40,7 @@ module Urbanairship
40
40
  response = @client.send_request(
41
41
  method: 'POST',
42
42
  body: JSON.dump(payload),
43
- url: NAMED_USER_URL + '/disassociate',
43
+ url: named_users_url('/disassociate'),
44
44
  content_type: 'application/json'
45
45
  )
46
46
  logger.info { "Dissociated channel_id #{channel_id}" }
@@ -52,7 +52,7 @@ module Urbanairship
52
52
  'named_user_id is required for lookup' if @named_user_id.nil?
53
53
  response = @client.send_request(
54
54
  method: 'GET',
55
- url: NAMED_USER_URL + '?id=' + @named_user_id,
55
+ url: named_users_url('?id=' + @named_user_id),
56
56
  )
57
57
  logger.info { "Retrieved information on named_user_id #{@named_user_id}" }
58
58
  response
@@ -65,7 +65,7 @@ module Urbanairship
65
65
 
66
66
  def initialize(client: required('client'))
67
67
  super(client: client)
68
- @url = NAMED_USER_URL + 'tags/'
68
+ @url = named_users_url('tags/')
69
69
  end
70
70
 
71
71
  def set_audience(user_ids: required('user_ids'))
@@ -79,7 +79,7 @@ module Urbanairship
79
79
 
80
80
  def initialize(client: required('client'))
81
81
  super(client: client)
82
- @next_page = NAMED_USER_URL
82
+ @next_page = named_users_url
83
83
  @data_attribute = 'named_users'
84
84
  end
85
85
  end
@@ -101,7 +101,7 @@ module Urbanairship
101
101
  response = @client.send_request(
102
102
  method: 'POST',
103
103
  body: JSON.dump(payload),
104
- url: NAMED_USER_URL + '/uninstall',
104
+ url: named_users_url('/uninstall'),
105
105
  content_type: 'application/json'
106
106
  )
107
107
  logger.info { "Uninstalled named_user_ids #{@named_user_ids} " }
@@ -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
- url: OPEN_CHANNEL_URL,
48
+ url: open_channel_url,
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
- url: OPEN_CHANNEL_URL,
80
+ url: open_channel_url,
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
- url: CHANNEL_URL + channel_id
93
+ url: channel_url(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
- url: SEGMENTS_URL,
31
+ url: segments_url,
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
- url: SEGMENTS_URL + id
48
+ url: segments_url(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
- url: SEGMENTS_URL + @id,
72
+ url: segments_url(@id),
73
73
  content_type: 'application/json'
74
74
  )
75
75
  logger.info { "Successful segment update: #{@display_name}" }
@@ -83,7 +83,7 @@ module Urbanairship
83
83
  fail ArgumentError,
84
84
  'id cannot be nil' if id.nil?
85
85
 
86
- url = SEGMENTS_URL + id
86
+ url = segments_url(id)
87
87
  response = @client.send_request(
88
88
  method: 'DELETE',
89
89
  url: url
@@ -98,7 +98,7 @@ module Urbanairship
98
98
 
99
99
  def initialize(client: required('client'))
100
100
  super(client: client)
101
- @next_page = SEGMENTS_URL
101
+ @next_page = segments_url
102
102
  @data_attribute = 'segments'
103
103
  end
104
104
  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, :sender, :opted_in, :sender
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
- url: CHANNEL_URL + 'sms',
34
+ url: channel_url('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
+ url: channel_url('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 register sms channel' if sender.nil?
36
- fail ArgumentError, 'msisdn must be set to register sms channel' if msisdn.nil?
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
- url: CHANNEL_URL + 'sms/opt-out',
77
+ url: channel_url('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 register sms channel' if sender.nil?
55
- fail ArgumentError, 'msisdn must be set to register sms channel' if msisdn.nil?
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
- url: CHANNEL_URL + 'sms/uninstall',
96
+ url: channel_url('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
- url: CHANNEL_URL + 'sms/' + @msisdn + '/' + @sender
109
+ url: channel_url('sms/' + @msisdn + '/' + @sender)
79
110
  )
80
111
  logger.info { "Retrieved information for msisdn #{@msisdn}" }
81
112
  response