urbanairship 5.5.0 → 5.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,37 +5,41 @@ module Urbanairship
5
5
  class OpenChannel
6
6
  include Urbanairship::Common
7
7
  include Urbanairship::Loggable
8
- attr_accessor :channel_id, :open_platform, :opt_in, :address,
9
- :tags, :identifiers
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
10
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 @address.is_a? String
23
- fail TypeError, 'open_platform must be set to create open channel' unless @open_platform.is_a? String
24
- fail TypeError, 'opt_in must be boolean' unless [true, false].include? @opt_in
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
25
33
 
26
34
  channel_data = {
27
35
  'type': 'open',
28
- 'open': {:open_platform_name => @open_platform},
29
- 'opt_in': @opt_in,
30
- 'address': @address
31
- }
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
32
41
 
33
- if @tags
34
- channel_data['tags'] = @tags
35
- end
36
- if @identifiers
37
- channel_data[:open][:identifiers] = @identifiers
38
- end
42
+ set_identifiers
39
43
 
40
44
  body = {'channel': channel_data}
41
45
 
@@ -45,37 +49,29 @@ module Urbanairship
45
49
  body: JSON.dump(body),
46
50
  content_type: 'application/json'
47
51
  )
48
- logger.info("Registering open channel with address: #{@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 && @tags != nil
55
- fail TypeError, 'opt_in must be boolean' unless [true, false].include? @opt_in
56
- fail TypeError, 'address or channel_id must not be nil' unless @address.is_a? String || @channel_id.is_a?(String)
57
- fail TypeError, 'open_platform cannot be nil' unless @open_platform.is_a? String
58
- fail TypeErorr, 'address must not be nil if opt_in is true' unless @opt_in.is_a? TrueClass
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
59
63
 
60
64
  channel_data = {
61
65
  'type': 'open',
62
- 'open': {'open_platform_name': @open_platform},
63
- 'opt_in': @opt_in,
64
- 'set_tags': set_tags
65
- }
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
66
73
 
67
- if @channel_id
68
- channel_data['channel_id'] = @channel_id
69
- end
70
- if @address
71
- channel_data['address'] = @address
72
- end
73
- if @tags
74
- channel_data['tags'] = @tags
75
- end
76
- if @identifiers
77
- channel_data['open']['identifiers'] = @identifiers
78
- end
74
+ set_identifiers
79
75
 
80
76
  body = {'channel': channel_data}
81
77
 
@@ -85,7 +81,7 @@ module Urbanairship
85
81
  body: JSON.dump(body),
86
82
  content_type: 'application/json'
87
83
  )
88
- logger.info("Updating open channel with address #{@address}")
84
+ logger.info("Updating open channel with address #{address}")
89
85
  response
90
86
  end
91
87
 
@@ -99,6 +95,55 @@ module Urbanairship
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
@@ -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,8 +22,8 @@ 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
- :display_name => @display_name,
29
- :criteria => @criteria
25
+ 'display_name': display_name,
26
+ 'criteria': criteria
30
27
  }
31
28
  response = @client.send_request(
32
29
  method: 'POST',
@@ -67,8 +64,8 @@ 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'] = @display_name
71
- data['criteria'] = @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),
@@ -84,9 +81,9 @@ module Urbanairship
84
81
  # @ returns [Object] response HTTP response
85
82
  def delete
86
83
  fail ArgumentError,
87
- 'id cannot be nil' if @id.nil?
84
+ 'id cannot be nil' if id.nil?
88
85
 
