urbanairship 5.5.0 → 5.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,52 @@
1
+ require 'urbanairship'
2
+
3
+ module Urbanairship
4
+ module Automations
5
+ class Pipeline
6
+ include Urbanairship::Common
7
+ include Urbanairship::Loggable
8
+ attr_accessor :activation_time,
9
+ :cancellation_trigger,
10
+ :condition,
11
+ :constraint,
12
+ :creation_time,
13
+ :deactivation_time,
14
+ :historical_trigger,
15
+ :immediate_trigger,
16
+ :last_modified_time,
17
+ :name,
18
+ :status,
19
+ :timing,
20
+ :url,
21
+ :enabled,
22
+ :outcome
23
+
24
+ def initialize(client: required('client'))
25
+ @client = client
26
+ end
27
+
28
+ def payload
29
+ fail ArgumentError, 'enabled must be set to create pipeline payload' if @enabled.nil?
30
+ fail ArgumentError, 'outcome must be set to create pipeline payload' if @outcome.nil?
31
+ {
32
+ activation_time: activation_time,
33
+ cancellation_trigger: cancellation_trigger,
34
+ condition: condition,
35
+ constraint: constraint,
36
+ creation_time: creation_time,
37
+ deactivation_time: deactivation_time,
38
+ enabled: enabled,
39
+ historical_trigger: historical_trigger,
40
+ immediate_trigger: immediate_trigger,
41
+ last_modified_time: last_modified_time,
42
+ name: name,
43
+ outcome: outcome,
44
+ status: status,
45
+ timing: timing,
46
+ url: url
47
+ }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -20,6 +20,7 @@ module Urbanairship
20
20
  FEEDS_URL = BASE_URL + '/feeds/'
21
21
  LOCATION_URL = BASE_URL + '/location/'
22
22
  CREATE_AND_SEND_URL = BASE_URL + '/create-and-send/'
23
+ EXPERIMENTS_URL = BASE_URL + '/experiments/'
23
24
 
24
25
  # Helper method for required keyword args in Ruby 2.0 that is compatible with 2.1+
25
26
  # @example
@@ -0,0 +1,54 @@
1
+ require 'urbanairship'
2
+
3
+ module Urbanairship
4
+ module Devices
5
+ class Attribute
6
+ include Urbanairship::Common
7
+ include Urbanairship::Loggable
8
+ attr_accessor :attribute,
9
+ :operator,
10
+ :precision,
11
+ :value
12
+
13
+ def initialize(client: required('client'))
14
+ @client = client
15
+ end
16
+
17
+ def payload
18
+ if precision
19
+ date_attribute
20
+ elsif value.is_a? String
21
+ text_attribute
22
+ elsif value.is_a? Integer
23
+ number_attribute
24
+ end
25
+ end
26
+
27
+ def number_attribute
28
+ {
29
+ 'attribute': attribute,
30
+ 'operator': operator,
31
+ 'value': value
32
+ }
33
+ end
34
+
35
+ def text_attribute
36
+ {
37
+ 'attribute': attribute,
38
+ 'operator': operator,
39
+ 'value': value
40
+ }
41
+ end
42
+
43
+ def date_attribute
44
+ {
45
+ 'attribute': attribute,
46
+ 'operator': operator,
47
+ 'precision': precision,
48
+ 'value': value
49
+ }
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -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
 
@@ -7,6 +7,8 @@ module Urbanairship
7
7
  include Urbanairship::Common
8
8
  include Urbanairship::Loggable
9
9
  attr_writer :client
10
+ attr_accessor :audience,
11
+ :attributes
10
12
 
11
13
  def initialize(client: required('client'))
12
14
  @client = client
@@ -20,6 +22,25 @@ module Urbanairship
20
22
  logger.info("Retrieved channel information for #{uuid}")
21
23
  response['body']['channel']
22
24
  end
25
+
26
+ def payload
27
+ {
28
+ 'audience': audience,
29
+ 'attributes': [
30
+ attributes
31
+ ]
32
+ }
33
+ end
34
+
35
+ def set_attributes
36
+ response = @client.send_request(
37
+ method: 'POST',
38
+ body: JSON.dump(payload),
39
+ url: CHANNEL_URL + 'attributes',
40
+ content_type: 'application/json'
41
+ )
42
+ response
43
+ end
23
44
  end
24
45
 
25
46
  class ChannelList < Urbanairship::Common::PageIterator
@@ -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,36 @@ 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
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
81
68
 
82
- if @bcc
83
- inline_template[:email][:bcc] = @bcc
84
- end
69
+ {'email': inline_template}
70
+ end
85
71
 
86
- if @variable_details
87
- inline_template[:email][:template][:variable_details] = @variable_details
88
- end
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
89
80
 
90
- if @template_id
91
- inline_template[:email][:template][:template_id] = @template_id
81
+ def define_fields
82
+ if subject && plaintext_body
83
+ {
84
+ subject: subject,
85
+ plaintext_body: plaintext_body
86
+ }
92
87
  end
93
-
94
- inline_template
95
88
  end
96
89
 
97
90
  end
@@ -19,41 +19,33 @@ 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
33
- unless @url[-4..-1] == '.jpg' || '.gif' || '.png' || 'jpeg'
25
+ unless ['.jpg', '.gif', '.png', 'jpeg'].include?(@url[-4..-1])
34
26
  fail ArgumentError, 'url must end in .gif, .jpg, .png, or .jpeg'
35
27
  end
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
  ]