urbanairship 5.3.0 → 5.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,12 +37,12 @@ Complex audience with platform specifics
37
37
  )
38
38
  push.notification = UA.notification(
39
39
  ios: UA.ios(
40
- alert: "Kim Jong-Un wins U.S. Open",
40
+ alert: "Serena Williams wins U.S. Open",
41
41
  badge: "+1",
42
42
  extra: {"articleid" => "123456"}
43
43
  ),
44
44
  android: UA.android(
45
- alert: "Breaking Android News! Glorious Leader Kim Jong-Un wins U.S. Open!",
45
+ alert: "Breaking Android News! Serena Williams wins U.S. Open!",
46
46
  extra: {"articleid" => "http://m.example.com/123456"}
47
47
  ),
48
48
  amazon: UA.amazon(
@@ -64,7 +64,7 @@ Single iOS push
64
64
  push = airship.create_push
65
65
  push.audience = UA.ios_channel('channel-id')
66
66
  push.notification = UA.notification(
67
- ios: UA.ios(alert="Kim Jong-Un is following you on Twitter")
67
+ ios: UA.ios(alert="Your package is on its way!")
68
68
  )
69
69
  push.device_types = UA.device_types(['ios'])
70
70
  push.send_push
@@ -78,10 +78,10 @@ Single iOS Rich Push with notification
78
78
  push = airship.create_push
79
79
  push.audience = UA.ios_channel('channel-id')
80
80
  push.notification = UA.notification(
81
- ios: UA.ios(alert="Kim Jong-Un is following you on Twitter")
81
+ ios: UA.ios(alert="Your package is on its way!")
82
82
  )
83
83
  push.device_types = UA.device_types(['ios'])
84
- push.message = UA.message(title: "New follower", body: "<h1>OMG It's Kim Jong-Un</h1>")
84
+ push.message = UA.message(title: "Your package is on the way!", body: "<h1>Please complete our survey</h1>")
85
85
  push.send_push
86
86
 
87
87
 
@@ -94,8 +94,8 @@ Rich Push with extra and without notification
94
94
  push.audience = UA.all
95
95
  push.device_types = UA.all
96
96
  push.message = UA.message(
97
- title: "New follower",
98
- body: "<h1>OMG It's Kim Jong-Un</h1>",
97
+ title: "Your package is on its way!",
98
+ body: "<h1>Would you please complete our customer survey?</h1>",
99
99
  extra: {"articleid" => "http://m.example.com/123456"}
100
100
  )
101
101
  push.send_push
@@ -112,7 +112,7 @@ Scheduled iOS Push
112
112
  sched.push = airship.create_push
113
113
  sched.push.audience = UA.ios_channel('channel-id')
114
114
  sched.push.notification = UA.notification(
115
- ios: UA.ios(alert: "Kim Jong-Un is following you on Twitter"))
115
+ ios: UA.ios(alert: "Your package is on its way!"))
116
116
  sched.push.device_types = UA.device_types(['ios'])
117
117
 
118
118
  sched.send_push
@@ -69,6 +69,10 @@ Contents:
69
69
  location.rst
70
70
  exceptions.rst
71
71
  examples.rst
72
+ create_and_send.rst
73
+ email.rst
74
+ open_channels.rst
75
+ sms.rst
72
76
 
73
77
 
74
78
  Indices and tables
@@ -6,6 +6,10 @@ require 'urbanairship/devices/segment'
6
6
  require 'urbanairship/devices/channel_uninstall'
7
7
  require 'urbanairship/devices/sms'
8
8
  require 'urbanairship/devices/email'
9
+ require 'urbanairship/devices/email_notification'
10
+ require 'urbanairship/devices/sms_notification'
11
+ require 'urbanairship/devices/mms_notification'
12
+ require 'urbanairship/devices/create_and_send'
9
13
  require 'urbanairship/client'
10
14
  require 'urbanairship/common'
11
15
  require 'urbanairship/configuration'
@@ -4,8 +4,8 @@ require 'urbanairship/loggable'
4
4
  module Urbanairship
5
5
  # Features mixed in to all classes
6
6
  module Common
7
- SERVER = 'go.airship.com'
8
- BASE_URL = 'https://go.airship.com/api'
7
+ SERVER = 'go.urbanairship.com'
8
+ BASE_URL = 'https://go.urbanairship.com/api'
9
9
  CHANNEL_URL = BASE_URL + '/channels/'
10
10
  OPEN_CHANNEL_URL = BASE_URL + '/channels/open/'
11
11
  DEVICE_TOKEN_URL = BASE_URL + '/device_tokens/'
@@ -19,6 +19,7 @@ module Urbanairship
19
19
  PIPELINES_URL = BASE_URL + '/pipelines/'
20
20
  FEEDS_URL = BASE_URL + '/feeds/'
21
21
  LOCATION_URL = BASE_URL + '/location/'
22
+ CREATE_AND_SEND_URL = BASE_URL + '/create-and-send/'
22
23
 
23
24
  # Helper method for required keyword args in Ruby 2.0 that is compatible with 2.1+
24
25
  # @example
@@ -0,0 +1,96 @@
1
+ require 'urbanairship'
2
+ require 'urbanairship/devices/email_notification'
3
+
4
+ module Urbanairship
5
+ module Devices
6
+ class CreateAndSend
7
+ include Urbanairship::Common
8
+ include Urbanairship::Loggable
9
+ attr_accessor :addresses,
10
+ :device_types,
11
+ :notification,
12
+ :campaigns,
13
+ :name,
14
+ :scheduled_time
15
+
16
+ def initialize(client: required('client'))
17
+ @client = client
18
+ end
19
+
20
+ def validate_address
21
+ @addresses.each do |address|
22
+ unless address.include?(:ua_address) or address.include?(:ua_msisdn && :ua_opted_in && :ua_sender)
23
+ fail ArgumentError, 'Missing a component in address portion of the object'
24
+ end
25
+ end
26
+ end
27
+
28
+ def payload
29
+ fail ArgumentError, 'addresses must be set for defining payload' if @addresses.nil?
30
+ fail ArgumentError, 'device type array must be set for defining payload' if @device_types.nil?
31
+ fail ArgumentError, 'notification object must be set for defining payload' if @notification.nil?
32
+
33
+ validate_address
34
+
35
+ full_payload = {
36
+ 'audience': {
37
+ 'create_and_send': addresses
38
+ },
39
+ 'device_types': device_types,
40
+ 'notification': notification,
41
+ }
42
+
43
+ if campaigns
44
+ campaign_object = {'categories': campaigns}
45
+ full_payload[:campaigns] = campaign_object
46
+ end
47
+
48
+ full_payload
49
+ end
50
+
51
+ def create_and_send
52
+ response = @client.send_request(
53
+ method: 'POST',
54
+ body: JSON.dump(payload),
55
+ url: CREATE_AND_SEND_URL,
56
+ content_type: 'application/json'
57
+ )
58
+ logger.info("Running create and send for addresses #{@addresses}")
59
+ response
60
+ end
61
+
62
+ def validate
63
+ response = @client.send_request(
64
+ method: 'POST',
65
+ body: JSON.dump(payload),
66
+ url: CREATE_AND_SEND_URL + 'validate',
67
+ content_type: 'application/json'
68
+ )
69
+ logger.info("Validating payload for create and send")
70
+ response
71
+ end
72
+
73
+ def schedule
74
+ fail ArgumentError, 'scheduled time must be set to run an operation' if @scheduled_time.nil?
75
+
76
+ scheduled_payload = {
77
+ "schedule": {
78
+ "scheduled_time": scheduled_time
79
+ },
80
+ "name": name,
81
+ "push": payload
82
+ }
83
+
84
+ response = @client.send_request(
85
+ method: 'POST',
86
+ body: JSON.dump(scheduled_payload),
87
+ url: SCHEDULES_URL + 'create-and-send',
88
+ content_type: 'application/json'
89
+ )
90
+ logger.info("Scheduling create and send operation with name #{@name}")
91
+ response
92
+ end
93
+
94
+ end
95
+ end
96
+ end
@@ -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
  )
