urbanairship 5.6.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +30 -0
  3. data/README.rst +1 -0
  4. data/docs/ab_tests.rst +162 -0
  5. data/docs/attributes.rst +52 -0
  6. data/docs/automations.rst +212 -0
  7. data/docs/index.rst +3 -0
  8. data/docs/push.rst +24 -0
  9. data/docs/sms.rst +19 -0
  10. data/docs/static_lists.rst +2 -2
  11. data/lib/urbanairship.rb +12 -0
  12. data/lib/urbanairship/ab_tests/ab_test.rb +88 -0
  13. data/lib/urbanairship/ab_tests/experiment.rb +45 -0
  14. data/lib/urbanairship/ab_tests/variant.rb +34 -0
  15. data/lib/urbanairship/automations/automation.rb +105 -0
  16. data/lib/urbanairship/automations/pipeline.rb +52 -0
  17. data/lib/urbanairship/client.rb +22 -9
  18. data/lib/urbanairship/common.rb +63 -16
  19. data/lib/urbanairship/configuration.rb +2 -1
  20. data/lib/urbanairship/custom_events/custom_event.rb +60 -0
  21. data/lib/urbanairship/custom_events/payload.rb +89 -0
  22. data/lib/urbanairship/devices/attribute.rb +54 -0
  23. data/lib/urbanairship/devices/channel_tags.rb +1 -1
  24. data/lib/urbanairship/devices/channel_uninstall.rb +10 -10
  25. data/lib/urbanairship/devices/create_and_send.rb +4 -4
  26. data/lib/urbanairship/devices/devicelist.rb +28 -7
  27. data/lib/urbanairship/devices/email.rb +5 -5
  28. data/lib/urbanairship/devices/email_notification.rb +11 -4
  29. data/lib/urbanairship/devices/named_user.rb +6 -6
  30. data/lib/urbanairship/devices/open_channel.rb +22 -23
  31. data/lib/urbanairship/devices/segment.rb +5 -5
  32. data/lib/urbanairship/devices/sms.rb +40 -9
  33. data/lib/urbanairship/devices/static_lists.rb +12 -12
  34. data/lib/urbanairship/push/location.rb +7 -7
  35. data/lib/urbanairship/push/push.rb +23 -13
  36. data/lib/urbanairship/push/schedule.rb +9 -0
  37. data/lib/urbanairship/reports/response_statistics.rb +9 -9
  38. data/lib/urbanairship/version.rb +1 -1
  39. metadata +16 -5
data/docs/index.rst CHANGED
@@ -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
data/docs/push.rst CHANGED
@@ -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
  --------------------------------
data/docs/sms.rst CHANGED
@@ -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
data/lib/urbanairship.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'urbanairship/custom_events/payload'
1
2
  require 'urbanairship/push/audience'
2
3
  require 'urbanairship/push/payload'
3
4
  require 'urbanairship/push/schedule'
@@ -10,6 +11,7 @@ require 'urbanairship/devices/email_notification'
10
11
  require 'urbanairship/devices/sms_notification'
11
12
  require 'urbanairship/devices/mms_notification'
12
13
  require 'urbanairship/devices/create_and_send'
14
+ require 'urbanairship/devices/attribute'
13
15
  require 'urbanairship/client'
14
16
  require 'urbanairship/common'
15
17
  require 'urbanairship/configuration'
@@ -23,15 +25,25 @@ require 'urbanairship/devices/open_channel'
23
25
  require 'urbanairship/reports/response_statistics'
24
26
  require 'urbanairship/devices/static_lists'
25
27
  require 'urbanairship/push/location'
28
+ require 'urbanairship/automations/pipeline'
29
+ require 'urbanairship/automations/automation'
30
+ require 'urbanairship/ab_tests/variant'
31
+ require 'urbanairship/ab_tests/experiment'
32
+ require 'urbanairship/ab_tests/ab_test'
26
33
 
27
34
  module Urbanairship
35
+ extend Urbanairship::CustomEvents::Payload
36
+ extend Urbanairship::CustomEvents
28
37
  extend Urbanairship::Push::Audience
29
38
  extend Urbanairship::Push::Payload
30
39
  extend Urbanairship::Push::Schedule
31
40
  extend Urbanairship::Push
41
+ include Urbanairship::CustomEvents
32
42
  include Urbanairship::Devices
33
43
  include Urbanairship::Reports
34
44
  include Urbanairship::Push
45
+ include Urbanairship::Automations
46
+ include Urbanairship::AbTests
35
47
 
36
48
  class << self
37
49
  attr_accessor :configuration
@@ -0,0 +1,88 @@
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
@@ -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
@@ -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