urbanairship 5.7.0 → 8.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.github/PULL_REQUEST_TEMPLATE.md +2 -2
  3. data/.travis.yml +2 -2
  4. data/CHANGELOG +33 -0
  5. data/README.rst +95 -38
  6. data/docs/attributes.rst +73 -0
  7. data/docs/index.rst +3 -0
  8. data/docs/named_user.rst +22 -0
  9. data/docs/push.rst +24 -0
  10. data/docs/sms.rst +19 -0
  11. data/docs/static_lists.rst +2 -2
  12. data/lib/urbanairship.rb +7 -0
  13. data/lib/urbanairship/ab_tests/ab_test.rb +8 -9
  14. data/lib/urbanairship/automations/automation.rb +11 -11
  15. data/lib/urbanairship/client.rb +34 -12
  16. data/lib/urbanairship/common.rb +110 -43
  17. data/lib/urbanairship/configuration.rb +2 -1
  18. data/lib/urbanairship/custom_events/custom_event.rb +60 -0
  19. data/lib/urbanairship/custom_events/payload.rb +89 -0
  20. data/lib/urbanairship/devices/attribute.rb +54 -0
  21. data/lib/urbanairship/devices/attributes.rb +53 -0
  22. data/lib/urbanairship/devices/channel_tags.rb +2 -2
  23. data/lib/urbanairship/devices/channel_uninstall.rb +10 -10
  24. data/lib/urbanairship/devices/create_and_send.rb +4 -4
  25. data/lib/urbanairship/devices/devicelist.rb +28 -7
  26. data/lib/urbanairship/devices/email.rb +5 -5
  27. data/lib/urbanairship/devices/named_user.rb +22 -12
  28. data/lib/urbanairship/devices/open_channel.rb +22 -23
  29. data/lib/urbanairship/devices/segment.rb +6 -8
  30. data/lib/urbanairship/devices/sms.rb +40 -9
  31. data/lib/urbanairship/devices/static_lists.rb +12 -12
  32. data/lib/urbanairship/push/location.rb +18 -18
  33. data/lib/urbanairship/push/push.rb +5 -5
  34. data/lib/urbanairship/push/schedule.rb +9 -0
  35. data/lib/urbanairship/reports/response_statistics.rb +42 -31
  36. data/lib/urbanairship/version.rb +1 -1
  37. data/urbanairship.gemspec +1 -0
  38. metadata +25 -6
@@ -10,7 +10,7 @@ module Urbanairship
10
10
  class Push
11
11
  attr_writer :client
12
12
 
13
- attr_accessor :device_types,
13
+ attr_accessor :device_types,
14
14
  :audience,
15
15
  :notification,
16
16
  :options,
@@ -52,7 +52,7 @@ module Urbanairship
52
52
  response = @client.send_request(
53
53
  method: 'POST',
54
54
  body: JSON.dump(payload),
55
- url: PUSH_URL,
55
+ path: push_path,
56
56
  content_type: 'application/json'
57
57
  )
58
58
  pr = PushResponse.new(http_response_body: response['body'], http_response_code: response['code'].to_s)
@@ -93,7 +93,7 @@ module Urbanairship
93
93
  response = @client.send_request(
94
94
  method: 'POST',
95
95
  body: JSON.dump(payload),
96
- url: SCHEDULES_URL,
96
+ path: schedules_path,
97
97
  content_type: 'application/json'
98
98
  )
99
99
  pr = PushResponse.new(http_response_body: response['body'], http_response_code: response['code'].to_s)
@@ -170,7 +170,7 @@ module Urbanairship
170
170
  'schedule_id must be a string' unless schedule_id.is_a? String
171
171
  resp = @client.send_request(
172
172
  method: 'GET',
173
- url: SCHEDULES_URL + schedule_id
173
+ path: schedules_path(schedule_id)
174
174
  )
175
175
  logger.info("Retrieved info for schedule_id #{schedule_id}")
176
176
  resp
@@ -181,7 +181,7 @@ module Urbanairship
181
181
  class ScheduledPushList < Urbanairship::Common::PageIterator
182
182
  def initialize(client: required('client'))
183
183
  super(client: client)
184
- @next_page = SCHEDULES_URL
184
+ @next_page_path = schedules_path
185
185
  @data_attribute = 'schedules'
186
186
  end
187
187
  end
@@ -14,6 +14,15 @@ module Urbanairship
14
14
  payload(:local_scheduled_time, datetime)
15
15
  end
16
16
 
17
+ # Uses predictive analysis to send push at optimal time
18
+ def optimal_scheduled_time(date)
19
+ {
20
+ 'best_time': {
21
+ 'send_date': date
22
+ }
23
+ }
24
+ end
25
+
17
26
  private
18
27
 
19
28
  def payload(name, time)
@@ -4,22 +4,33 @@ require 'time'
4
4
  module Urbanairship
5
5
  module Reports
6
6
  class Helper
