urbanairship 6.0.0 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +5 -0
- data/README.rst +91 -35
- data/lib/urbanairship/ab_tests/ab_test.rb +6 -6
- data/lib/urbanairship/automations/automation.rb +7 -7
- data/lib/urbanairship/client.rb +12 -3
- data/lib/urbanairship/common.rb +79 -60
- data/lib/urbanairship/custom_events/custom_event.rb +1 -1
- data/lib/urbanairship/devices/channel_tags.rb +2 -2
- data/lib/urbanairship/devices/channel_uninstall.rb +2 -2
- data/lib/urbanairship/devices/create_and_send.rb +3 -3
- data/lib/urbanairship/devices/devicelist.rb +7 -7
- data/lib/urbanairship/devices/email.rb +5 -5
- data/lib/urbanairship/devices/named_user.rb +6 -6
- data/lib/urbanairship/devices/open_channel.rb +3 -3
- data/lib/urbanairship/devices/segment.rb +6 -8
- data/lib/urbanairship/devices/sms.rb +5 -5
- data/lib/urbanairship/devices/static_lists.rb +7 -7
- data/lib/urbanairship/push/location.rb +17 -17
- data/lib/urbanairship/push/push.rb +4 -4
- data/lib/urbanairship/reports/response_statistics.rb +42 -31
- data/lib/urbanairship/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fffdb1489ab1f833e816db52d94b9aea7dac527f07bde6507af1dee57f491140
|
4
|
+
data.tar.gz: 2255e7731044332f60b883568929e197905a690c45d905d0a75214806163434a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c39e8417e51bd08077a8658589cdee0db2639e5e5d60e6de2596aa361e9640f16cb25ff284cfa55da044dd814b1b01001b84bc7b1c1dbcbbdc441c1dab7b6405
|
7
|
+
data.tar.gz: 209ebf90c4d266092557e387d0479ccaf8fbd3d07d05f12f78e74186c4fd0c32a00a83b306994c64de9961554cd7eb39b115dc32b5130cc9c2f564553df72eb5
|
data/CHANGELOG
CHANGED
data/README.rst
CHANGED
@@ -38,17 +38,23 @@ Installation
|
|
38
38
|
|
39
39
|
If you have the ``bundler`` gem (if not you can get it with
|
40
40
|
``$ gem install bundler``) add this line to your application's
|
41
|
-
Gemfile
|
41
|
+
Gemfile:
|
42
42
|
|
43
|
-
|
43
|
+
.. code-block::
|
44
44
|
|
45
|
-
|
45
|
+
>>> $ gem 'urbanairship'
|
46
46
|
|
47
|
-
|
47
|
+
And then execute:
|
48
48
|
|
49
|
-
|
49
|
+
.. code-block::
|
50
50
|
|
51
|
-
|
51
|
+
>>> $ bundle
|
52
|
+
|
53
|
+
OR install it yourself as:
|
54
|
+
|
55
|
+
.. code-block::
|
56
|
+
|
57
|
+
>>> $ gem install urbanairship
|
52
58
|
|
53
59
|
|
54
60
|
Configuration
|
@@ -56,28 +62,35 @@ Configuration
|
|
56
62
|
|
57
63
|
In your app initialization, you can do something like the following:
|
58
64
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
65
|
+
.. code-block:: ruby
|
66
|
+
|
67
|
+
require 'urbanairship'
|
68
|
+
|
69
|
+
Urbanairship.configure do |config|
|
70
|
+
config.server = 'go.airship.eu'
|
71
|
+
config.log_path = '/path/to/your/logfile'
|
72
|
+
config.log_level = Logger::WARN
|
73
|
+
config.timeout = 60
|
74
|
+
end
|
75
|
+
|
66
76
|
|
67
77
|
If you want to use a custom logger (e.g Rails.logger), you can do:
|
68
78
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
79
|
+
.. code-block:: ruby
|
80
|
+
|
81
|
+
require 'urbanairship'
|
82
|
+
|
83
|
+
Urbanairship.configure do |config|
|
84
|
+
config.custom_logger = Rails.logger
|
85
|
+
config.log_level = Logger::WARN
|
86
|
+
end
|
75
87
|
|
76
88
|
Available Configurations
|
77
89
|
------------------------
|
78
90
|
|
79
91
|
- **log_path**: Allows to define the folder where the log file will be created (the default is nil).
|
80
92
|
- **log_level**: Allows to define the log level and only messages at that level or higher will be printed (the default is INFO).
|
93
|
+
- **server**: Allow to define the Airship server you want to use ("go.airship.eu" or "go.urbanairship.com")
|
81
94
|
- **timeout**: Allows to define the request timeout in seconds (the default is 5).
|
82
95
|
|
83
96
|
|
@@ -97,28 +110,71 @@ information.
|
|
97
110
|
Broadcast to All Devices
|
98
111
|
------------------------
|
99
112
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
>>> p.notification = UA.notification(alert: 'Hello')
|
106
|
-
>>> p.device_types = UA.all
|
107
|
-
>>> p.send_push
|
113
|
+
.. code-block:: ruby
|
114
|
+
|
115
|
+
require 'urbanairship'
|
116
|
+
|
117
|
+
UA = Urbanairship
|
108
118
|
|
119
|
+
airship = UA::Client.new(key:'application_key', secret:'master_secret')
|
120
|
+
p = airship.create_push
|
121
|
+
p.audience = UA.all
|
122
|
+
p.notification = UA.notification(alert: 'Hello')
|
123
|
+
p.device_types = UA.all
|
124
|
+
p.send_push
|
109
125
|
|
110
126
|
Simple Tag Push
|
111
127
|
---------------
|
112
128
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
129
|
+
.. code-block:: ruby
|
130
|
+
|
131
|
+
require 'urbanairship'
|
132
|
+
|
133
|
+
UA = Urbanairship
|
134
|
+
|
135
|
+
airship = UA::Client.new(key:'application_key', secret:'master_secret')
|
136
|
+
p = airship.create_push
|
137
|
+
p.audience = UA.tag('some_tag')
|
138
|
+
p.notification = UA.notification(alert: 'Hello')
|
139
|
+
p.device_types = UA.all
|
140
|
+
p.send_push
|
141
|
+
|
142
|
+
Specify the Airship server used to make your requests
|
143
|
+
-----------------------------------------------------
|
144
|
+
By default, the request will be sent to the 'go.airship.us' server:
|
145
|
+
|
146
|
+
.. code-block:: ruby
|
147
|
+
|
148
|
+
require 'urbanairship'
|
149
|
+
|
150
|
+
Urbanairship::Client.new(key:'application_key', secret:'master_secret')
|
151
|
+
|
152
|
+
You can change the server globally in the Urbanairship configuration:
|
153
|
+
|
154
|
+
.. code-block:: ruby
|
155
|
+
|
156
|
+
require 'urbanairship'
|
157
|
+
|
158
|
+
Urbanairship.configure do |config|
|
159
|
+
config.server = 'go.airship.eu'
|
160
|
+
end
|
161
|
+
|
162
|
+
Urbanairship::Client.new(key:'application_key', secret:'master_secret')
|
163
|
+
# request will be sent to the 'go.airship.eu' server
|
164
|
+
|
165
|
+
Finally, you can change the targeted server on a request basis:
|
166
|
+
|
167
|
+
.. code-block:: ruby
|
168
|
+
|
169
|
+
require 'urbanairship'
|
170
|
+
|
171
|
+
Urbanairship.configure do |config|
|
172
|
+
config.server = 'go.airship.eu'
|
173
|
+
end
|
121
174
|
|
175
|
+
Urbanairship::Client.new(key:'application_key', secret:'master_secret', server: 'go.airship.us')
|
176
|
+
# The Urbanairship configuration is overridden by the client and the
|
177
|
+
# request will be sent to the 'go.airship.us' server
|
122
178
|
|
123
179
|
Contributing
|
124
180
|
============
|
@@ -19,7 +19,7 @@ module Urbanairship
|
|
19
19
|
def list_ab_test
|
20
20
|
response = @client.send_request(
|
21
21
|
method: 'GET',
|
22
|
-
|
22
|
+
path: experiments_path(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
|
-
|
32
|
+
path: experiments_path,
|
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
|
-
|
42
|
+
path: experiments_path('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
|
-
|
52
|
+
path: experiments_path('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
|
-
|
62
|
+
path: experiments_path('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
|
-
|
73
|
+
path: experiments_path(experiment_id)
|
74
74
|
)
|
75
75
|
logger.info("Looking up A/B test with ID #{experiment_id}")
|
76
76
|
response
|
@@ -22,7 +22,7 @@ module Urbanairship
|
|
22
22
|
response = @client.send_request(
|
23
23
|
method: 'POST',
|
24
24
|
body: JSON.dump(pipeline_object),
|
25
|
-
|
25
|
+
path: pipelines_path,
|
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
|
-
|
35
|
+
path: pipelines_path(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
|
-
|
44
|
+
path: pipelines_path('deleted' + format_url_with_params)
|
45
45
|
)
|
46
46
|
logger.info("Looking up deleted automations for project")
|
47
47
|
response
|
@@ -51,7 +51,7 @@ module Urbanairship
|
|
51
51
|
response = @client.send_request(
|
52
52
|
method: 'POST',
|
53
53
|
body: JSON.dump(pipeline_object),
|
54
|
-
|
54
|
+
path: pipelines_path('validate'),
|
55
55
|
content_type: 'application/json'
|
56
56
|
)
|
57
57
|
logger.info("Validating Automation")
|
@@ -62,7 +62,7 @@ module Urbanairship
|
|
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
|
-
|
65
|
+
path: pipelines_path(pipeline_id)
|
66
66
|
)
|
67
67
|
logger.info("Looking up automation with id #{pipeline_id}")
|
68
68
|
response
|
@@ -74,7 +74,7 @@ module Urbanairship
|
|
74
74
|
response = @client.send_request(
|
75
75
|
method: 'PUT',
|
76
76
|
body: JSON.dump(pipeline_object),
|
77
|
-
|
77
|
+
path: pipelines_path(pipeline_id),
|
78
78
|
content_type: 'application/json'
|
79
79
|
)
|
80
80
|
logger.info("Validating Automation")
|
@@ -85,7 +85,7 @@ module Urbanairship
|
|
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
|
-
|
88
|
+
path: pipelines_path(pipeline_id)
|
89
89
|
)
|
90
90
|
logger.info("Deleting automation with id #{pipeline_id}")
|
91
91
|
response
|
data/lib/urbanairship/client.rb
CHANGED
@@ -13,11 +13,15 @@ module Urbanairship
|
|
13
13
|
#
|
14
14
|
# @param [Object] key Application Key
|
15
15
|
# @param [Object] secret Application Secret
|
16
|
+
# @param [String] server Airship server to use ("go.airship.eu" or "go.urbanairship.com").
|
17
|
+
# Used only when the request is sent with a "path", not an "url".
|
16
18
|
# @param [String] token Application Auth Token (for custom events endpoint)
|
17
19
|
# @return [Object] Client
|
18
|
-
def initialize(key: required('key'), secret: required('secret'),
|
20
|
+
def initialize(key: required('key'), secret: required('secret'),
|
21
|
+
server: Urbanairship.configuration.server, token: nil)
|
19
22
|
@key = key
|
20
23
|
@secret = secret
|
24
|
+
@server = server
|
21
25
|
@token = token
|
22
26
|
end
|
23
27
|
|
@@ -25,12 +29,13 @@ module Urbanairship
|
|
25
29
|
#
|
26
30
|
# @param [Object] method HTTP Method
|
27
31
|
# @param [Object] body Request Body
|
32
|
+
# @param [Object] path Request path
|
28
33
|
# @param [Object] url Request URL
|
29
34
|
# @param [Object] content_type Content-Type
|
30
35
|
# @param [Object] encoding Encoding
|
31
36
|
# @param [Symbol] auth_type (:basic|:bearer)
|
32
37
|
# @return [Object] Push Response
|
33
|
-
def send_request(method: required('method'), url:
|
38
|
+
def send_request(method: required('method'), path: nil, url: nil, body: nil,
|
34
39
|
content_type: nil, encoding: nil, auth_type: :basic)
|
35
40
|
req_type = case method
|
36
41
|
when 'GET'
|
@@ -45,17 +50,21 @@ module Urbanairship
|
|
45
50
|
fail 'Method was not "GET" "POST" "PUT" or "DELETE"'
|
46
51
|
end
|
47
52
|
|
53
|
+
raise ArgumentError.new("path and url can't be both nil") if path.nil? && url.nil?
|
54
|
+
|
48
55
|
headers = {'User-agent' => 'UARubyLib/' + Urbanairship::VERSION}
|
49
56
|
headers['Accept'] = 'application/vnd.urbanairship+json; version=3'
|
50
57
|
headers['Content-type'] = content_type unless content_type.nil?
|
51
58
|
headers['Content-Encoding'] = encoding unless encoding.nil?
|
52
|
-
|
59
|
+
|
53
60
|
if auth_type == :bearer
|
54
61
|
raise ArgumentError.new('token must be provided as argument if auth_type=bearer') if @token.nil?
|
55
62
|
headers['X-UA-Appkey'] = @key
|
56
63
|
headers['Authorization'] = "Bearer #{@token}"
|
57
64
|
end
|
58
65
|
|
66
|
+
url = "https://#{@server}/api#{path}" unless path.nil?
|
67
|
+
|
59
68
|
debug = "Making #{method} request to #{url}.\n"+ "\tHeaders:\n"
|
60
69
|
debug += "\t\tcontent-type: #{content_type}\n" unless content_type.nil?
|
61
70
|
debug += "\t\tcontent-encoding: gzip\n" unless encoding.nil?
|
data/lib/urbanairship/common.rb
CHANGED
@@ -4,68 +4,64 @@ require 'urbanairship/loggable'
|
|
4
4
|
module Urbanairship
|
5
5
|
# Features mixed in to all classes
|
6
6
|
module Common
|
7
|
-
def
|
8
|
-
"
|
7
|
+
def apid_path(path='')
|
8
|
+
"/apids/#{path}"
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def channel_path(path='')
|
12
|
+
"/channels/#{path}"
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def create_and_send_path(path='')
|
16
|
+
"/create-and-send/#{path}"
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
|
19
|
+
def custom_events_path(path='')
|
20
|
+
"/custom-events/#{path}"
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
|
23
|
+
def device_token_path(path='')
|
24
|
+
"/device_tokens/#{path}"
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
|
27
|
+
def experiments_path(path='')
|
28
|
+
"/experiments/#{path}"
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
|
31
|
+
def lists_path(path='')
|
32
|
+
"/lists/#{path}"
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
|
35
|
+
def location_path(path='')
|
36
|
+
"/location/#{path}"
|
37
37
|
end
|
38
38
|
|
39
|
-
def
|
40
|
-
|
39
|
+
def named_users_path(path='')
|
40
|
+
"/named_users/#{path}"
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
44
|
-
|
43
|
+
def open_channel_path(path='')
|
44
|
+
"/open/#{path}"
|
45
45
|
end
|
46
46
|
|
47
|
-
def
|
48
|
-
|
47
|
+
def pipelines_path(path='')
|
48
|
+
"/pipelines/#{path}"
|
49
49
|
end
|
50
50
|
|
51
|
-
def
|
52
|
-
|
51
|
+
def push_path(path='')
|
52
|
+
"/push/#{path}"
|
53
53
|
end
|
54
54
|
|
55
|
-
def
|
56
|
-
|
55
|
+
def reports_path(path='')
|
56
|
+
"/reports/#{path}"
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
60
|
-
|
59
|
+
def schedules_path(path='')
|
60
|
+
"/schedules/#{path}"
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
def segments_url(path='')
|
68
|
-
url_for("/segments/#{path}")
|
63
|
+
def segments_path(path='')
|
64
|
+
"/segments/#{path}"
|
69
65
|
end
|
70
66
|
|
71
67
|
# Helper method for required keyword args in Ruby 2.0 that is compatible with 2.1+
|
@@ -161,36 +157,18 @@ module Urbanairship
|
|
161
157
|
|
162
158
|
def initialize(client: required('client'))
|
163
159
|
@client = client
|
164
|
-
@next_page = nil
|
165
|
-
@data_list = nil
|
166
|
-
@data_attribute = nil
|
167
160
|
@count = 0
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
response = @client.send_request(
|
173
|
-
method: 'GET',
|
174
|
-
url: @next_page
|
175
|
-
)
|
176
|
-
logger.info("Retrieving data from: #{@next_page}")
|
177
|
-
check_next_page = response['body']['next_page']
|
178
|
-
if check_next_page != @next_page
|
179
|
-
@next_page = check_next_page
|
180
|
-
elsif check_next_page
|
181
|
-
# if check_page = next_page, we have repeats in the response.
|
182
|
-
# and we don't want to load them
|
183
|
-
return false
|
184
|
-
else
|
185
|
-
@next_page = nil
|
186
|
-
end
|
187
|
-
@data_list = response['body'][@data_attribute]
|
188
|
-
true
|
161
|
+
@data_attribute = nil
|
162
|
+
@data_list = nil
|
163
|
+
@next_page_path = nil
|
164
|
+
@next_page_url = nil
|
189
165
|
end
|
190
166
|
|
191
167
|
def each
|
192
|
-
while
|
193
|
-
|
168
|
+
while @next_page_path || @next_page_url
|
169
|
+
load_page
|
170
|
+
|
171
|
+
@data_list.each do |value|
|
194
172
|
@count += 1
|
195
173
|
yield value
|
196
174
|
end
|
@@ -200,6 +178,47 @@ module Urbanairship
|
|
200
178
|
def count
|
201
179
|
@count
|
202
180
|
end
|
181
|
+
|
182
|
+
private
|
183
|
+
|
184
|
+
def load_page
|
185
|
+
logger.info("Retrieving data from: #{@next_page_url || @next_page_path}")
|
186
|
+
params = {
|
187
|
+
method: 'GET',
|
188
|
+
path: @next_page_path,
|
189
|
+
url: @next_page_url
|
190
|
+
}.select { |k, v| !v.nil? }
|
191
|
+
response = @client.send_request(params)
|
192
|
+
|
193
|
+
@data_list = get_new_data(response)
|
194
|
+
@next_page_url = get_next_page_url(response)
|
195
|
+
@next_page_path = nil
|
196
|
+
end
|
197
|
+
|
198
|
+
def extract_next_page_url(response)
|
199
|
+
response['body']['next_page']
|
200
|
+
end
|
201
|
+
|
202
|
+
def get_new_data(response)
|
203
|
+
potential_next_page_url = extract_next_page_url(response)
|
204
|
+
|
205
|
+
# if potential_next_page_url is the same as the current page, we have
|
206
|
+
# repeats in the response and we don't want to load them
|
207
|
+
return [] if potential_next_page_url && get_next_page_url(response).nil?
|
208
|
+
|
209
|
+
response['body'][@data_attribute]
|
210
|
+
end
|
211
|
+
|
212
|
+
def get_next_page_url(response)
|
213
|
+
potential_next_page_url = extract_next_page_url(response)
|
214
|
+
return nil if potential_next_page_url.nil?
|
215
|
+
|
216
|
+
# if potential_next_page_url is the same as the current page, we have
|
217
|
+
# repeats in the response and we don't want to check the next pages
|
218
|
+
return potential_next_page_url if @next_page_url && potential_next_page_url != @next_page_url
|
219
|
+
return potential_next_page_url if @next_page_path && !potential_next_page_url.end_with?(@next_page_path)
|
220
|
+
nil
|
221
|
+
end
|
203
222
|
end
|
204
223
|
end
|
205
224
|
end
|