urbanairship 5.5.1 → 5.6.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b69d5dcd7102160071266e66723dce74d1752386a4ebbda9e12cff07b3ddeb33
4
- data.tar.gz: d579b09d0d59cc728f445dc51793051745431000631ff74f00b2f8be46386fb1
3
+ metadata.gz: c447a1f428a9ad9ba9a2f56d9ceeaea45969828c3eadaa97b33497c302eac851
4
+ data.tar.gz: 7347eb5271eb74d15493d18d2970b3d1e4e7fcc8053d1303ba5706453ac9a946
5
5
  SHA512:
6
- metadata.gz: 739853d57c2b626679a5175ad4282766e2165d16279d27dd25746f5853ca38720e3b9f70c7627294fe15ce18d3c95c4147ddfba853111e5650c3711d34852d5e
7
- data.tar.gz: e6bb28f136bb85d7429f3368ce2909a5d8e97fb7cff680a632cf969ef87fdbdd3be83195d48319c824cdf2388032a899a57ebbfc9c8ee40fb88c878ae9f5d99b
6
+ metadata.gz: 38c2236678e3ec19ebf328671ef73247cfee22bab34627ce9425e18b8ca8377136c39e21e7685bd29a0877ec82b00d355c961eb170bfa20c45bf82860ca271ac
7
+ data.tar.gz: d4c9ef053d0639db6f65f0b554cb51aeeddeaec4cfa1a95d7ac553be46f330e7dffe2e3068054eb8831fda2c8e8b633470a631559ac7921189d08a20a688e1e0
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ --------------------
2
+ 5.6.0
3
+ --------------------
4
+ - Refactors EmailNotification class
5
+ - Adds Create and Send implementation to Open Channel class
6
+
1
7
  --------------------
2
8
  5.5.1
3
9
  --------------------
@@ -487,3 +487,65 @@ shown in the line of code here:
487
487
  .. note::
488
488
 
489
489
  Should return a 202 Accepted HTTP response.
490
+
491
+ Create and Send to Open Channels
492
+ ================================
493
+
494
+ Create and Send to Open Channels with Template ID
495
+ -------------------------------------------------
496
+
497
+ The first few lines of code are creating an OpenChannel object, and assigning
498
+ instance variables to that object. This is essentially creating the payload that
499
+ will be passed to notification portion of the CreateAndSend class, which ultimately
500
+ is sending a fully constructed payload to the API.
501
+
502
+ .. code-block:: ruby
503
+
504
+ require 'urbanairship'
505
+ UA = Urbanairship
506
+ airship = UA::Client.new(key:'<app_key>', secret:'<master_secret>')
507
+ open_channel_notification = UA::OpenChannel.new(client:airship)
508
+ open_channel_notification.open_platform = 'smart_fridge'
509
+ open_channel_notification.template_id = "<template_id>"
510
+ send_it = UA::CreateAndSend.new(client: airship)
511
+ send_it.addresses = [
512
+ {
513
+ "ua_address": "<ua_address>",
514
+ "name": "Jane"
515
+ }
516
+ ]
517
+ send_it.device_types = [ 'open::smart_fridge' ]
518
+ send_it.notification = open_channel_notification.
519
+ send_it.campaigns = ["winter sale", "west coast"]
520
+ send_it.create_and_send
521
+
522
+ Create and Send to Open Channels Override
523
+ ------------------------------------------
524
+
525
+ The first few lines of code are creating an OpenChannel object, and assigning
526
+ instance variables to that object. This is essentially creating the payload that
527
+ will be passed to notification portion of the CreateAndSend class, which ultimately
528
+ is sending a fully constructed payload to the API.
529
+
530
+ .. code-block:: ruby
531
+
532
+ require 'urbanairship'
533
+ UA = Urbanairship
534
+ airship = UA::Client.new(key:'<app_key>', secret:'<master_secret>')
535
+ open_channel_notification = UA::OpenChannel.new(client:airship)
536
+ open_channel_notification.open_platform = 'smart_fridge'
537
+ open_channel_notification.alert = 'a general alert for all open channels'
538
+ open_channel_notification.platform_alert = 'an alert for specific open channel platforms'
539
+ open_channel_notification.media_attachment = 'https://example.com/cat_standing_up.jpeg'
540
+ open_channel_notification.title = 'That\'s pretty neat!'
541
+ send_it = UA::CreateAndSend.new(client: airship)
542
+ send_it.addresses = [
543
+ {
544
+ "ua_address": "<ua_address>",
545
+ "name": "Jane"
546
+ }
547
+ ]
548
+ send_it.device_types = [ 'open::smart_fridge' ]
549
+ send_it.notification = open_channel_notification,open_channel_override
550
+ send_it.campaigns = ["winter sale", "west coast"]
551
+ send_it.create_and_send
@@ -15,12 +15,6 @@ module Urbanairship
15
15
 
16
16
  def initialize(client: required('client'))
17
17
  @client = client
18
- @addresses = nil
19
- @device_types = nil
20
- @notification = nil
21
- @campaigns = nil
22
- @name = nil
23
- @scheduled_time = nil
24
18
  end