7
- def get_url(start_date, end_date, precision)
8
- fail ArgumentError,
9
- 'the parameters cannot be set to nil' if start_date.nil? or end_date.nil? or precision.nil?
10
- precision_array = %w(HOURLY DAILY MONTHLY)
11
- fail ArgumentError,
12
- "Precision must be 'HOURLY', 'DAILY', or 'MONTHLY'" unless precision_array.include?(precision)
7
+ def get_period_params(start_date, end_date, precision)
8
+ validates_parameters_presence!(start_date, end_date, precision)
9
+ validates_precision_format!(precision)
13
10
 
14
11
  begin
15
- start_parsed = Time.parse(start_date)
16
- end_parsed = Time.parse(end_date)
12
+ start_parsed = Time.parse(start_date).iso8601
13
+ end_parsed = Time.parse(end_date).iso8601
14
+
15
+ "?start=#{start_parsed}&end=#{end_parsed}&precision=#{precision}"
17
16
  rescue ArgumentError
18
- fail ArgumentError,
19
- 'start_date and end_date must be valid date strings'
17
+ fail ArgumentError, 'start_date and end_date must be valid date strings'
20
18
  end
21
- url = '?start=' + start_parsed.iso8601 + '&end=' + end_parsed.iso8601
22
- url += '&precision=' + precision
19
+ end
20
+
21
+ private
22
+
23
+ def validates_parameters_presence!(start_date, end_date, precision)
24
+ return unless [start_date, end_date, precision].any?(&:nil?)
25
+
26
+ fail ArgumentError, 'the parameters cannot be set to nil'
27
+ end
28
+
29
+ AUTHORIZED_PRECISIONS = %w(HOURLY DAILY MONTHLY)
30
+ def validates_precision_format!(precision)
31
+ return if AUTHORIZED_PRECISIONS.include?(precision)
32
+
33
+ fail ArgumentError, 'Precision must be "HOURLY", "DAILY", or "MONTHLY"'
23
34
  end
24
35
  end
25
36
 
@@ -35,8 +46,8 @@ module Urbanairship
35
46
  fail ArgumentError,
36
47
  'push_id cannot be nil' if push_id.nil?
37
48
 
38
- url = REPORTS_URL + 'responses/' + push_id
39
- response = @client.send_request(method: 'GET', url: url)
49
+ path = reports_path('responses/' + push_id)
50
+ response = @client.send_request(method: 'GET', path: path)
40
51
  logger.info("Retrieved info on push_id: #{push_id}")
41
52
  response
42
53
  end
@@ -60,10 +71,10 @@ module Urbanairship
60
71
  fail ArgumentError,
61
72
  'start_date and end_date must be valid date strings'
62
73
  end
63
- url = REPORTS_URL + 'responses/list?start=' + start_parsed.iso8601 + '&end=' + end_parsed.iso8601
64
- url += '&limit' + limit.to_s unless limit.nil?
65
- url += '&push_id_start&' + push_id_start unless push_id_start.nil?
66
- @next_page = url
74
+ path = reports_path('responses/list?start=' + start_parsed.iso8601 + '&end=' + end_parsed.iso8601)
75
+ path += '&limit' + limit.to_s unless limit.nil?
76
+ path += '&push_id_start&' + push_id_start unless push_id_start.nil?
77
+ @next_page_path = path
67
78
  @data_attribute = 'pushes'
68
79
  end
69
80
  end
@@ -87,7 +98,7 @@ module Urbanairship
87
98
  end
88
99
  response = @client.send_request(
89
100
  method: 'GET',
90
- url: REPORTS_URL + 'devices/?date=' + date_parsed.iso8601
101
+ path: reports_path('devices/?date=' + date_parsed.iso8601)
91
102
  )
92
103
  logger.info("Retrieved device report for date #{date}")
93
104
  response
@@ -98,8 +109,8 @@ module Urbanairship
98
109
  def initialize(client: required('client'), start_date: required('start_date'),
99
110
  end_date: required('end_date'), precision: required('precision'))
100
111
  super(client: client)
101
- url = Helper.new.get_url(start_date, end_date, precision)
102
- @next_page = REPORTS_URL + 'optins/' + url
112
+ period_params = Helper.new.get_period_params(start_date, end_date, precision)
113
+ @next_page_path = reports_path('optins/' + period_params)
103
114
  @data_attribute = 'optins'
104
115
  end
105
116
  end
@@ -108,8 +119,8 @@ module Urbanairship
108
119
  def initialize(client: required('client'), start_date: required('start_date'),
109
120
  end_date: required('end_date'), precision: required('precision'))
110
121
  super(client: client)
111
- url = Helper.new.get_url(start_date, end_date, precision)
112
- @next_page = REPORTS_URL + 'optouts/' + url
122
+ period_params = Helper.new.get_period_params(start_date, end_date, precision)
123
+ @next_page_path = reports_path('optouts/' + period_params)
113
124
  @data_attribute = 'optouts'
114
125
  end
115
126
  end
