urbanairship 5.9.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dbcc6fe1884df9f5beb53e6bc29406d2d4cb51aabfab22cc45f67b714104064
4
- data.tar.gz: d147e04cbeadbb51e13325ff9cd5b7af458aa22531b8aab2e4ef0c19544ae15c
3
+ metadata.gz: 169148502585341b7938add240f3595e2124e56228916a1ad73b72f4e457885e
4
+ data.tar.gz: da1a1067c809c43bed0b0df1ebfc55d28443c2adcb1d5c0c8f3311dbd070b378
5
5
  SHA512:
6
- metadata.gz: 7109db5053551032e3c6f933d07e39496b1f8d530349dba64a0b0b1d0b09ed5d2cbec46f89bd3adfe340cbfc0601d0ca089bcf17d302ad498959790915819096
7
- data.tar.gz: 2e6366c2f3cbb0b35bbb68e78a1752fd32ddfeefe7316ddbcaa609b5971947d8e01c898672eee1eec617ecef222bc36928a972fefcb2b18bad0406993813536b
6
+ metadata.gz: 6f04b2d733ed47e8bf8779cf3844d67962b0b7815c9450b5112cb706b81e8c8f566660034f21a8762a6ddc9ac6c547e43fdbc11d083e881096bac53315d9f8d2
7
+ data.tar.gz: fdd59798309c0dca97e596c35684ccab4f1cf04d9ffe7fb72eb6964a5466c126c6d47c236f9b50f784b4b1ba1e5a455b00950353aa9c77ffb62aa48ace89a2ee
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ --------------------
2
+ 6.0.0
3
+ --------------------
4
+ - Creates custom base url, and refactors urls within classes
5
+ - Adds support for sending custom events
6
+
1
7
  --------------------
2
8
  5.9.0
3
9
  --------------------
data/README.rst CHANGED
@@ -58,6 +58,7 @@ In your app initialization, you can do something like the following:
58
58
 
59
59
  >>> require 'urbanairship'
60
60
  >>> Urbanairship.configure do |config|
61
+ >>> config.server = 'go.airship.eu'
61
62
  >>> config.log_path = '/path/to/your/logfile'
62
63
  >>> config.log_level = Logger::WARN
63
64
  >>> config.timeout = 60
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'
@@ -31,10 +32,13 @@ require 'urbanairship/ab_tests/experiment'
31
32
  require 'urbanairship/ab_tests/ab_test'
32
33
 
33
34
  module Urbanairship
35
+ extend Urbanairship::CustomEvents::Payload
36
+ extend Urbanairship::CustomEvents
34
37
  extend Urbanairship::Push::Audience
35
38
  extend Urbanairship::Push::Payload
36
39
  extend Urbanairship::Push::Schedule
37
40
  extend Urbanairship::Push
41
+ include Urbanairship::CustomEvents
38
42
  include Urbanairship::Devices
39
43
  include Urbanairship::Reports
40
44
  include Urbanairship::Push
@@ -11,7 +11,7 @@ module Urbanairship
11
11
  :offset,
12
12
  :experiment_object,
13
13
  :experiment_id
14
-
14
+
15
15
  def initialize(client: required('client'))
16
16
  @client = client
17
17
  end
@@ -19,7 +19,7 @@ module Urbanairship
19
19
  def list_ab_test
20
20
  response = @client.send_request(
21
21
  method: 'GET',
22
- url: EXPERIMENTS_URL + format_url_with_params
22
+ url: experiments_url(format_url_with_params)
23
23
  )
24
24
  logger.info("Looking up A/B Tests for project")
25
25
  response
@@ -29,7 +29,7 @@ module Urbanairship
29
29
  response = @client.send_request(
30
30
  method: 'POST',
31
31
  body: JSON.dump(experiment_object),
32
- url: EXPERIMENTS_URL,
32
+ url: experiments_url,
33
33
  content_type: 'application/json'
34
34
  )
35
35
  logger.info("Created A/B Test")
@@ -39,7 +39,7 @@ module Urbanairship
39
39
  def list_scheduled_ab_test
40
40
  response = @client.send_request(
41
41
  method: 'GET',
42
- url: EXPERIMENTS_URL + 'scheduled' + format_url_with_params
42
+ url: experiments_url('scheduled' + format_url_with_params)
43
43
  )
44
44
  logger.info("Looking up scheduled A/B Tests for project")
45
45
  response
