urbanairship 5.5.1 → 5.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -73,6 +73,9 @@ Contents:
73
73
  email.rst
74
74
  open_channels.rst
75
75
  sms.rst
76
+ automations.rst
77
+ ab_tests.rst
78
+ attributes.rst
76
79
 
77
80
 
78
81
  Indices and tables
@@ -507,6 +507,30 @@ local time.
507
507
  If the schedule is unsuccessful, an :rb:class:`AirshipFailure` exception
508
508
  will be raised.
509
509
 
510
+ Scheduled Delivery for Optimal Send Time
511
+ ----------------------------------------
512
+
513
+ Scheduled notifications build upon the Push object, and have two other
514
+ components: the scheduled time(s) and an optional name.
515
+
516
+ This example schedules the above notification delivery for optimal send time.
517
+
518
+ .. code-block:: ruby
519
+
520
+ schedule = airship.create_scheduled_push
521
+ schedule.push = push
522
+ schedule.name = "optional name for later reference"
523
+ schedule.schedule = UA.optimal_scheduled_time('2020-02-20')
524
+ response = schedule.send_push
525
+ print ("Created schedule. url: " + response.schedule_url)
526
+
527
+ If the schedule is unsuccessful, an :rb:class:`AirshipFailure` exception
528
+ will be raised.
529
+
530
+ .. note::
531
+
532
+ Make sure the time for UA.optimal_scheduled_time is a date versus a timestamp.
533
+
510
534
 
511
535
  Updating or Canceling a Schedule
512
536
  --------------------------------
@@ -21,6 +21,25 @@ request with an opted_in key.
21
21
  sms_channel.opted_in = '2018-02-13T11:58:59'
22
22
  sms_channel.register
23
23
 
24
+ Update SMS Channel
25
+ -------------------
26
+
27
+ To update an SMS channel you need a sender, MSISDN, and a channel ID.
28
+
29
+ .. code-block:: ruby
30
+
31
+ require 'urbanairship'
32
+ UA = Urbanairship
33
+ airship = UA::Client.new(key:'application_key', secret:'master_secret')
34
+ sms_channel = UA::Sms.new(client: airship)
35
+ sms_channel.msisdn = '15035556789'
36
+ sms_channel.sender = '12345'
37
+ sms_channel.opted_in = '2020-12-14T11:58:59'
38
+ sms_channel.timezone = 'America/Denver'
39
+ sms_channel.channel_id = 'a1b2c3d4e5f6'
40
+ sms_channel.update
41
+
42
+
24
43
  Opt-Out of SMS Messages
25
44
  -----------------------
26
45
 
@@ -28,7 +28,7 @@ string keys to arbitrary JSON values.
28
28
  airship = UA::Client.new(key:'application_key', secret:'master_secret')
29
29
  static_list = UA::StaticList.new(client: airship)
30
30
  static_list.name = 'list_name'
31
- static_list.create(description: 'description', extras: { 'key' => 'value' })
31
+ static_list.create(description: 'description', extra: {'key': 'value'})
32
32
 
33
33
 
34
34
  Upload List
@@ -71,7 +71,7 @@ Updates the metadata of a static list.
71
71
  airship = UA::Client.new(key:'application_key', secret:'master_secret')
72
72
  static_list = UA::StaticList.new(client: airship)
73
73
  static_list.name = 'list_name'
74
- static_list.update(description: 'description', { 'key' => 'value' })
74
+ static_list.update(description: 'new description', 'extra': {'new_key': 'new_value' })
75
75
 
76
76
 
77
77
  Delete List
@@ -10,6 +10,7 @@ require 'urbanairship/devices/email_notification'
10
10
  require 'urbanairship/devices/sms_notification'
11
11
  require 'urbanairship/devices/mms_notification'
12
12
  require 'urbanairship/devices/create_and_send'
13
+ require 'urbanairship/devices/attribute'
13
14
  require 'urbanairship/client'
14
15
  require 'urbanairship/common'
15
16
  require 'urbanairship/configuration'
@@ -23,6 +24,11 @@ require 'urbanairship/devices/open_channel'
23
24
  require 'urbanairship/reports/response_statistics'
24
25
  require 'urbanairship/devices/static_lists'
25
26
  require 'urbanairship/push/location'
27
+ require 'urbanairship/automations/pipeline'
28
+ require 'urbanairship/automations/automation'
29
+ require 'urbanairship/ab_tests/variant'
30
+ require 'urbanairship/ab_tests/experiment'
31
+ require 'urbanairship/ab_tests/ab_test'
26
32
 
