urbanairship 5.9.0 → 8.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,5 @@
1
1
  require 'urbanairship'
2
2
 
3
-
4
3
  module Urbanairship
5
4
  module Devices
6
5
  class NamedUser
@@ -13,6 +12,17 @@ module Urbanairship
13
12
  @named_user_id = nil
14
13
  end
15
14
 
15
+ def update_attributes(attributes: required('attributes'))
16
+ response = @client.send_request(
17
+ method: 'POST',
18
+ body: Urbanairship::Attributes.new(attributes).payload.to_json,
19
+ path: named_users_path("#{@named_user_id}/attributes"),
20
+ content_type: CONTENT_TYPE,
21
+ )
22
+ logger.info { "Updated attributes for named_user #{@named_user_id}" }
23
+ response
24
+ end
25
+
16
26
  def associate(channel_id: required('channel_id'), device_type: nil)
17
27
  fail ArgumentError,
18
28
  'named_user_id is required for association' if @named_user_id.nil?
@@ -20,13 +30,13 @@ module Urbanairship
20
30
  payload = {}
21
31
  payload['channel_id'] = channel_id
22
32
  payload['device_type'] = device_type unless device_type.nil?
23
- payload['named_user_id'] = @named_user_id
33
+ payload['named_user_id'] = @named_user_id.to_s
24
34
 
25
35
  response = @client.send_request(
26
36
  method: 'POST',
27
37
  body: JSON.dump(payload),
28
- url: NAMED_USER_URL + '/associate',
29
- content_type: 'application/json'
38
+ path: named_users_path('associate'),
39
+ content_type: CONTENT_TYPE
30
40
  )
31
41
  logger.info { "Associated channel_id #{channel_id} with named_user #{@named_user_id}" }
32
42
  response
@@ -40,8 +50,8 @@ module Urbanairship
40
50
  response = @client.send_request(
41
51
  method: 'POST',
42
52
  body: JSON.dump(payload),
43
- url: NAMED_USER_URL + '/disassociate',
44
- content_type: 'application/json'
53
+ path: named_users_path('disassociate'),
54
+ content_type: CONTENT_TYPE
45
55
  )
46
56
  logger.info { "Dissociated channel_id #{channel_id}" }
47
57
  response
@@ -51,8 +61,8 @@ module Urbanairship
51
61
  fail ArgumentError,
52
62
  'named_user_id is required for lookup' if @named_user_id.nil?
53
63
  response = @client.send_request(
54
- method: 'GET',
55
- url: NAMED_USER_URL + '?id=' + @named_user_id,
64
+ method: 'GET',
65
+ path: named_users_path('?id=' + @named_user_id),
56
66
  )
57
67
  logger.info { "Retrieved information on named_user_id #{@named_user_id}" }
58
68
  response
@@ -65,7 +75,7 @@ module Urbanairship
65
75
 
66
76
  def initialize(client: required('client'))
67
77
  super(client: client)
68
- @url = NAMED_USER_URL + 'tags/'
78
+ @path = named_users_path('tags/')
69
79
  end
70
80
 
71
81
  def set_audience(user_ids: required('user_ids'))
@@ -79,7 +89,7 @@ module Urbanairship
79
89
 
80
90
  def initialize(client: required('client'))
81
91
  super(client: client)
82
- @next_page = NAMED_USER_URL
92
+ @next_page_path = named_users_path
83
93
  @data_attribute = 'named_users'
84
94
  end
85
95
  end
@@ -101,8 +111,8 @@ module Urbanairship
101
111
  response = @client.send_request(
102
112
  method: 'POST',
103
113
  body: JSON.dump(payload),
104
- url: NAMED_USER_URL + '/uninstall',
105
- content_type: 'application/json'
114
+ path: named_users_path('uninstall'),
115
+ content_type: CONTENT_TYPE
106
116
  )
107
117
  logger.info { "Uninstalled named_user_ids #{@named_user_ids} " }
108
118
  response
@@ -5,11 +5,11 @@ module Urbanairship
5
5
  class OpenChannel
6
6
  include Urbanairship::Common
7
7
  include Urbanairship::Loggable