@@ -49,7 +49,7 @@ module Urbanairship
49
49
  fail ArgumentError, 'experiment_id must be set to delete individual A/B test' if @experiment_id.nil?
50
50
  response = @client.send_request(
51
51
  method: 'DELETE',
52
- url: EXPERIMENTS_URL + 'scheduled/' + experiment_id
52
+ url: experiments_url('scheduled/' + experiment_id)
53
53
  )
54
54
  logger.info("Deleting A/B test with ID #{experiment_id}")
55
55
  response
@@ -59,7 +59,7 @@ module Urbanairship
59
59
  response = @client.send_request(
60
60
  method: 'POST',
61
61
  body: JSON.dump(experiment_object),
62
- url: EXPERIMENTS_URL + 'validate',
62
+ url: experiments_url('validate'),
63
63
  content_type: 'application/json'
64
64
  )
65
65
  logger.info("Validating A/B Test")
@@ -70,7 +70,7 @@ module Urbanairship
70
70
  fail ArgumentError, 'experiment_id must be set to lookup individual A/B Test' if @experiment_id.nil?
71
71
  response = @client.send_request(
72
72
  method: 'GET',
73
- url: EXPERIMENTS_URL + experiment_id
73
+ url: experiments_url(experiment_id)
74
74
  )
75
75
  logger.info("Looking up A/B test with ID #{experiment_id}")
76
76
  response
@@ -85,5 +85,4 @@ module Urbanairship
85
85
  end
86
86
  end
87
87
  end
88
- end
89
-
88
+ end
@@ -22,7 +22,7 @@ module Urbanairship
22
22
  response = @client.send_request(
23
23
  method: 'POST',
24
24
  body: JSON.dump(pipeline_object),
25
- url: PIPELINES_URL,
25
+ url: pipelines_url,
26
26
  content_type: 'application/json'
27
27
  )
28
28
  logger.info("Created Automation")
@@ -32,7 +32,7 @@ module Urbanairship
32
32
  def list_automations
33
33
  response = @client.send_request(
34
34
  method: 'GET',
35
- url: PIPELINES_URL + format_url_with_params
35
+ url: pipelines_url(format_url_with_params)
36
36
  )
37
37
  logger.info("Looking up automations for project")
38
38
  response
@@ -41,7 +41,7 @@ module Urbanairship
41
41
  def list_deleted_automations
42
42
  response = @client.send_request(
43
43
  method: 'GET',
44
- url: PIPELINES_URL + 'deleted' + format_url_with_params
44
+ url: pipelines_url('deleted' + format_url_with_params)
45
45
  )
46
46
  logger.info("Looking up deleted automations for project")
47
47
  response
@@ -51,18 +51,18 @@ module Urbanairship
51
51
  response = @client.send_request(
52
52
  method: 'POST',
53
53
  body: JSON.dump(pipeline_object),
54
- url: PIPELINES_URL + 'validate',
54
+ url: pipelines_url('validate'),
55
55
  content_type: 'application/json'
56
56
  )
57
57
  logger.info("Validating Automation")
58
58
  response
59
59
  end
60
60
 
61
- def lookup_automation
61
+ def lookup_automation
62
62
  fail ArgumentError, 'pipeline_id must be set to lookup individual automation' if @pipeline_id.nil?
63
63
  response = @client.send_request(
64
64
  method: 'GET',
65
- url: PIPELINES_URL + pipeline_id
65
+ url: pipelines_url(pipeline_id)
66
66
  )
67
67
  logger.info("Looking up automation with id #{pipeline_id}")
68
68
  response
@@ -70,22 +70,22 @@ module Urbanairship
70
70
 
71
71
  def update_automation
72
72
  fail ArgumentError, 'pipeline_id must be set to update individual automation' if @pipeline_id.nil?
73
-
73
+
74
74
  response = @client.send_request(
75
75
  method: 'PUT',
76
76
  body: JSON.dump(pipeline_object),
77
- url: PIPELINES_URL + pipeline_id,
77
+ url: pipelines_url(pipeline_id),
78
78
  content_type: 'application/json'
79
79
  )
80
80
  logger.info("Validating Automation")
81
81
  response
82
82
  end
83
83
 
84
- def delete_automation
84
+ def delete_automation
85
85
  fail ArgumentError, 'pipeline_id must be set to delete individual automation' if @pipeline_id.nil?