25
19
 
26
20
  def validate_address
@@ -40,17 +34,17 @@ module Urbanairship
40
34
 
41
35
  full_payload = {
42
36
  'audience': {
43
- 'create_and_send': @addresses
37
+ 'create_and_send': addresses
44
38
  },
45
- 'device_types': @device_types,
46
- 'notification': @notification,
39
+ 'device_types': device_types,
40
+ 'notification': notification,
47
41
  }
48
42
 
49
- if @campaigns
50
- campaign_object = {'categories': @campaigns}
43
+ if campaigns
44
+ campaign_object = {'categories': campaigns}
51
45
  full_payload[:campaigns] = campaign_object
52
46
  end
53
-
47
+
54
48
  full_payload
55
49
  end
56
50
 
@@ -81,9 +75,9 @@ module Urbanairship
81
75
 
82
76
  scheduled_payload = {
83
77
  "schedule": {
84
- "scheduled_time": @scheduled_time
78
+ "scheduled_time": scheduled_time
85
79
  },
86
- "name": @name,
80
+ "name": name,
87
81
  "push": payload
88
82
  }
89
83
 
@@ -19,16 +19,6 @@ module Urbanairship
19
19
 
20
20
  def initialize(client: required('client'))
21
21
  @client = client
22
- @address = nil
23
- @commercial_opted_in = nil
24
- @commercial_opted_out = nil
25
- @locale_country = nil
26
- @locale_language = nil
27
- @timezone = nil
28
- @transactional_opted_in = nil
29
- @transactional_opted_out = nil
30
- @type = nil
31
- @channel_id = nil
32
22
  end
33
23
 
34
24
  def register
@@ -36,15 +26,15 @@ module Urbanairship
36
26
 
37
27
  payload = {
38
28
  'channel': {
39
- 'address': @address,
40
- 'commercial_opted_in': @commercial_opted_in,
41
- 'commercial_opted_out': @commercial_opted_out,
42
- 'locale_country': @locale_country,
43
- 'locale_language': @locale_language,
44
- 'timezone': @timezone,
45
- 'transactional_opted_in': @transactional_opted_in,
46
- 'transactional_opted_out': @transactional_opted_out,
47
- 'type': @type
29
+ 'address': address,
30
+ 'commercial_opted_in': commercial_opted_in,
31
+ 'commercial_opted_out': commercial_opted_out,
32
+ 'locale_country': locale_country,
33
+ 'locale_language': locale_language,
34
+ 'timezone': timezone,
35
+ 'transactional_opted_in': transactional_opted_in,
36
+ 'transactional_opted_out': transactional_opted_out,
37
+ 'type': type
48
38
  }
49
39
  }
50
40
 
@@ -54,7 +44,7 @@ module Urbanairship
54
44
  url: CHANNEL_URL + 'email',
55
45
  content_type: 'application/json'
56
46
  )
57
- logger.info("Registering email channel with address #{@address}")
47
+ logger.info("Registering email channel with address #{address}")
58
48
  response
59
49
  end
60
50
 
@@ -62,7 +52,7 @@ module Urbanairship
62
52
  fail ArgumentError, 'address must be set to register email channel' if @address.nil?
63
53
 
64
54
  payload = {
65
- 'email_address': @address
55
+ 'email_address': address
66
56
  }
67
57
 
68
58
  response = @client.send_request(
@@ -71,7 +61,7 @@ module Urbanairship
71
61
  url: CHANNEL_URL + 'email/uninstall',
72
62
  content_type: 'application/json'
73
63
  )
74
- logger.info("Uninstalling email channel with address #{@address}")
64
+ logger.info("Uninstalling email channel with address #{address}")
75
65
  response
76
66
  end
77
67
 
@@ -80,32 +70,32 @@ module Urbanairship
80
70
 
81
71
  response = @client.send_request(
82
72
  method: 'GET',
83
- url: CHANNEL_URL + 'email/' + @address
73
+ url: CHANNEL_URL + 'email/' + address
84
74
  )
85
- logger.info("Looking up email channel with address #{@address}")
75
+ logger.info("Looking up email channel with address #{address}")
86
76
  response
87
77
  end
88
78
 
89
79
  def update
90
- fail ArgumentError, 'address must be set to update email channel' if @channel_id.nil?
91
-
92
- channel_data = {}
93
-
94
- channel_data['address'] = @address if @address
95
- channel_data['commercial_opted_in'] = @commercial_opted_in if @commercial_opted_in
96
- channel_data['commercial_opted_out'] = @commercial_opted_out if @commercial_opted_out
97
- channel_data['locale_country'] = @locale_country if @locale_country
98
- channel_data['locale_language'] = @locale_language if @locale_language
99
- channel_data['timezone'] = @timezone if @timezone
100
- channel_data['transactional_opted_in'] = @transactional_opted_in if @transactional_opted_in
101
- channel_data['transactional_opted_out'] = @transactional_opted_out if @transactional_opted_out
102
- channel_data['type'] = @type if @type
103
-
104
- payload = {channel: channel_data}
80
+ fail ArgumentError, 'address must be set to update email channel' if channel_id.nil?
81
+
82
+ channel_data = {
83
+ 'address': address,
84
+ 'commercial_opted_in': commercial_opted_in,
85
+ 'commercial_opted_out': commercial_opted_out,
86
+ 'localte_country': locale_country,
87
+ 'locale_language': locale_language,
88
+ 'timezone': timezone,
89
+ 'transactional_opted_in': transactional_opted_in,
90
+ 'transactional_opted_out': transactional_opted_out,
91
+ 'type': type
92
+ }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
93
+
94
+ payload = {'channel': channel_data}
105
95
 
