urbanairship 6.0.0 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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 = '6.0.0'
2
+ VERSION = '7.0.0'
3
3
  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: 6.0.0
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Airship
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-18 00:00:00.000000000 Z
11
+ date: 2021-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client