86
86
  response = @client.send_request(
87
87
  method: 'DELETE',
88
- url: PIPELINES_URL + pipeline_id
88
+ url: pipelines_url(pipeline_id)
89
89
  )
90
90
  logger.info("Deleting automation with id #{pipeline_id}")
91
91
  response
@@ -102,4 +102,4 @@ module Urbanairship
102
102
  end
103
103
  end
104
104
  end
105
- end
105
+ end
@@ -4,23 +4,69 @@ require 'urbanairship/loggable'
4
4
  module Urbanairship
5
5
  # Features mixed in to all classes
6
6
  module Common
7
- SERVER = 'go.urbanairship.com'
8
- BASE_URL = 'https://go.urbanairship.com/api'
9
- CHANNEL_URL = BASE_URL + '/channels/'
10
- OPEN_CHANNEL_URL = BASE_URL + '/channels/open/'
11
- DEVICE_TOKEN_URL = BASE_URL + '/device_tokens/'
12
- APID_URL = BASE_URL + '/apids/'
13
- PUSH_URL = BASE_URL + '/push/'
14
- SCHEDULES_URL = BASE_URL + '/schedules/'
15
- SEGMENTS_URL = BASE_URL + '/segments/'
16
- NAMED_USER_URL = BASE_URL + '/named_users/'
17
- REPORTS_URL = BASE_URL + '/reports/'
18
- LISTS_URL = BASE_URL + '/lists/'
19
- PIPELINES_URL = BASE_URL + '/pipelines/'
20
- FEEDS_URL = BASE_URL + '/feeds/'
21
- LOCATION_URL = BASE_URL + '/location/'
22
- CREATE_AND_SEND_URL = BASE_URL + '/create-and-send/'
23
- EXPERIMENTS_URL = BASE_URL + '/experiments/'
7
+ def url_for(path)
8
+ "https://#{Urbanairship.configuration.server}/api#{path}"
9
+ end
10
+
11
+ def apid_url(path='')
12
+ url_for("/apids/#{path}")
13
+ end
14
+
15
+ def channel_url(path='')
16
+ url_for("/channels/#{path}")
17
+ end
18
+
19
+ def create_and_send_url(path='')
20
+ url_for("/create-and-send/#{path}")
21
+ end
22
+
23
+ def custom_events_url(path='')
24
+ url_for("/custom-events/#{path}")
25
+ end
26
+
27
+ def device_token_url(path='')
28
+ url_for("/device_tokens/#{path}")
29
+ end
30
+
31
+ def experiments_url(path='')
32
+ url_for("/experiments/#{path}")
33
+ end
34
+
35
+ def lists_url(path='')
36
+ url_for("/lists/#{path}")
37
+ end
38
+
39
+ def location_url(path='')
40
+ url_for("/location/#{path}")
41
+ end
42
+
43
+ def named_users_url(path='')
44
+ url_for("/named_users/#{path}")
45
+ end
46
+
47
+ def open_channel_url(path='')
48
+ channel_url("/open/#{path}")
49
+ end
50
+
51
+ def pipelines_url(path='')
52
+ url_for("/pipelines/#{path}")
53
+ end
54
+
55
+ def push_url(path='')
56
+ url_for("/push/#{path}")
57
+ end
58
+
59
+ def reports_url(path='')
60
+ url_for("/reports/#{path}")
61
+ end
62
+
63
+ def schedules_url(path='')
64
+ url_for("/schedules/#{path}")
65
+ end
66
+
67
+ def segments_url(path='')
68
+ url_for("/segments/#{path}")
69
+ end
24
70
 
25
71
  # Helper method for required keyword args in Ruby 2.0 that is compatible with 2.1+
26
72
  # @example
@@ -1,8 +1,9 @@
1
1
  module Urbanairship
2
2
  class Configuration
3
- attr_accessor :custom_logger, :log_path, :log_level, :timeout
3
+ attr_accessor :custom_logger, :log_path, :log_level, :server, :timeout
4
4
 
5
5
  def initialize
6
+ @server = 'go.urbanairship.com'
6
7
  @custom_logger = nil
7
8
  @log_path = nil
8
9
  @log_level = Logger::INFO
