urbanairship 5.5.1 → 5.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,14 +19,6 @@ module Urbanairship
19
19
 
20
20
  def initialize(client: required('client'))
21
21
  @client = client
22
- @fallback_text = nil
23
- @shorten_links = nil
24
- @content_length = nil
25
- @content_type = nil
26
- @url = nil
27
- @text = nil
28
- @subject = nil
29
- @template_id = nil
30
22
  end
31
23
 
32
24
  def validate_url
@@ -36,24 +28,24 @@ module Urbanairship
36
28
  end
37
29
 
38
30
  def mms_override
39
- fail ArgumentError, 'fallback_text is needed for MMS override' if @fallback_text.nil?
40
- fail ArgumentError, 'content_length is needed for MMS override' if @content_length.nil?
41
- fail ArgumentError, 'content_type is needed for MMS override' if @content_type.nil?
42
- fail ArgumentError, 'url is needed for MMS override' if @url.nil?
31
+ fail ArgumentError, 'fallback_text is needed for MMS override' if fallback_text.nil?
32
+ fail ArgumentError, 'content_length is needed for MMS override' if content_length.nil?
33
+ fail ArgumentError, 'content_type is needed for MMS override' if content_type.nil?
34
+ fail ArgumentError, 'url is needed for MMS override' if url.nil?
43
35
 
44
36
  validate_url
45
37
 
46
38
  override = {"mms": {
47
- "subject": @subject,
48
- "fallback_text": @fallback_text,
49
- "shorten_links": @shorten_links,
39
+ "subject": subject,
40
+ "fallback_text": fallback_text,
41
+ "shorten_links": shorten_links,
50
42
  "slides": [
51
43
  {
52
- "text": @text,
44
+ "text": text,
53
45
  "media": {
54
- "url": @url,
55
- "content_type": @content_type,
56
- "content_length": @content_length
46
+ "url": url,
47
+ "content_type": content_type,
48
+ "content_length": content_length
57
49
  }
58
50
  }
59
51
  ]
@@ -63,22 +55,22 @@ module Urbanairship
63
55
  end
64
56
 
65
57
  def mms_template_with_id
66
- fail ArgumentError, 'content_length is needed for MMS Inline Template with ID' if @content_length.nil?
67
- fail ArgumentError, 'content_type is needed for MMS Inline Template with ID' if @content_type.nil?
68
- fail ArgumentError, 'url is needed for MMS Inline Template with ID' if @url.nil?
69
- fail ArgumentError, 'template_id is needed for MMS Inline Template with ID' if @template_id.nil?
58
+ fail ArgumentError, 'content_length is needed for MMS Inline Template with ID' if content_length.nil?
59
+ fail ArgumentError, 'content_type is needed for MMS Inline Template with ID' if content_type.nil?
60
+ fail ArgumentError, 'url is needed for MMS Inline Template with ID' if url.nil?
61
+ fail ArgumentError, 'template_id is needed for MMS Inline Template with ID' if template_id.nil?
70
62
 
71
63
  {"mms": {
72
64
  "template": {
73
- "template_id": @template_id
65
+ "template_id": template_id
74
66
  },
75
67
  "shorten_links": true,
76
68
  "slides": [
77
69
  {
78
70
  "media": {
79
- "url": @url,
80
- "content_type": @content_type,
81
- "content_length": @content_length
71
+ "url": url,
72
+ "content_type": content_type,
73
+ "content_length": content_length
82
74
  }
83
75
  }
84
76
  ]
@@ -87,22 +79,22 @@ module Urbanairship
87
79
  end
88
80
 
89
81
  def mms_inline_template
90
- fail ArgumentError, 'slide_1_text text is needed for MMS with inline template' if @text.nil?
82
+ fail ArgumentError, 'slide_1_text text is needed for MMS with inline template' if text.nil?
91
83
 
92
84
  {"mms": {
93
85
  "template": {
94
86
  "fields": {
95
- "subject": @subject,
96
- "fallback_text": @fallback_text,
97
- "slide_1_text": @text
87
+ "subject": subject,
88
+ "fallback_text": fallback_text,
89
+ "slide_1_text": text
98
90
  }
99
91
  },
100
92
  "slides": [
101
93
  {
102
94
  "media": {
103
- "url": @url,
104
- "content_type": @content_type,
105
- "content_length": @content_length
95
+ "url": url,
96
+ "content_type": content_type,
97
+ "content_length": content_length
106
98
  }
107
99
  }
108
100
  ]
@@ -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
@@ -5,23 +5,27 @@ 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
12
- @sender = nil
13
- @msisdn = nil
14
- @opted_in = nil
15
19
  end
16
20
 
17
21
  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?
22
+ fail ArgumentError, 'sender must be set to register sms channel' if sender.nil?
23
+ fail ArgumentError, 'msisdn must be set to register sms channel' if msisdn.nil?
20
24
 
21
25
  payload = {
22
- 'msisdn': @msisdn,
23
- 'sender': @sender,
24
- 'opted_in': @opted_in
26
+ 'msisdn': msisdn,
27
+ 'sender': sender,
28
+ 'opted_in': opted_in
25
29
  }
26
30
 
27
31
  response = @client.send_request(
@@ -34,13 +38,37 @@ module Urbanairship
34
38
  response
35
39
  end
36
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
+
37
65
  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?
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?
40
68
 
41
69
  payload = {
42
- 'msisdn': @msisdn,
43
- 'sender': @sender,
70
+ 'msisdn': msisdn,
71
+ 'sender': sender,
44
72
  }
45
73
 
46
74
  response = @client.send_request(
@@ -54,12 +82,12 @@ module Urbanairship
54
82
  end
55
83
 
56
84
  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?
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?
59
87
 
60
88
  payload = {
61
- 'msisdn': @msisdn,
62
- 'sender': @sender,
89
+ 'msisdn': msisdn,
90
+ 'sender': sender,
63
91
  }
64
92
 
65
93
  response = @client.send_request(
@@ -73,8 +101,8 @@ module Urbanairship
73
101
  end
74
102
 
75
103
  def lookup
76
- fail ArgumentError,'msisdn is required for lookup' if @msisdn.nil?
77
- fail ArgumentError,'sender is required for lookup' if @sender.nil?
104
+ fail ArgumentError,'msisdn is required for lookup' if msisdn.nil?
105
+ fail ArgumentError,'sender is required for lookup' if sender.nil?
78
106
 
79
107
  response = @client.send_request(
80
108
  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