8
- attr_accessor :channel_id,
9
- :open_platform,
10
- :opt_in,
8
+ attr_accessor :channel_id,
9
+ :open_platform,
10
+ :opt_in,
11
11
  :address,
12
- :tags,
12
+ :tags,
13
13
  :identifiers,
14
14
  :template_id,
15
15
  :alert,
@@ -21,16 +21,16 @@ module Urbanairship
21
21
  :fields,
22
22
  :interactive,
23
23
  :platform_alert
24
-
24
+
25
25
  def initialize(client: required('client'))
26
26
  @client = client
27
27
  end
28
-
28
+
29
29
  def create()
30
30
  fail TypeError, 'address must be set to create open channel' unless address.is_a? String
31
31
  fail TypeError, 'open_platform must be set to create open channel' unless open_platform.is_a? String
32
32
  fail TypeError, 'opt_in must be boolean' unless [true, false].include? opt_in
33
-
33
+
34
34
  channel_data = {
35
35
  'type': 'open',
36
36
  'open': {:open_platform_name => open_platform},
@@ -38,21 +38,21 @@ module Urbanairship
38
38
  'address': address,
39
39
  'tags': tags
40
40
  }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
41
-
41
+
42
42
  set_identifiers
43
-
43
+
44
44
  body = {'channel': channel_data}
45
-
45
+
46
46
  response = @client.send_request(
47
47
  method: 'POST',
48
- url: OPEN_CHANNEL_URL,
48
+ path: open_channel_path,
49
49
  body: JSON.dump(body),
50
50
  content_type: 'application/json'
51
51
  )
52
52
  logger.info("Registering open channel with address: #{address}")
53
53
  response
54
54
  end
55
-
55
+
56
56
  def update(set_tags: required('set_tags'))
57
57
  fail ArgumentError, 'set_tags must be boolean' unless [true, false].include? set_tags
58
58
  fail ArgumentError, 'set_tags cannot be true when tags are not set' unless set_tags == true && tags != nil
@@ -60,7 +60,7 @@ module Urbanairship
60
60
  fail TypeError, 'address or channel_id must not be nil' unless address.is_a? String || channel_id.is_a?(String)
61
61
  fail TypeError, 'open_platform cannot be nil' unless open_platform.is_a? String
62
62
  fail TypeErorr, 'address must not be nil if opt_in is true' unless opt_in.is_a? TrueClass
63
-
63
+
64
64
  channel_data = {
65
65
  'type': 'open',
66
66
  'open': {'open_platform_name': open_platform},
@@ -70,34 +70,34 @@ module Urbanairship
70
70
  'address': address,
71
71
  'tags': tags
72
72
  }.delete_if {|key, value| value.nil?} #this removes the nil key value pairs
73
-
73
+
74
74
  set_identifiers
75
-
75
+
76
76
  body = {'channel': channel_data}
77
-
77
+
78
78
  response = @client.send_request(
79
79
  method: 'POST',
80
- url: OPEN_CHANNEL_URL,
80
+ path: open_channel_path,
81
81
  body: JSON.dump(body),
82
82
  content_type: 'application/json'
83
83
  )
84
84
  logger.info("Updating open channel with address #{address}")
85
85
  response
86
86
  end
87
-
87
+
88
88
  def lookup(channel_id: required('channel_id'))
89
89
  fail ArgumentError, 'channel_id needs to be a string' unless channel_id.is_a? String
90
-
90
+
91
91
  response = @client.send_request(
92
92
  method: 'GET',
93
- url: CHANNEL_URL + channel_id
93
+ path: channel_path(channel_id)
94
94
  )
95
95
  logger.info("Looking up info on device token #{channel_id}")
96
96
  response
97
97
  end
98
98
 
99
99
  def notification_with_template_id
100
- fail TypeError, 'open_platform cannot be nil' if open_platform.nil?
100
+ fail TypeError, 'open_platform cannot be nil' if open_platform.nil?
101
101
 
102
102
  if alert