@@ -0,0 +1,60 @@
1
+ require 'uri'
2
+ require 'urbanairship'
3
+ require 'urbanairship/common'
4
+ require 'urbanairship/loggable'
5
+
6
+ module Urbanairship
7
+ module CustomEvents
8
+ class CustomEvent
9
+ include Urbanairship::Common
10
+ include Urbanairship::Loggable
11
+
12
+ attr_accessor :events
13
+
14
+ def initialize(client: required('client'))
15
+ @client = client
16
+ end
17
+
18
+ def create
19
+ fail ArgumentError, 'events must be an array of custom events' unless events.is_a?(Array)
20
+
21
+ response = @client.send_request(
22
+ auth_type: :bearer,
23
+ body: JSON.dump(events),
24
+ content_type: 'application/json',
25
+ method: 'POST',
26
+ url: custom_events_url
27
+ )
28
+ cer = CustomEventResponse.new(body: response['body'], code: response['code'])
29
+ logger.info { cer.format }
30
+
31
+ cer
32
+ end
33
+ end
34
+
35
+ # Response to a successful custom event creation.
36
+ class CustomEventResponse
37
+ attr_reader :ok, :operation_id, :payload, :status_code
38
+
39
+ def initialize(body: nil, code: nil)
40
+ @payload = (body.nil? || body.empty?) ? {} : body
41
+ @ok = payload['ok']
42
+ @operation_id = payload['operationId']
43
+ @status_code = code
44
+ end
45
+
46
+ # String Formatting of the CustomEventResponse
47
+ #
48
+ # @return [Object] String Formatted CustomEventResponse
49
+ def format
50
+ "Received [#{status_code}] response code.\nBody:\n#{formatted_body}"
51
+ end
52
+
53
+ def formatted_body
54
+ payload
55
+ .map { |key, value| "#{key}:\t#{value.to_s || 'None'}" }
56
+ .join("\n")
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,89 @@
1
+ require 'urbanairship'
2
+ require 'urbanairship/common'
3
+
4
+ module Urbanairship
5
+ module CustomEvents
6
+ module Payload
7
+ include Urbanairship::Common
8
+
9
+ def custom_events(
10
+ body: required('body'),
11
+ occurred: required('occurred'),
12
+ user: required('user')
13
+ )
14
+ compact_helper({
15
+ body: body,
16
+ occurred: format_timestamp(occurred),
17
+ user: user
18
+ })
19
+ end
20
+
21
+ # Body specific portion of CustomEvent Object
22
+ def custom_events_body(
23
+ interaction_id: nil, interaction_type: nil, name: required('name'),
24
+ properties: nil, session_id: nil, transaction: nil, value: nil
25
+ )
26
+
27
+ validates_name_format(name)
28
+ validates_value_format(value)
29
+
30
+ compact_helper({
31
+ interaction_id: interaction_id,
32
+ interaction_type: interaction_type,
33
+ name: name,
34
+ properties: properties,
35
+ session_id: session_id,
36
+ transaction: transaction,
37
+ value: value
38
+ })
39
+ end
40
+
41
+ # User specific portion of CustomEvent Object
42
+ def custom_events_user(
43
+ amazon_channel: nil, android_channel: nil, channel: nil,
44
+ ios_channel: nil, named_user_id: nil, web_channel: nil
45
+ )
46
+ res = compact_helper({
47
+ amazon_channel: amazon_channel,
48
+ android_channel: android_channel,
49
+ channel: channel,
50
+ ios_channel: ios_channel,
51
+ named_user_id: named_user_id,
52
+ web_channel: web_channel,
53
+ })
54
+
55
+ fail ArgumentError, 'at least one user identifier must be defined' if res.empty?
56
+
57
+ res
58
+ end
59
+
60
+
61
+ # Formatters
62
+ # ------------------------------------------------------------------------
63
+
64
+ def format_timestamp(timestamp)
65
+ return timestamp if timestamp.is_a?(String)
66
+
67
+ timestamp.strftime('%Y-%m-%dT%H:%M:%S')
68
+ end
69
+
70
+
71
+ # Validators
72
+ # ------------------------------------------------------------------------
73
+
74
+ NAME_REGEX = /^[a-z0-9_\-]+$/
75
+ def validates_name_format(name)
76
+ return if name =~ NAME_REGEX
77
+
78
+ fail ArgumentError, 'invalid "name": it must follows this pattern /^[a-z0-9_\-]+$/'
79
+ end
80
+
81
+ def validates_value_format(value)
82
+ return if value.nil?
83
+ return if value.is_a?(Numeric)
84
+
85
+ fail ArgumentError, 'invalid "value": must be a number'
86
+ end
87
+ end
88
+ end
89
+ end
@@ -15,7 +15,7 @@ module Urbanairship
15
15
  @add_group = {}