@@ -0,0 +1,92 @@
1
+ require 'urbanairship'
2
+ require 'json'
3
+
4
+ module Urbanairship
5
+ module Devices
6
+ class EmailNotification
7
+ include Urbanairship::Common
8
+ include Urbanairship::Loggable
9
+ attr_accessor :bcc,
10
+ :bypass_opt_in_level,
11
+ :html_body,
12
+ :message_type,
13
+ :plaintext_body,
14
+ :reply_to,
15
+ :sender_address,
16
+ :sender_name,
17
+ :subject,
18
+ :template_id,
19
+ :variable_details,
20
+ :click_tracking,
21
+ :open_tracking
22
+
23
+ def initialize(client: required('client'))
24
+ @client = client
25
+ end
26
+
27
+ def email_override
28
+ fail ArgumentError, 'message_type is needed for email override' if @message_type.nil?
29
+ fail ArgumentError, 'plaintext_body is needed for email override' if @plaintext_body.nil?
30
+ fail ArgumentError, 'reply_to is needed for email override' if @reply_to.nil?
31
+ fail ArgumentError, 'sender_address is needed for email override' if @sender_address.nil?
32
+ fail ArgumentError, 'sender_name is needed for email override' if @sender_name.nil?
33
+ fail ArgumentError, 'subject is needed for email override' if @subject.nil?
34
+
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
48
+
49
+ {'email': override}
50
+ end
51
+
52
+ def email_with_inline_template
53
+ fail ArgumentError, 'message_type is needed for email with inline template' if @message_type.nil?
54
+ fail ArgumentError, 'reply_to is needed for email with inline template' if @reply_to.nil?
55
+ fail ArgumentError, 'sender_address is needed for email with inline template' if @sender_address.nil?
56
+ fail ArgumentError, 'sender_name is needed for email with inline template' if @sender_name.nil?
57
+
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
68
+
69
+ {'email': inline_template}
70
+ end
71
+
72
+ def define_template_object
73
+ fail ArgumentError, 'Must choose between template_id or fields object' if template_id && plaintext_body && subject
74
+ template_portion = {
75
+ template_id: template_id,
76
+ fields: define_fields,
77
+ variable_details: variable_details
78
+ }.delete_if {|key, value| value.nil?}
79
+ end
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
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,107 @@
1
+ require 'urbanairship'
2
+ require 'json'
3
+
4
+ module Urbanairship
5
+ module Devices
6
+ class MmsNotification
7
+ include Urbanairship::Common
8
+ include Urbanairship::Loggable
9
+
10
+ attr_accessor :fallback_text,
11
+ :shorten_links,
12
+ :content_length,
13
+ :content_type,
14
+ :url,
15
+ :text,
16
+ :subject,
17
+ :template_id,
18
+ :slide_1_text
19
+
20
+ def initialize(client: required('client'))
21
+ @client = client
22
+ end
23
+
24
+ def validate_url
25
+ unless ['.jpg', '.gif', '.png', 'jpeg'].include?(@url[-4..-1])
26
+ fail ArgumentError, 'url must end in .gif, .jpg, .png, or .jpeg'
27
+ end
28
+ end
29
+
30
+ def mms_override
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?
35
+
36
+ validate_url
37
+
38
+ override = {"mms": {
39
+ "subject": subject,
40
+ "fallback_text": fallback_text,
41
+ "shorten_links": shorten_links,
42
+ "slides": [
43
+ {
44
+ "text": text,
45
+ "media": {
46
+ "url": url,
47
+ "content_type": content_type,
48
+ "content_length": content_length
49
+ }
50
+ }
51
+ ]
52
+ }
53
+ }
54
+ override
55
+ end
56
+
57
+ def mms_template_with_id
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?
62
+
63
+ {"mms": {
64
+ "template": {
65
+ "template_id": template_id
66
+ },
67
+ "shorten_links": true,
68
+ "slides": [
69
+ {
70
+ "media": {
71
+ "url": url,
72
+ "content_type": content_type,
73
+ "content_length": content_length
74
+ }
75
+ }
76
+ ]
77
+ }
78
+ }
79
+ end
80
+
81
+ def mms_inline_template
82
+ fail ArgumentError, 'slide_1_text text is needed for MMS with inline template' if text.nil?
83
+
84
+ {"mms": {
85
+ "template": {
86
+ "fields": {
87
+ "subject": subject,
88
+ "fallback_text": fallback_text,
89
+ "slide_1_text": text
90
+ }
91
+ },
92
+ "slides": [
93
+ {
94
+ "media": {
95
+ "url": url,
96
+ "content_type": content_type,
97
+ "content_length": content_length
98
+ }
99
+ }
100
+ ]
101
+ }
102
+ }
103
+ end
104
+
105
+ end
106
+ end
107
+ end