27
33
  module Urbanairship
28
34
  extend Urbanairship::Push::Audience
@@ -32,6 +38,8 @@ module Urbanairship
32
38
  include Urbanairship::Devices
33
39
  include Urbanairship::Reports
34
40
  include Urbanairship::Push
41
+ include Urbanairship::Automations
42
+ include Urbanairship::AbTests
35
43
 
36
44
  class << self
37
45
  attr_accessor :configuration
@@ -0,0 +1,89 @@
1
+ require 'uri'
2
+ require 'urbanairship'
3
+ require 'urbanairship/ab_tests/experiment'
4
+
5
+ module Urbanairship
6
+ module AbTests
7
+ class AbTest
8
+ include Urbanairship::Common
9
+ include Urbanairship::Loggable
10
+ attr_accessor :limit,
11
+ :offset,
12
+ :experiment_object,
13
+ :experiment_id
14
+
15
+ def initialize(client: required('client'))
16
+ @client = client
17
+ end
18
+
19
+ def list_ab_test
20
+ response = @client.send_request(
21
+ method: 'GET',
22
+ url: EXPERIMENTS_URL + format_url_with_params
23
+ )
24
+ logger.info("Looking up A/B Tests for project")
25
+ response
26
+ end
27
+
28
+ def create_ab_test
29
+ response = @client.send_request(
30
+ method: 'POST',
31
+ body: JSON.dump(experiment_object),
32
+ url: EXPERIMENTS_URL,
33
+ content_type: 'application/json'
34
+ )
35
+ logger.info("Created A/B Test")
36
+ response
37
+ end
38
+
39
+ def list_scheduled_ab_test
40
+ response = @client.send_request(
41
+ method: 'GET',
42
+ url: EXPERIMENTS_URL + 'scheduled' + format_url_with_params
43
+ )
44
+ logger.info("Looking up scheduled A/B Tests for project")
45
+ response
46
+ end
47
+
48
+ def delete_ab_test
49
+ fail ArgumentError, 'experiment_id must be set to delete individual A/B test' if @experiment_id.nil?
50
+ response = @client.send_request(
51
+ method: 'DELETE',
52
+ url: EXPERIMENTS_URL + 'scheduled/' + experiment_id
53
+ )
54
+ logger.info("Deleting A/B test with ID #{experiment_id}")
55
+ response
56
+ end
57
+
58
+ def validate_ab_test
59
+ response = @client.send_request(
60
+ method: 'POST',
61
+ body: JSON.dump(experiment_object),
62
+ url: EXPERIMENTS_URL + 'validate',
63
+ content_type: 'application/json'
64
+ )
65
+ logger.info("Validating A/B Test")
66
+ response
67
+ end
68
+
69
+ def lookup_ab_test
70
+ fail ArgumentError, 'experiment_id must be set to lookup individual A/B Test' if @experiment_id.nil?
71
+ response = @client.send_request(
72
+ method: 'GET',
73
+ url: EXPERIMENTS_URL + experiment_id
74
+ )
75
+ logger.info("Looking up A/B test with ID #{experiment_id}")
76
+ response
77
+ end
78
+
79
+ def format_url_with_params
80
+ params = []
81
+ params << ['limit', limit] if limit
82
+ params << ['offset', offset] if offset
83
+ query = URI.encode_www_form(params)
84
+ '?' + query
85
+ end
86
+ end
87
+ end
88
+ end
89
+
@@ -0,0 +1,45 @@
1
+ require 'urbanairship'
2
+
3
+ module Urbanairship
4
+ module AbTests
5
+ class Experiment
6
+ include Urbanairship::Common
7
+ include Urbanairship::Loggable
8
+ attr_accessor :audience,
9
+ :campaigns,
10
+ :control,
11
+ :created_at,
12
+ :description,
13
+ :device_types,
14
+ :id,
15
+ :name,
16
+ :push_id,
17
+ :variants
18
+
19
+ def initialize(client: required('client'))
20
+ @client = client
21
+ @variants = []
22
+ end
23
+
24
+ def payload
25
+ fail ArgumentError, 'audience is required for experiment' if @audience.nil?
26
+ fail ArgumentError, 'device_types is required for experiment' if @device_types.nil?
27
+ fail ArgumentError, 'variant cannot be empty for experiment' if @variants.empty?
28
+
29
+ {
30
+ 'name': name,
31
+ 'description': description,
32
+ 'control': control,
33
+ 'audience': audience,
34
+ 'device_types': device_types,
35
+ 'campaigns': campaigns,
36
+ 'variants': variants,
37
+ 'id': id,
38
+ 'created_at': created_at,
39
+ 'push_id': push_id
40
+ }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,34 @@
1
+ require 'urbanairship'
2
+
3
+ module Urbanairship
4
+ module AbTests
5
+ class Variant
6
+ include Urbanairship::Common
7
+ include Urbanairship::Loggable
8
+ attr_accessor :description,
9
+ :id,
10
+ :name,
11
+ :push,
12
+ :schedule,
13
+ :weight
14
+
15
+ def initialize(client: required('client'))
16
+ @client = client
17
+ end
18
+
19
+ def payload
20
+ fail ArgumentError, 'a push must be added to create a variant' if @push.nil?
21
+
22
+ {
23
+ 'description': description,
24
+ 'id': id,
25
+ 'name': name,
26
+ 'push': push,
27
+ 'schedule': schedule,
28
+ 'weight': weight
29
+ }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,105 @@
1
+ require 'uri'
2
+ require 'urbanairship'
3
+ require 'urbanairship/automations/pipeline'
4
+
5
+ module Urbanairship
6
+ module Automations
7
+ class Automation
8
+ include Urbanairship::Common
9
+ include Urbanairship::Loggable
10
+ attr_accessor :limit,
11
+ :enabled,
12
+ :offset,
13
+ :start,
14
+ :pipeline_id,
15
+ :pipeline_object
16
+
17
+ def initialize(client: required('client'))
18
+ @client = client
19
+ end
20
+
21
+ def create_automation
22
+ response = @client.send_request(
23
+ method: 'POST',
24
+ body: JSON.dump(pipeline_object),
25
+ url: PIPELINES_URL,
26
+ content_type: 'application/json'
27
+ )
28
+ logger.info("Created Automation")
29
+ response
30
+ end
31
+
32
+ def list_automations
33
+ response = @client.send_request(
34
+ method: 'GET',
35
+ url: PIPELINES_URL + format_url_with_params
36
+ )
37
+ logger.info("Looking up automations for project")
38
+ response
39
+ end
40
+
41
+ def list_deleted_automations
42
+ response = @client.send_request(
43
+ method: 'GET',
44
+ url: PIPELINES_URL + 'deleted' + format_url_with_params
45
+ )
46
+ logger.info("Looking up deleted automations for project")
47
+ response
48
+ end
49
+
50
+ def validate_automation
51
+ response = @client.send_request(
52
+ method: 'POST',
53
+ body: JSON.dump(pipeline_object),
54
+ url: PIPELINES_URL + 'validate',
55
+ content_type: 'application/json'
56
+ )
57
+ logger.info("Validating Automation")
58
+ response
59
+ end
60
+
61
+ def lookup_automation
62
+ fail ArgumentError, 'pipeline_id must be set to lookup individual automation' if @pipeline_id.nil?
63
+ response = @client.send_request(
64
+ method: 'GET',
65
+ url: PIPELINES_URL + pipeline_id
66
+ )
67
+ logger.info("Looking up automation with id #{pipeline_id}")
68
+ response
69
+ end
70
+
71
+ def update_automation
72
+ fail ArgumentError, 'pipeline_id must be set to update individual automation' if @pipeline_id.nil?
73
+
74
+ response = @client.send_request(
75
+ method: 'PUT',
76
+ body: JSON.dump(pipeline_object),
77
+ url: PIPELINES_URL + pipeline_id,
78
+ content_type: 'application/json'
79
+ )
80
+ logger.info("Validating Automation")
81
+ response
82
+ end
83
+
84
+ def delete_automation
85
+ fail ArgumentError, 'pipeline_id must be set to delete individual automation' if @pipeline_id.nil?
86
+ response = @client.send_request(
87
+ method: 'DELETE',
88
+ url: PIPELINES_URL + pipeline_id
89
+ )
90
+ logger.info("Deleting automation with id #{pipeline_id}")
91
+ response
92
+ end
93
+
94
+ def format_url_with_params
95
+ params = []
96
+ params << ['limit', limit] if limit
97
+ params << ['enabled', enabled] if enabled
98
+ params << ['offset', offset] if offset
99
+ params << ['start', start] if start
100
+ query = URI.encode_www_form(params)
101
+ '?' + query
102
+ end
103
+ end
104
+ end
105
+ end