16
16
  @remove_group = {}
17
17
  @set_group = {}
18
- @url = CHANNEL_URL + 'tags/'
18
+ @url = channel_url('tags/')
19
19
  end
20
20
 
21
21
  def set_audience(ios: nil, android: nil, amazon: nil)
@@ -23,7 +23,7 @@ module Urbanairship
23
23
  response = @client.send_request(
24
24
  method: 'POST',
25
25
  body: JSON.dump(channels),
26
- url: CHANNEL_URL + 'uninstall/',
26
+ url: channel_url('uninstall/'),
27
27
  content_type: 'application/json'
28
28
  )
29
29
 
@@ -31,32 +31,32 @@ module Urbanairship
31
31
  response
32
32
  end
33
33
  end
34
-
35
-
34
+
35
+
36
36
  class OpenChannelUninstall
37
37
  include Urbanairship::Common
38
38
  include Urbanairship::Loggable
39
39
  attr_reader :client
40
-
40
+
41
41
  def initialize(client: required('client'))
42
42
  @client = client
43
43
  end
44
-
44
+
45
45
  def uninstall(address: required('address'),
46
46
  open_platform: required('open_platform'))
47
-
47
+
48
48
  body = {
49
49
  address: address,
50
50
  open_platform_name: open_platform
51
51
  }
52
-
52
+
53
53
  response = @client.send_request(
54
54
  method: 'POST',
55
55
  body: JSON.dump(body),
56
- url: OPEN_CHANNEL_URL + 'uninstall/',
56
+ url: open_channel_url('uninstall/'),
57
57
  content_type: 'application/json'
58
58
  )
59
-
59
+
60
60
  logger.info { "Successfully uninstalled open channel with address: #{address}"}
61
61
  response
62
62
  end
@@ -44,7 +44,7 @@ module Urbanairship
44
44
  campaign_object = {'categories': campaigns}
45
45
  full_payload[:campaigns] = campaign_object
46
46
  end
47
-
47
+
48
48
  full_payload
49
49
  end
50
50
 
@@ -52,7 +52,7 @@ module Urbanairship
52
52
  response = @client.send_request(
53
53
  method: 'POST',
54
54
  body: JSON.dump(payload),
55
- url: CREATE_AND_SEND_URL,
55
+ url: create_and_send_url,
56
56
  content_type: 'application/json'
57
57
  )
58
58
  logger.info("Running create and send for addresses #{@addresses}")
@@ -63,7 +63,7 @@ module Urbanairship
63
63
  response = @client.send_request(
64
64
  method: 'POST',
65
65
  body: JSON.dump(payload),
66
- url: CREATE_AND_SEND_URL + 'validate',
66
+ url: create_and_send_url('validate'),
67
67
  content_type: 'application/json'
68
68
  )
69
69
  logger.info("Validating payload for create and send")
@@ -84,7 +84,7 @@ module Urbanairship
84
84
  response = @client.send_request(
85
85
  method: 'POST',
86
86
  body: JSON.dump(scheduled_payload),
87
- url: SCHEDULES_URL + 'create-and-send',
87
+ url: schedules_url('create-and-send'),
88
88
  content_type: 'application/json'
89
89
  )
90
90
  logger.info("Scheduling create and send operation with name #{@name}")
@@ -17,7 +17,7 @@ module Urbanairship
17
17
  def lookup(uuid: required('uuid'))
18
18
  response = @client.send_request(
19
19
  method: 'GET',
20
- url: CHANNEL_URL + uuid
20
+ url: channel_url(uuid)
21
21
  )
22
22
  logger.info("Retrieved channel information for #{uuid}")
23
23
  response['body']['channel']
@@ -36,7 +36,7 @@ module Urbanairship
36
36
  response = @client.send_request(
37
37
  method: 'POST',
38
38
  body: JSON.dump(payload),
39
- url: CHANNEL_URL + 'attributes',
39
+ url: channel_url('attributes'),
40
40
  content_type: 'application/json'
41
41
  )
42
42
  response
@@ -46,7 +46,7 @@ module Urbanairship
46
46
  class ChannelList < Urbanairship::Common::PageIterator
47
47
  def initialize(client: required('client'))
48
48
  super(client: client)
49
- @next_page = CHANNEL_URL
49
+ @next_page = channel_url
50
50
  @data_attribute = 'channels'
51
51
  end
52
52
  end