@@ -118,8 +129,8 @@ module Urbanairship
118
129
  def initialize(client: required('client'), start_date: required('start_date'),
119
130
  end_date: required('end_date'), precision: required('precision'))
120
131
  super(client: client)
121
- url = Helper.new.get_url(start_date, end_date, precision)
122
- @next_page = REPORTS_URL + 'sends/' + url
132
+ period_params = Helper.new.get_period_params(start_date, end_date, precision)
133
+ @next_page_path = reports_path('sends/' + period_params)
123
134
  @data_attribute = 'sends'
124
135
  end
125
136
  end
@@ -128,8 +139,8 @@ module Urbanairship
128
139
  def initialize(client: required('client'), start_date: required('start_date'),
129
140
  end_date: required('end_date'), precision: required('precision'))
130
141
  super(client: client)
131
- url = Helper.new.get_url(start_date, end_date, precision)
132
- @next_page = REPORTS_URL + 'responses/' + url
142
+ period_params = Helper.new.get_period_params(start_date, end_date, precision)
143
+ @next_page_path = reports_path('responses/' + period_params)
133
144
  @data_attribute = 'responses'
134
145
  end
135
146
  end
@@ -138,8 +149,8 @@ module Urbanairship
138
149
  def initialize(client: required('client'), start_date: required('start_date'),
139
150
  end_date: required('end_date'), precision: required('precision'))
140
151
  super(client: client)
141
- url = Helper.new.get_url(start_date, end_date, precision)
142
- @next_page = REPORTS_URL + 'opens/' + url
152
+ period_params = Helper.new.get_period_params(start_date, end_date, precision)
153
+ @next_page_path = reports_path('opens/' + period_params)
143
154
  @data_attribute = 'opens'
144
155
  end
145
156
  end
@@ -148,8 +159,8 @@ module Urbanairship
148
159
  def initialize(client: required('client'), start_date: required('start_date'),
149
160
  end_date: required('end_date'), precision: required('precision'))
150
161
  super(client: client)
151
- url = Helper.new.get_url(start_date, end_date, precision)
152
- @next_page = REPORTS_URL + 'timeinapp/' + url
162
+ period_params = Helper.new.get_period_params(start_date, end_date, precision)
163
+ @next_page_path = reports_path('timeinapp/' + period_params)
153
164
  @data_attribute = 'timeinapp'
154
165
  end
155
166
  end
@@ -1,3 +1,3 @@
1
1
  module Urbanairship
2
- VERSION = '5.7.0'
2
+ VERSION = '8.0.0'
3
3
  end
data/urbanairship.gemspec CHANGED
@@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
35
35
  spec.add_development_dependency 'rake', '~> 12.3.3'
36
36
  spec.add_development_dependency 'rspec', '~> 3'
37
37
  spec.add_development_dependency 'terminal-notifier-guard', '~> 1'
38
+ spec.add_development_dependency 'timecop'
38
39
  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.7.0
4
+ version: 8.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airship
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-31 00:00:00.000000000 Z
11
+ date: 2021-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -114,6 +114,20 @@ dependencies:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
116
  version: '1'
117
+ - !ruby/object:Gem::Dependency
118
+ name: timecop
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
117
131
  description: A Ruby Library for using the Airship web service API for push notifications
118
132
  and rich app pages.
119
133
  email:
@@ -139,6 +153,7 @@ files:
139
153
  - bin/setup
140
154
  - docs/Makefile
141
155
  - docs/ab_tests.rst
156
+ - docs/attributes.rst
142
157
  - docs/automations.rst
143
158
  - docs/channel_uninstall.rst
144
159
  - docs/conf.py
@@ -167,6 +182,10 @@ files:
167
182
  - lib/urbanairship/client.rb
168
183
  - lib/urbanairship/common.rb
169
184
  - lib/urbanairship/configuration.rb
185
+ - lib/urbanairship/custom_events/custom_event.rb
186
+ - lib/urbanairship/custom_events/payload.rb
187
+ - lib/urbanairship/devices/attribute.rb
188
+ - lib/urbanairship/devices/attributes.rb
170
189
  - lib/urbanairship/devices/channel_tags.rb
171
190
  - lib/urbanairship/devices/channel_uninstall.rb
172
191
  - lib/urbanairship/devices/create_and_send.rb
@@ -195,7 +214,7 @@ licenses:
195
214
  - Apache-2.0
196
215
  metadata:
197
216
  allowed_push_host: https://rubygems.org
198
- post_install_message:
217
+ post_install_message:
199
218
  rdoc_options: []
200
219
  require_paths:
201
220
  - lib
@@ -210,8 +229,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
229
  - !ruby/object:Gem::Version
211
230
  version: '0'
212
231
  requirements: []
213
- rubygems_version: 3.0.1
214
- signing_key:
232
+ rubygems_version: 3.1.4
233
+ signing_key:
215
234
  specification_version: 4
216
235
  summary: Ruby Gem for using the Airship API
217
236
  test_files: []