103
103
  payload = {
@@ -124,7 +124,7 @@ module Urbanairship
124
124
  end
125
125
 
126
126
  def open_channel_override
127
- fail TypeError, 'open_platform cannot be nil' if open_platform.nil?
127
+ fail TypeError, 'open_platform cannot be nil' if open_platform.nil?
128
128
  payload = {
129
129
  'alert': platform_alert,
130
130
  'extra': extra,
@@ -147,4 +147,3 @@ module Urbanairship
147
147
  end
148
148
  end
149
149
  end
150
-
@@ -28,7 +28,7 @@ module Urbanairship
28
28
  response = @client.send_request(
29
29
  method: 'POST',
30
30
  body: JSON.dump(payload),
31
- url: SEGMENTS_URL,
31
+ path: segments_path,
32
32
  content_type: 'application/json'
33
33
  )
34
34
  logger.info { "Successful segment creation: #{@display_name}" }
@@ -45,7 +45,7 @@ module Urbanairship
45
45
  'id must be set to a valid string' if id.nil?
46
46
  response = @client.send_request(
47
47
  method: 'GET',
48
- url: SEGMENTS_URL + id
48
+ path: segments_path(id)
49
49
  )
50
50
  logger.info("Retrieved segment information for #{id}")
51
51
  @id = id
@@ -69,7 +69,7 @@ module Urbanairship
69
69
  response = @client.send_request(
70
70
  method: 'PUT',
71
71
  body: JSON.dump(data),
72
- url: SEGMENTS_URL + @id,
72
+ path: segments_path(@id),
73
73
  content_type: 'application/json'
74
74
  )
75
75
  logger.info { "Successful segment update: #{@display_name}" }
@@ -80,13 +80,11 @@ module Urbanairship
80
80
  #
81
81
  # @ returns [Object] response HTTP response
82
82
  def delete
83
- fail ArgumentError,
84
- 'id cannot be nil' if id.nil?
83
+ fail ArgumentError, 'id cannot be nil' if id.nil?
85
84
 
86
- url = SEGMENTS_URL + id
87
85
  response = @client.send_request(
88
86
  method: 'DELETE',
89
- url: url
87
+ path: segments_path(id)
90
88
  )
91
89
  logger.info { "Successful segment deletion: #{@display_name}" }
92
90
  response
@@ -98,7 +96,7 @@ module Urbanairship
98
96
 
99
97
  def initialize(client: required('client'))
100
98
  super(client: client)
101
- @next_page = SEGMENTS_URL
99
+ @next_page_path = segments_path
102
100
  @data_attribute = 'segments'
103
101
  end
104
102
  end
@@ -5,9 +5,9 @@ module Urbanairship
5
5
  class Sms
6
6
  include Urbanairship::Common
7
7
  include Urbanairship::Loggable
8
- attr_accessor :msisdn,
9
- :sender,
10
- :opted_in,
8
+ attr_accessor :msisdn,
9
+ :sender,
10
+ :opted_in,
11
11
  :sender,
12
12
  :locale_country,
13
13
  :locale_language,
@@ -31,7 +31,7 @@ module Urbanairship
31
31
  response = @client.send_request(
32
32
  method: 'POST',
33
33
  body: JSON.dump(payload),
34
- url: CHANNEL_URL + 'sms',
34
+ path: channel_path('sms'),
35
35
  content_type: 'application/json'
36
36
  )
37
37
  logger.info("Registering SMS channel with msisdn #{@msisdn}")
@@ -55,7 +55,7 @@ module Urbanairship
55
55
  response = @client.send_request(
56
56
  method: 'PUT',
57
57
  body: JSON.dump(payload),
58
- url: CHANNEL_URL + 'sms/' + channel_id,
58
+ path: channel_path('sms/' + channel_id),
59
59
  content_type: 'application/json'
60
60
  )
61
61
  logger.info("Updating SMS channel with msisdn #{@channel_id}")
@@ -74,7 +74,7 @@ module Urbanairship
74
74
  response = @client.send_request(
75
75
  method: 'POST',
76
76
  body: JSON.dump(payload),
77
- url: CHANNEL_URL + 'sms/opt-out',
77
+ path: channel_path('sms/opt-out'),
78
78
  content_type: 'application/json'
79
79
  )
80
80
  logger.info("Opting Out of SMS messages for #{@msisdn}")
@@ -93,7 +93,7 @@ module Urbanairship
93
93
  response = @client.send_request(
94
94
  method: 'POST',
95
95
  body: JSON.dump(payload),
96
- url: CHANNEL_URL + 'sms/uninstall',
96
+ path: channel_path('sms/uninstall'),
97
97
  content_type: 'application/json'
98
98
  )
99
99
  logger.info("Uninstalling SMS channel for #{@msisdn}")
@@ -106,7 +106,7 @@ module Urbanairship
106
106
 
107
107
  response = @client.send_request(
108
108
  method: 'GET',
109
- url: CHANNEL_URL + 'sms/' + @msisdn + '/' + @sender
109
+ path: channel_path('sms/' + @msisdn + '/' + @sender)
110
110
  )
111
111
  logger.info { "Retrieved information for msisdn #{@msisdn}" }
112
112
  response
@@ -22,7 +22,7 @@ module Urbanairship
22
22
  response = @client.send_request(
23
23
  method: 'POST',
24
24
  body: JSON.dump(payload),
25
- url: LISTS_URL,
25
+ path: lists_path,
26
26
  content_type: 'application/json'
27
27
  )
28
28
  logger.info("Created static list for #{@name}")
@@ -35,7 +35,7 @@ module Urbanairship
35
35
  response = @client.send_request(
36
36
  method: 'PUT',
37
37
  body: csv_file,
38
- url: LISTS_URL + @name + '/csv/',
38
+ path: lists_path(@name + '/csv/'),
39
39
  content_type: 'text/csv',
40
40
  encoding: gzip
41
41
  )
@@ -43,7 +43,7 @@ module Urbanairship
43
43
  response = @client.send_request(
44
44
  method: 'PUT',
45
45
  body: csv_file,
46
- url: LISTS_URL + @name + '/csv/',
46
+ path: lists_path(@name + '/csv/'),
47
47
  content_type: 'text/csv'
48
48
  )
49
49
  end
@@ -61,7 +61,7 @@ module Urbanairship
61
61
  response = @client.send_request(
62
62
  method: 'PUT',
63
63
  body: JSON.dump(payload),
64
- url: LISTS_URL + @name,
64
+ path: lists_path(@name),
65
65
  content_type: 'application/json'
66
66
  )
67
67
  logger.info("Updating the metadata for list #{@name}")
@@ -72,7 +72,7 @@ module Urbanairship
72
72
  fail ArgumentError, 'Name must be set' if name.nil?
73
73
  response = @client.send_request(
74
74
  method: 'GET',
75
- url: LISTS_URL + @name
75
+ path: lists_path(@name)
76
76
  )
77
77
  logger.info("Retrieving info for list #{@name}")
78
78
  response
@@ -82,7 +82,7 @@ module Urbanairship
82
82
  fail ArgumentError, 'Name must be set' if name.nil?
83
83
  response = @client.send_request(
84
84
  method: 'DELETE',
85
- url: LISTS_URL + @name
85
+ path: lists_path(@name)
86
86
  )
87
87
  logger.info("Deleted list #{@name}")
88
88
  response
@@ -92,7 +92,7 @@ module Urbanairship
92
92
  class StaticLists < Urbanairship::Common::PageIterator
93
93
  def initialize(client: required('client'))
94
94
  super(client: client)
95
- @next_page = LISTS_URL
95
+ @next_page_path = lists_path
96
96
  @data_attribute = 'lists'
97
97
  end
98
98
  end
@@ -14,11 +14,11 @@ module Urbanairship
14
14
  def name_lookup(name: required('name'), type: nil)
15
15
  fail ArgumentError, 'name needs to be a string' unless name.is_a? String
16
16
  fail ArgumentError, 'type needs to be a string' unless type.nil? or type.is_a? String
17
- url = LOCATION_URL + '?q=' + name
18
- url += '&type=' + type unless type.nil?
17
+ path = location_path('?q=' + name)
18
+ path += '&type=' + type unless type.nil?
19
19
  resp = @client.send_request(
20
20
  method: 'GET',
21
- url: url
21
+ path: path
22
22
  )
23
23
  logger.info("Retrieved location information for #{name}")
24
24
  resp
@@ -28,11 +28,11 @@ module Urbanairship
28
28
  fail ArgumentError,
29
29
  'latitude and longitude need to be numbers' unless latitude.is_a? Numeric and longitude.is_a? Numeric
30
30
  fail ArgumentError, 'type needs to be a string' unless type.nil? or type.is_a? String
31
- url = LOCATION_URL + latitude.to_s + ',' + longitude.to_s
32
- url += '?type=' + type unless type.nil?
31
+ path = location_path(latitude.to_s + ',' + longitude.to_s)
32
+ path += '?type=' + type unless type.nil?
33
33
  resp = @client.send_request(
34
34
  method: 'GET',
35
- url: url
35
+ path: path
36
36
  )
37
37
  logger.info("Retrieved location information for latitude #{latitude} and longitude #{longitude}")
38
38
  resp
@@ -45,11 +45,11 @@ module Urbanairship
45
45
  'lat1, long1, lat2, and long2 need to be numbers' unless lat1.is_a? Numeric and long2.is_a? Numeric\
46
46
  and lat2.is_a? Numeric and long2.is_a? Numeric
47
47
  fail ArgumentError, 'type needs to be a string' unless type.nil? or type.is_a? String
48
- url = LOCATION_URL + lat1.to_s + ',' + long1.to_s + ',' + lat2.to_s + ',' + long2.to_s
49
- url += '?type=' + type unless type.nil?
48
+ path = location_path(lat1.to_s + ',' + long1.to_s + ',' + lat2.to_s + ',' + long2.to_s)
49
+ path += '?type=' + type unless type.nil?
50
50
  resp = @client.send_request(
51
51
  method: 'GET',
52
- url: url
52
+ path: path
53
53
  )
54
54
  logger.info("Retrieved location information for bounding box with lat1 #{lat1}, long1 #{long1}," +
55
55
  " lat2 #{lat2}, and long2 #{long2}")
@@ -58,20 +58,20 @@ module Urbanairship
58
58
 
59
59
  def alias_lookup(from_alias: required('from_alias'))
60
60
  fail ArgumentError, 'from_alias needs to be a string or an array of strings' unless from_alias.is_a? String or from_alias.is_a? Array
61
- url = LOCATION_URL + 'from-alias?'
61
+ path = location_path('from-alias?')
62
62
  if from_alias.is_a? Array
63
63
  from_alias.each do |a|
64
64
  fail ArgumentError, 'from_alias needs to be a string or an array of strings' unless a.is_a? String
65
- url += a + '&'
65
+ path += a + '&'
66
66
  end
67
- url = url.chop
67
+ path = path.chop
68
68
  else
69
- url += from_alias
69
+ path += from_alias
70
70
  end
71
71
 
72
72
  resp = @client.send_request(
73
73
  method: 'GET',
74
- url: url
74
+ path: path
75
75
  )
76
76
  logger.info("Retrieved location info from alias #{from_alias}")
77
77
  resp
@@ -81,10 +81,10 @@ module Urbanairship
81
81
  fail ArgumentError, 'polygon_id needs to be a string' unless polygon_id.is_a? String
82
82
  fail ArgumentError, 'zoom needs to be an integer' unless zoom.is_a? Integer
83
83
 
84
- url = LOCATION_URL + polygon_id + '?zoom=' + zoom.to_s
84
+ path = location_path(polygon_id + '?zoom=' + zoom.to_s)
85
85
  resp = @client.send_request(
86
86
  method: 'GET',
87
- url: url
87
+ path: path
88
88
  )
89
89
  logger.info("Retrieved location info for polygon #{polygon_id} and zoom level #{zoom}")
90
90
  resp
@@ -93,11 +93,11 @@ module Urbanairship
93
93
  def date_ranges
94
94
  resp = @client.send_request(
95
95
  method: 'GET',
96
- url: SEGMENTS_URL + 'dates/'
96
+ path: segments_path('dates/')
97
97
  )
98
98
  logger.info('Retrieved location date ranges')
99
99
  resp
100
100
  end
101
101
  end
102
102
  end
103
- end
103
+ end
@@ -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