@@ -64,7 +64,7 @@ module Urbanairship
64
64
 
65
65
  resp = @client.send_request(
66
66
  method: 'GET',
67
- url: DEVICE_TOKEN_URL + token
67
+ url: device_token_url(token)
68
68
  )
69
69
  logger.info("Looking up info on device token #{token}")
70
70
  resp
@@ -77,7 +77,7 @@ module Urbanairship
77
77
 
78
78
  def initialize(client: required('client'))
79
79
  super(client: client)
80
- @next_page = DEVICE_TOKEN_URL
80
+ @next_page = device_token_url
81
81
  @data_attribute = 'device_tokens'
82
82
  end
83
83
  end
@@ -95,7 +95,7 @@ module Urbanairship
95
95
 
96
96
  resp = @client.send_request(
97
97
  method: 'GET',
98
- url: APID_URL + apid
98
+ url: apid_url(apid)
99
99
  )
100
100
  logger.info("Retrieved info on apid #{apid}")
101
101
  resp
@@ -105,9 +105,9 @@ module Urbanairship
105
105
  class APIDList < Urbanairship::Common::PageIterator
106
106
  def initialize(client: required('client'))
107
107
  super(client: client)
108
- @next_page = APID_URL
108
+ @next_page = apid_url
109
109
  @data_attribute = 'apids'
110
110
  end
111
111
  end
112
112
  end
113
- end
113
+ end
@@ -41,7 +41,7 @@ module Urbanairship
41
41
  response = @client.send_request(
42
42
  method: 'POST',
43
43
  body: JSON.dump(payload),
44
- url: CHANNEL_URL + 'email',
44
+ url: channel_url('email'),
45
45
  content_type: 'application/json'
46
46
  )
47
47
  logger.info("Registering email channel with address #{address}")
@@ -58,7 +58,7 @@ module Urbanairship
58
58
  response = @client.send_request(
59
59
  method: 'POST',
60
60
  body: JSON.dump(payload),
61
- url: CHANNEL_URL + 'email/uninstall',
61
+ url: channel_url('email/uninstall'),
62
62
  content_type: 'application/json'
63
63
  )
64
64
  logger.info("Uninstalling email channel with address #{address}")
@@ -70,7 +70,7 @@ module Urbanairship
70
70
 
71
71
  response = @client.send_request(
72
72
  method: 'GET',
73
- url: CHANNEL_URL + 'email/' + address
73
+ url: channel_url('email/' + address)
74
74
  )
75
75
  logger.info("Looking up email channel with address #{address}")
76
76
  response
@@ -95,7 +95,7 @@ module Urbanairship
95
95
 
96
96
  response = @client.send_request(
97
97
  method: 'PUT',
98
- url: CHANNEL_URL + 'email/' + channel_id,
98
+ url: channel_url('email/' + channel_id),
99
99
  body: JSON.dump(payload),
100
100
  content_type: 'application/json'
101
101
  )
@@ -109,7 +109,7 @@ module Urbanairship
109
109
 
110
110
  def initialize(client: required('client'))
111
111
  super(client: client)
112
- @url = CHANNEL_URL + 'email/tags'
112
+ @url = channel_url('email/tags')
113
113
  end
114
114
 
115
115
  def set_audience(email_address: required('email_address'))
@@ -25,7 +25,7 @@ module Urbanairship
25
25
  response = @client.send_request(
26
26
  method: 'POST',
27
27
  body: JSON.dump(payload),
28
- url: NAMED_USER_URL + '/associate',
28
+ url: named_users_url('/associate'),
29
29
  content_type: 'application/json'
30
30
  )
31
31
  logger.info { "Associated channel_id #{channel_id} with named_user #{@named_user_id}" }
@@ -40,7 +40,7 @@ module Urbanairship
40
40
  response = @client.send_request(
41
41
  method: 'POST',
42
42
  body: JSON.dump(payload),
43
- url: NAMED_USER_URL + '/disassociate',
43
+ url: named_users_url('/disassociate'),
44
44
  content_type: 'application/json'
45
45
  )
46
46
  logger.info { "Dissociated channel_id #{channel_id}" }
@@ -52,7 +52,7 @@ module Urbanairship
52
52
  'named_user_id is required for lookup' if @named_user_id.nil?
53
53
  response = @client.send_request(
54
54
  method: 'GET',
55
- url: NAMED_USER_URL + '?id=' + @named_user_id,
55
+ url: named_users_url('?id=' + @named_user_id),
56
56
  )