89
- url = SEGMENTS_URL + @id
86
+ url = SEGMENTS_URL + id
90
87
  response = @client.send_request(
91
88
  method: 'DELETE',
92
89
  url: url
@@ -9,19 +9,16 @@ module Urbanairship
9
9
 
10
10
  def initialize(client: required('client'))
11
11
  @client = client
12
- @sender = nil
13
- @msisdn = nil
14
- @opted_in = nil
15
12
  end
16
13
 
17
14
  def register
18
- fail ArgumentError, 'sender must be set to register sms channel' if @sender.nil?
19
- fail ArgumentError, 'msisdn must be set to register sms channel' if @msisdn.nil?
15
+ fail ArgumentError, 'sender must be set to register sms channel' if sender.nil?
16
+ fail ArgumentError, 'msisdn must be set to register sms channel' if msisdn.nil?
20
17
 
21
18
  payload = {
22
- 'msisdn': @msisdn,
23
- 'sender': @sender,
24
- 'opted_in': @opted_in
19
+ 'msisdn': msisdn,
20
+ 'sender': sender,
21
+ 'opted_in': opted_in
25
22
  }
26
23
 
27
24
  response = @client.send_request(
@@ -35,12 +32,12 @@ module Urbanairship
35
32
  end
36
33
 
37
34
  def opt_out
38
- fail ArgumentError, 'sender must be set to register sms channel' if @sender.nil?
39
- fail ArgumentError, 'msisdn must be set to register sms channel' if @msisdn.nil?
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?
40
37
 
41
38
  payload = {
42
- 'msisdn': @msisdn,
43
- 'sender': @sender,
39
+ 'msisdn': msisdn,
40
+ 'sender': sender,
44
41
  }
45
42
 
46
43
  response = @client.send_request(
@@ -54,12 +51,12 @@ module Urbanairship
54
51
  end
55
52
 
56
53
  def uninstall
57
- fail ArgumentError, 'sender must be set to register sms channel' if @sender.nil?
58
- fail ArgumentError, 'msisdn must be set to register sms channel' if @msisdn.nil?
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?
59
56
 
60
57
  payload = {
61
- 'msisdn': @msisdn,
62
- 'sender': @sender,
58
+ 'msisdn': msisdn,
59
+ 'sender': sender,
63
60
  }
64
61
 
65
62
  response = @client.send_request(
@@ -73,8 +70,8 @@ module Urbanairship
73
70
  end
74
71
 
75
72
  def lookup
76
- fail ArgumentError,'msisdn is required for lookup' if @msisdn.nil?
77
- fail ArgumentError,'sender is required for lookup' if @sender.nil?
73
+ fail ArgumentError,'msisdn is required for lookup' if msisdn.nil?
74
+ fail ArgumentError,'sender is required for lookup' if sender.nil?
78
75
 
79
76
  response = @client.send_request(
80
77
  method: 'GET',
@@ -15,20 +15,15 @@ module Urbanairship
15
15
 
16
16
  def initialize(client: required('client'))
17
17
  @client = client
18
- @alert = nil
19
- @generic_alert = nil
20
- @expiry = nil
21
- @shorten_links = nil
22
- @template_id = nil
23
18
  end
24
19
 
25
20
  def sms_notification_override
26
21
  {
27
- "alert": @generic_alert,
22
+ "alert": generic_alert,
28
23
  "sms": {
29
- "alert": @sms_alert,
30
- "expiry": @expiry,
31
- "shorten_links": @shorten_links
24
+ "alert": sms_alert,
25
+ "expiry": expiry,
26
+ "shorten_links": shorten_links
32
27
  }
33
28
  }
34
29
  end
@@ -11,12 +11,11 @@ module Urbanairship
11
11
  def initialize(client: required('client'))
12
12
  fail ArgumentError, 'Client cannot be set to nil' if client.nil?
13
13
  @client = client
14
- @name = nil
15
14
  end
16
15
 
17
16
  def create(description: nil, extras: nil)
18
- fail ArgumentError, 'Name must be set' if @name.nil?
19
- payload = {'name' => @name}
17
+ fail ArgumentError, 'Name must be set' if name.nil?
18
+ payload = {'name': name}
20
19
  payload['description'] = description unless description.nil?
21
20
  payload['extras'] = extras unless extras.nil?
22
21
 
@@ -31,7 +30,7 @@ module Urbanairship
31
30
  end
32
31
 
33
32
  def upload(csv_file: required('csv_file'), gzip: false)
34
- fail ArgumentError, 'Name must be set' if @name.nil?
33
+ fail ArgumentError, 'Name must be set' if name.nil?
35
34
  if gzip
36
35
  response = @client.send_request(
37
36
  method: 'PUT',
@@ -53,7 +52,7 @@ module Urbanairship
53
52
  end
54
53
 
55
54
  def update(description: nil, extras: nil)
56
- fail ArgumentError, 'Name must be set' if @name.nil?
55
+ fail ArgumentError, 'Name must be set' if name.nil?
57
56
  fail ArgumentError,
58
57
  'Either description or extras must be set to a value' if description.nil? and extras.nil?
59
58
  payload = {}
@@ -70,7 +69,7 @@ module Urbanairship
70
69
  end
71
70
 
72
71
  def lookup
73
- fail ArgumentError, 'Name must be set' if @name.nil?
72
+ fail ArgumentError, 'Name must be set' if name.nil?
74
73
  response = @client.send_request(
75
74
  method: 'GET',
76
75
  url: LISTS_URL + @name
@@ -80,7 +79,7 @@ module Urbanairship
80
79
  end
81
80
 
82
81
  def delete
83
- fail ArgumentError, 'Name must be set' if @name.nil?
82
+ fail ArgumentError, 'Name must be set' if name.nil?
84
83
  response = @client.send_request(
85
84
  method: 'DELETE',
86
85
  url: LISTS_URL + @name
@@ -8,9 +8,17 @@ module Urbanairship
8
8
 
9
9
  # A Push Notification.
10
10
  class Push
11
- attr_writer :client, :audience, :notification, :options,
12
- :device_types, :message, :in_app
13
- attr_reader :device_types, :audience
11
+ attr_writer :client
12
+
13
+ attr_accessor :device_types,
14
+ :audience,
15
+ :notification,
16
+ :options,
17
+ :message,
18
+ :in_app,
19
+ :campaigns,
20
+ :localizations
21
+
14
22
  include Urbanairship::Common
15
23
  include Urbanairship::Loggable
16
24
 
@@ -23,12 +31,14 @@ module Urbanairship
23
31
 
24
32
  def payload
25
33
  compact_helper({
26
- audience: @audience,
27
- notification: @notification,
28
- options: @options,
29
- device_types: @device_types,
30
- message: @message,
31
- in_app: @in_app
34
+ audience: audience,
35
+ notification: notification,
36
+ options: options,
37
+ device_types: device_types,
38
+ message: message,
39
+ in_app: in_app,
40
+ campaigns: campaigns,
41
+ localizations: localizations
32
42
  })
33
43
  end
34
44
 
@@ -14,6 +14,15 @@ module Urbanairship
14
14
  payload(:local_scheduled_time, datetime)
15
15
  end
16
16
 
17
+ # Uses predictive analysis to send push at optimal time
18
+ def optimal_scheduled_time(date)
19
+ {
20
+ 'best_time': {
21
+ 'send_date': date
22
+ }
23
+ }
24
+ end
25
+
17
26
  private
18
27
 
19
28
  def payload(name, time)
@@ -1,3 +1,3 @@
1
1
  module Urbanairship
2
- VERSION = '5.5.0'
2
+ VERSION = '5.8.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: urbanairship
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.5.0
4
+ version: 5.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airship
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-02 00:00:00.000000000 Z
11
+ date: 2020-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -138,6 +138,9 @@ files:
138
138
  - bin/console
139
139
  - bin/setup
140
140
  - docs/Makefile
141
+ - docs/ab_tests.rst
142
+ - docs/attributes.rst
143
+ - docs/automations.rst
141
144
  - docs/channel_uninstall.rst
142
145
  - docs/conf.py
143
146
  - docs/create_and_send.rst
@@ -157,9 +160,15 @@ files:
157
160
  - docs/tags.rst
158
161
  - example/pusher.rb
159
162
  - lib/urbanairship.rb
163
+ - lib/urbanairship/ab_tests/ab_test.rb
164
+ - lib/urbanairship/ab_tests/experiment.rb
165
+ - lib/urbanairship/ab_tests/variant.rb
166
+ - lib/urbanairship/automations/automation.rb
167
+ - lib/urbanairship/automations/pipeline.rb
160
168
  - lib/urbanairship/client.rb
161
169
  - lib/urbanairship/common.rb
162
170
  - lib/urbanairship/configuration.rb
171
+ - lib/urbanairship/devices/attribute.rb
163
172
  - lib/urbanairship/devices/channel_tags.rb
164
173
  - lib/urbanairship/devices/channel_uninstall.rb
165
174
  - lib/urbanairship/devices/create_and_send.rb
@@ -188,7 +197,7 @@ licenses:
188
197
  - Apache-2.0
189
198
  metadata:
190
199
  allowed_push_host: https://rubygems.org
191
- post_install_message:
200
+ post_install_message:
192
201
  rdoc_options: []
193
202
  require_paths:
194
203
  - lib
@@ -204,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
204
213
  version: '0'
205
214
  requirements: []
206
215
  rubygems_version: 3.0.1
207
- signing_key:
216
+ signing_key:
208
217
  specification_version: 4
209
218
  summary: Ruby Gem for using the Airship API
210
219
  test_files: []