urbanairship 5.3.0 → 5.6.1

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',
@@ -0,0 +1,54 @@
1
+ require 'urbanairship'
2
+ require 'json'
3
+
4
+ module Urbanairship
5
+ module Devices
6
+ class SmsNotification
7
+ include Urbanairship::Common
8
+ include Urbanairship::Loggable
9
+
10
+ attr_accessor :sms_alert,
11
+ :generic_alert,
12
+ :expiry,
13
+ :shorten_links,
14
+ :template_id
15
+
16
+ def initialize(client: required('client'))
17
+ @client = client
18
+ end
19
+
20
+ def sms_notification_override
21
+ {
22
+ "alert": generic_alert,
23
+ "sms": {
24
+ "alert": sms_alert,
25
+ "expiry": expiry,
26
+ "shorten_links": shorten_links
27
+ }
28
+ }
29
+ end
30
+
31
+ def sms_inline_template
32
+ inline_template = {
33
+ "sms": {
34
+ "template": {}
35
+ }
36
+ }
37
+
38
+ if @template_id
39
+ inline_template[:sms][:template][:template_id] = @template_id
40
+ end
41
+
42
+ if @sms_alert
43
+ inline_fields= {
44
+ "fields": {"alert": @sms_alert}
45
+ }
46
+ inline_template[:sms][:template] = inline_fields
47
+ end
48
+
49
+ inline_template
50
+ end
51
+
52
+ end
53
+ end
54
+ 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
@@ -1,3 +1,3 @@
1
1
  module Urbanairship
2
- VERSION = '5.3.0'
2
+ VERSION = '5.6.1'
3
3
  end
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
32
32
  spec.add_development_dependency 'bundler', '>= 1'
33
33
  spec.add_development_dependency 'guard-rspec'
34
34
  spec.add_development_dependency 'pry', '~> 0'
35
- spec.add_development_dependency 'rake', '~> 10.0'
35
+ spec.add_development_dependency 'rake', '~> 12.3.3'
36
36
  spec.add_development_dependency 'rspec', '~> 3'
37
37
  spec.add_development_dependency 'terminal-notifier-guard', '~> 1'
38
38
  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.3.0
4
+ version: 5.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airship
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-12 00:00:00.000000000 Z
11
+ date: 2020-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '10.0'
81
+ version: 12.3.3
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '10.0'
88
+ version: 12.3.3
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: rspec
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +140,7 @@ files:
140
140
  - docs/Makefile
141
141
  - docs/channel_uninstall.rst
142
142
  - docs/conf.py
143
+ - docs/create_and_send.rst
143
144
  - docs/devices.rst
144
145
  - docs/email.rst
145
146
  - docs/examples.rst
@@ -161,12 +162,16 @@ files:
161
162
  - lib/urbanairship/configuration.rb
162
163
  - lib/urbanairship/devices/channel_tags.rb
163
164
  - lib/urbanairship/devices/channel_uninstall.rb
165
+ - lib/urbanairship/devices/create_and_send.rb
164
166
  - lib/urbanairship/devices/devicelist.rb
165
167
  - lib/urbanairship/devices/email.rb
168
+ - lib/urbanairship/devices/email_notification.rb
169
+ - lib/urbanairship/devices/mms_notification.rb
166
170
  - lib/urbanairship/devices/named_user.rb
167
171
  - lib/urbanairship/devices/open_channel.rb
168
172
  - lib/urbanairship/devices/segment.rb
169
173
  - lib/urbanairship/devices/sms.rb
174
+ - lib/urbanairship/devices/sms_notification.rb
170
175
  - lib/urbanairship/devices/static_lists.rb
171
176
  - lib/urbanairship/loggable.rb
172
177
  - lib/urbanairship/push/audience.rb