106
96
  response = @client.send_request(
107
97
  method: 'PUT',
108
- url: CHANNEL_URL + 'email/' + @channel_id,
98
+ url: CHANNEL_URL + 'email/' + channel_id,
109
99
  body: JSON.dump(payload),
110
100
  content_type: 'application/json'
111
101
  )
@@ -16,21 +16,12 @@ module Urbanairship
16
16
  :sender_name,
17
17
  :subject,
18
18
  :template_id,
19
- :variable_details
19
+ :variable_details,
20
+ :click_tracking,
21
+ :open_tracking
20
22
 
21
23
  def initialize(client: required('client'))
22
24
  @client = client
23
- @bcc = nil
24
- @bypass_opt_in_level = nil
25
- @html_body = nil
26
- @message_type = nil
27
- @plaintext_body = nil
28
- @reply_to = nil
29
- @sender_address = nil
30
- @sender_name = nil
31
- @subject = nil
32
- @template_id = nil
33
- @variable_details = nil
34
25
  end
35
26
 
36
27
  def email_override
@@ -41,22 +32,21 @@ module Urbanairship
41
32
  fail ArgumentError, 'sender_name is needed for email override' if @sender_name.nil?
42
33
  fail ArgumentError, 'subject is needed for email override' if @subject.nil?
43
34
 
44
- override = {'email': {
45
- 'bypass_opt_in_level': @bypass_opt_in_level,
46
- 'html_body': @html_body,
47
- 'message_type': @message_type,
48
- 'plaintext_body': @plaintext_body,
49
- 'reply_to': @reply_to,
50
- 'sender_address': @sender_address,
51
- 'sender_name': @sender_name,
52
- 'subject': @subject
53
- }}
35
+ override = {
36
+ bcc: bcc,
37
+ bypass_opt_in_level: bypass_opt_in_level,
38
+ click_tracking: click_tracking,
39
+ html_body: html_body,
40
+ message_type: message_type,
41
+ open_tracking: open_tracking,
42
+ plaintext_body: plaintext_body,
43
+ reply_to: reply_to,
44
+ sender_address: sender_address,
45
+ sender_name: sender_name,
46
+ subject: subject
47
+ }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
54
48
 
55
- if @bcc
56
- override[:email][:bcc] = @bcc
57
- end
58
-
59
- override
49
+ {'email': override}
60
50
  end
61
51
 
62
52
  def email_with_inline_template
@@ -65,33 +55,29 @@ module Urbanairship
65
55
  fail ArgumentError, 'sender_address is needed for email with inline template' if @sender_address.nil?
66
56
  fail ArgumentError, 'sender_name is needed for email with inline template' if @sender_name.nil?
67
57
 
68
- inline_template = {'email': {
69
- 'message_type': @message_type,
70
- 'reply_to': @reply_to,
71
- 'sender_address': @sender_address,
72
- 'sender_name': @sender_name,
73
- 'template': {}
74
- }
75
- }
76
-
77
- if @subject and @plaintext_body
78
- fields_object = {'plaintext_body': @plaintext_body, 'subject': @subject}
79
- inline_template[:email][:template][:fields] = fields_object
80
- end
81
-
82
- if @bcc
83
- inline_template[:email][:bcc] = @bcc
84
- end
58
+ inline_template = {
59
+ bcc: bcc,
60
+ click_tracking: click_tracking,
61
+ message_type: message_type,
62
+ open_tracking: open_tracking,
63
+ reply_to: reply_to,
64
+ sender_address: sender_address,
65
+ sender_name: sender_name,
66
+ template: define_template_object
67
+ }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
85
68
 
86
- if @variable_details
87
- inline_template[:email][:template][:variable_details] = @variable_details
88
- end
89
-
90
- if @template_id
91
- inline_template[:email][:template][:template_id] = @template_id
92
- end
69
+ {'email': inline_template}
70
+ end
93
71
 
94
- inline_template
72
+ def define_template_object
73
+ template_portion = {
74
+ template_id: template_id,
75
+ fields: {
76
+ subject: subject,
77
+ plaintext_body: plaintext_body
78
+ },
79
+ variable_details: variable_details
80
+ }.delete_if {|key, value| value.nil?}
95
81
  end
96
82
 
97
83
  end
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Urbanairship
2
- VERSION = '5.5.1'
2
+ VERSION = '5.6.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.1
4
+ version: 5.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airship
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-04-14 00:00:00.000000000 Z
11
+ date: 2020-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client