57
57
  logger.info { "Retrieved information on named_user_id #{@named_user_id}" }
58
58
  response
@@ -65,7 +65,7 @@ module Urbanairship
65
65
 
66
66
  def initialize(client: required('client'))
67
67
  super(client: client)
68
- @url = NAMED_USER_URL + 'tags/'
68
+ @url = named_users_url('tags/')
69
69
  end
70
70
 
71
71
  def set_audience(user_ids: required('user_ids'))
@@ -79,7 +79,7 @@ module Urbanairship
79
79
 
80
80
  def initialize(client: required('client'))
81
81
  super(client: client)
82
- @next_page = NAMED_USER_URL
82
+ @next_page = named_users_url
83
83
  @data_attribute = 'named_users'
84
84
  end
85
85
  end
@@ -101,7 +101,7 @@ module Urbanairship
101
101
  response = @client.send_request(
102
102
  method: 'POST',
103
103
  body: JSON.dump(payload),
104
- url: NAMED_USER_URL + '/uninstall',
104
+ url: named_users_url('/uninstall'),
105
105
  content_type: 'application/json'
106
106
  )
107
107
  logger.info { "Uninstalled named_user_ids #{@named_user_ids} " }
@@ -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
+ url: open_channel_url,
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
+ url: open_channel_url,
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
+ url: channel_url(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
+ url: segments_url,
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
+ url: segments_url(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
+ url: segments_url(@id),
73
73
  content_type: 'application/json'
74
74
  )
75
75
  logger.info { "Successful segment update: #{@display_name}" }
@@ -83,7 +83,7 @@ module Urbanairship
83
83
  fail ArgumentError,
84
84
  'id cannot be nil' if id.nil?
85
85
 
86
- url = SEGMENTS_URL + id
86
+ url = segments_url(id)
87
87
  response = @client.send_request(
88
88
  method: 'DELETE',
89
89
  url: url
@@ -98,7 +98,7 @@ module Urbanairship
98
98
 
99
99
  def initialize(client: required('client'))
100
100
  super(client: client)
101
- @next_page = SEGMENTS_URL
101
+ @next_page = segments_url
102
102
  @data_attribute = 'segments'
103
103
  end
104
104
  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
+ url: channel_url('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
+ url: channel_url('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
+ url: channel_url('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
+ url: channel_url('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
+ url: channel_url('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
+ url: lists_url,
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
+ url: lists_url(@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
+ url: lists_url(@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
+ url: lists_url(@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
+ url: lists_url(@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
+ url: lists_url(@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 = lists_url
96
96
  @data_attribute = 'lists'
97
97
  end
98
98
  end
@@ -14,7 +14,7 @@ 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
17
+ url = location_url('?q=' + name)
18
18
  url += '&type=' + type unless type.nil?
19
19
  resp = @client.send_request(
20
20
  method: 'GET',
@@ -28,7 +28,7 @@ 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
31
+ url = location_url(latitude.to_s + ',' + longitude.to_s)
32
32
  url += '?type=' + type unless type.nil?
33
33
  resp = @client.send_request(
34
34
  method: 'GET',
@@ -45,7 +45,7 @@ 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
48
+ url = location_url(lat1.to_s + ',' + long1.to_s + ',' + lat2.to_s + ',' + long2.to_s)
49
49
  url += '?type=' + type unless type.nil?
50
50
  resp = @client.send_request(
51
51
  method: 'GET',
@@ -58,7 +58,7 @@ 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
+ url = location_url('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
@@ -81,7 +81,7 @@ 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
+ url = location_url(polygon_id + '?zoom=' + zoom.to_s)
85
85
  resp = @client.send_request(
86
86
  method: 'GET',
87
87
  url: url
@@ -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
+ url: segments_url('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
+ url: push_url,
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
+ url: schedules_url,
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
+ url: schedules_url(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 = schedules_url
185
185
  @data_attribute = 'schedules'
186
186
  end
187
187
  end
@@ -35,7 +35,7 @@ module Urbanairship
35
35
  fail ArgumentError,
36
36
  'push_id cannot be nil' if push_id.nil?
37
37
 
38
- url = REPORTS_URL + 'responses/' + push_id
38
+ url = reports_url('responses/' + push_id)
39
39
  response = @client.send_request(method: 'GET', url: url)
40
40
  logger.info("Retrieved info on push_id: #{push_id}")
41
41
  response
@@ -60,7 +60,7 @@ module Urbanairship
60
60
  fail ArgumentError,
61
61
  'start_date and end_date must be valid date strings'
62
62
  end
63
- url = REPORTS_URL + 'responses/list?start=' + start_parsed.iso8601 + '&end=' + end_parsed.iso8601
63
+ url = reports_url('responses/list?start=' + start_parsed.iso8601 + '&end=' + end_parsed.iso8601)
64
64
  url += '&limit' + limit.to_s unless limit.nil?
65
65
  url += '&push_id_start&' + push_id_start unless push_id_start.nil?
66
66
  @next_page = url
@@ -87,7 +87,7 @@ module Urbanairship
87
87
  end
88
88
  response = @client.send_request(
89
89
  method: 'GET',
90
- url: REPORTS_URL + 'devices/?date=' + date_parsed.iso8601
90
+ url: reports_url('devices/?date=' + date_parsed.iso8601)
91
91
  )
92
92
  logger.info("Retrieved device report for date #{date}")
93
93
  response
@@ -99,7 +99,7 @@ module Urbanairship
99
99
  end_date: required('end_date'), precision: required('precision'))
100
100
  super(client: client)
101
101
  url = Helper.new.get_url(start_date, end_date, precision)
102
- @next_page = REPORTS_URL + 'optins/' + url
102
+ @next_page = reports_url('optins/' + url)
103
103
  @data_attribute = 'optins'
104
104
  end
105
105
  end
@@ -109,7 +109,7 @@ module Urbanairship
109
109
  end_date: required('end_date'), precision: required('precision'))
110
110
  super(client: client)
111
111
  url = Helper.new.get_url(start_date, end_date, precision)
112
- @next_page = REPORTS_URL + 'optouts/' + url
112
+ @next_page = reports_url('optouts/' + url)
113
113
  @data_attribute = 'optouts'
114
114
  end
115
115
  end
@@ -119,7 +119,7 @@ module Urbanairship
119
119
  end_date: required('end_date'), precision: required('precision'))
120
120
  super(client: client)
121
121
  url = Helper.new.get_url(start_date, end_date, precision)
122
- @next_page = REPORTS_URL + 'sends/' + url
122
+ @next_page = reports_url('sends/' + url)
123
123
  @data_attribute = 'sends'
124
124
  end
125
125
  end
@@ -129,7 +129,7 @@ module Urbanairship
129
129
  end_date: required('end_date'), precision: required('precision'))
130
130
  super(client: client)
131
131
  url = Helper.new.get_url(start_date, end_date, precision)
132
- @next_page = REPORTS_URL + 'responses/' + url
132
+ @next_page = reports_url('responses/' + url)
133
133
  @data_attribute = 'responses'
134
134
  end
135
135
  end
@@ -139,7 +139,7 @@ module Urbanairship
139
139
  end_date: required('end_date'), precision: required('precision'))
140
140
  super(client: client)
141
141
  url = Helper.new.get_url(start_date, end_date, precision)
142
- @next_page = REPORTS_URL + 'opens/' + url
142
+ @next_page = reports_url('opens/' + url)
143
143
  @data_attribute = 'opens'
144
144
  end
145
145
  end
@@ -149,7 +149,7 @@ module Urbanairship
149
149
  end_date: required('end_date'), precision: required('precision'))
150
150
  super(client: client)
151
151
  url = Helper.new.get_url(start_date, end_date, precision)
152
- @next_page = REPORTS_URL + 'timeinapp/' + url
152
+ @next_page = reports_url('timeinapp/' + url)
153
153
  @data_attribute = 'timeinapp'
154
154
  end
155
155
  end
@@ -1,3 +1,3 @@
1
1
  module Urbanairship
2
- VERSION = '5.9.0'
2
+ VERSION = '6.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: 5.9.0
4
+ version: 6.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: 2020-12-29 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -168,6 +168,8 @@ files:
168
168
  - lib/urbanairship/client.rb
169
169
  - lib/urbanairship/common.rb
170
170
  - lib/urbanairship/configuration.rb
171
+ - lib/urbanairship/custom_events/custom_event.rb
172
+ - lib/urbanairship/custom_events/payload.rb
171
173
  - lib/urbanairship/devices/attribute.rb
172
174
  - lib/urbanairship/devices/channel_tags.rb
173
175
  - lib/urbanairship/devices/channel_uninstall.rb