one_signal 0.0.11 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +7 -0
- data/example.rb +54 -2
- data/lib/one_signal/notification.rb +50 -0
- data/lib/one_signal/one_signal.rb +21 -0
- data/lib/one_signal/player.rb +0 -11
- data/lib/one_signal/version.rb +1 -1
- data/test/notification_test.rb +39 -8
- data/test/one_signal_test.rb +17 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36e9569d2a051f3e9fc4e2c70439c18322c89c21
|
4
|
+
data.tar.gz: a74e6c5eeb18553a235e03132b5003f03d8da20d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f6e387073ffe3c503f5e8d1fbc520e9f06a875bef9fe1ccf9ba22be608da56af328fa1852eb09f2c67efebeaed72fa3184df1c389d0d3c3f86c1b158a759a07
|
7
|
+
data.tar.gz: 23cc0acb614002fbee84cf298bd46a9e29e115c4b2cc9817ce9cfad2a73e24398dbfbe8d5bad5fef2c363bc400ae293c9c3121cefe056787f7a9c3ca2031c607
|
data/CHANGELOG.txt
CHANGED
data/example.rb
CHANGED
@@ -125,6 +125,44 @@ def update_player(id:)
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
+
def all_notifs
|
129
|
+
params = {
|
130
|
+
app_id: @app_id,
|
131
|
+
limit: 5,
|
132
|
+
offset: 0
|
133
|
+
}
|
134
|
+
|
135
|
+
begin
|
136
|
+
response = OneSignal::Notification.all(params: params)
|
137
|
+
puts "code : #{response.code}"
|
138
|
+
puts "message : #{response.message}"
|
139
|
+
puts "body : #{response.body}"
|
140
|
+
puts "id : #{JSON.parse(response.body).class}"
|
141
|
+
rescue OneSignal::OneSignalError => e
|
142
|
+
puts "-- message : #{e.message}"
|
143
|
+
puts "-- status : #{e.http_status}"
|
144
|
+
puts "-- body : #{e.http_body}"
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def get_notif(id:)
|
149
|
+
params = {
|
150
|
+
app_id: @app_id
|
151
|
+
}
|
152
|
+
|
153
|
+
begin
|
154
|
+
response = OneSignal::Notification.get(id: id, params: params)
|
155
|
+
puts "code : #{response.code}"
|
156
|
+
puts "message : #{response.message}"
|
157
|
+
puts "body : #{response.body}"
|
158
|
+
puts "id : #{JSON.parse(response.body).class}"
|
159
|
+
rescue OneSignal::OneSignalError => e
|
160
|
+
puts "-- message : #{e.message}"
|
161
|
+
puts "-- status : #{e.http_status}"
|
162
|
+
puts "-- body : #{e.http_body}"
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
128
166
|
def notify
|
129
167
|
params = {
|
130
168
|
app_id: @app_id,
|
@@ -181,13 +219,27 @@ def get_player(id:)
|
|
181
219
|
puts response.body
|
182
220
|
end
|
183
221
|
|
222
|
+
def update_notif(id:)
|
223
|
+
params = {
|
224
|
+
app_id: @app_id,
|
225
|
+
opened: true
|
226
|
+
}
|
227
|
+
response = OneSignal::Notification.update(id: id, params: params)
|
228
|
+
puts response.body
|
229
|
+
end
|
230
|
+
|
184
231
|
# player_id = create_player
|
185
232
|
# update_player(id: player_id)
|
186
233
|
player_id = '9c9a3fb4-62e0-455d-865b-670ccea594a1'
|
234
|
+
notification_id = 'c6e10bac-af7d-4879-a5e9-439de53e3cff'
|
187
235
|
# create_player_session(id: player_id)
|
188
236
|
# create_player_purchase(id: player_id)
|
189
|
-
create_player_focus(id: player_id)
|
237
|
+
# create_player_focus(id: player_id)
|
190
238
|
# notify
|
191
239
|
# csv_export
|
192
240
|
# all_players
|
193
|
-
get_player(id: player_id)
|
241
|
+
# get_player(id: player_id)
|
242
|
+
# all_notifs
|
243
|
+
get_notif(id: notification_id)
|
244
|
+
update_notif(id: notification_id)
|
245
|
+
get_notif(id: notification_id)
|
@@ -2,6 +2,39 @@ module OneSignal
|
|
2
2
|
|
3
3
|
class Notification < OneSignal
|
4
4
|
|
5
|
+
def self.all(params: {})
|
6
|
+
uri_string = @@base_uri
|
7
|
+
uri_string += "/notifications"
|
8
|
+
uri = URI.parse(uri_string)
|
9
|
+
|
10
|
+
response = send_get_request(uri: uri, params: params)
|
11
|
+
|
12
|
+
ensure_http_status(response: response,
|
13
|
+
status: '200',
|
14
|
+
method_name: 'All',
|
15
|
+
uri: uri,
|
16
|
+
params: params)
|
17
|
+
|
18
|
+
return response
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.get(id:, params:)
|
22
|
+
uri_string = @@base_uri
|
23
|
+
uri_string += "/notifications"
|
24
|
+
uri_string += "/#{id}"
|
25
|
+
uri = URI.parse(uri_string)
|
26
|
+
|
27
|
+
response = send_get_request(uri: uri, params: params)
|
28
|
+
|
29
|
+
ensure_http_status(response: response,
|
30
|
+
status: '200',
|
31
|
+
method_name: 'Get',
|
32
|
+
uri: uri,
|
33
|
+
params: nil)
|
34
|
+
|
35
|
+
return response
|
36
|
+
end
|
37
|
+
|
5
38
|
def self.create(params: {})
|
6
39
|
uri_string = @@base_uri
|
7
40
|
uri_string += "/notifications"
|
@@ -16,6 +49,23 @@ module OneSignal
|
|
16
49
|
return response
|
17
50
|
end
|
18
51
|
|
52
|
+
def self.update(id:, params: {})
|
53
|
+
uri_string = @@base_uri
|
54
|
+
uri_string += "/notifications"
|
55
|
+
uri_string += "/#{id}"
|
56
|
+
uri = URI.parse(uri_string)
|
57
|
+
|
58
|
+
response = send_put_request(uri: uri, body: params)
|
59
|
+
|
60
|
+
ensure_http_status(response: response,
|
61
|
+
status: '200',
|
62
|
+
method_name: 'Update',
|
63
|
+
uri: uri,
|
64
|
+
params: params)
|
65
|
+
|
66
|
+
return response
|
67
|
+
end
|
68
|
+
|
19
69
|
private
|
20
70
|
|
21
71
|
def self.handle_error(uri:, params:, response:)
|
@@ -54,6 +54,18 @@ module OneSignal
|
|
54
54
|
response = http.request(request)
|
55
55
|
end
|
56
56
|
|
57
|
+
def self.send_delete_request(uri:, body:)
|
58
|
+
ensure_api_key
|
59
|
+
|
60
|
+
request = Net::HTTP::Delete.new(uri.request_uri)
|
61
|
+
request.body = body.to_json
|
62
|
+
request = request_with_headers(request: request)
|
63
|
+
|
64
|
+
http = http_object(uri: uri)
|
65
|
+
|
66
|
+
response = http.request(request)
|
67
|
+
end
|
68
|
+
|
57
69
|
def self.send_put_request(uri:, body:)
|
58
70
|
ensure_api_key
|
59
71
|
|
@@ -80,6 +92,15 @@ module OneSignal
|
|
80
92
|
|
81
93
|
private
|
82
94
|
|
95
|
+
def self.ensure_http_status(response:, status:, method_name:, uri:, params:)
|
96
|
+
if response.code != status.to_s
|
97
|
+
msg = "#{method_name} error - uri: #{uri} params: #{params}"
|
98
|
+
raise OneSignalError.new(message: msg,
|
99
|
+
http_status: response.code,
|
100
|
+
http_body: response.body)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
83
104
|
def self.ensure_api_key
|
84
105
|
unless @@api_key && !@@api_key.strip.empty?
|
85
106
|
msg = "No API key provided"
|
data/lib/one_signal/player.rb
CHANGED
@@ -138,17 +138,6 @@ module OneSignal
|
|
138
138
|
return response
|
139
139
|
end
|
140
140
|
|
141
|
-
private
|
142
|
-
|
143
|
-
def self.ensure_http_status(response:, status:, method_name:, uri:, params:)
|
144
|
-
if response.code != status.to_s
|
145
|
-
msg = "#{method_name} Player error - uri: #{uri} params: #{params}"
|
146
|
-
raise OneSignalError.new(message: msg,
|
147
|
-
http_status: response.code,
|
148
|
-
http_body: response.body)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
141
|
end
|
153
142
|
|
154
143
|
end
|
data/lib/one_signal/version.rb
CHANGED
data/test/notification_test.rb
CHANGED
@@ -3,8 +3,13 @@ require File.dirname(__FILE__) + '/helper'
|
|
3
3
|
class NotificationTest < MiniTest::Test
|
4
4
|
|
5
5
|
def setup
|
6
|
-
@
|
7
|
-
|
6
|
+
@notification_id = "fake-id-123"
|
7
|
+
base_url = "https://onesignal.com/api/v1/notifications"
|
8
|
+
@create_uri = URI.parse(base_url)
|
9
|
+
@update_uri = URI.parse(base_url + "/#{@notification_id}")
|
10
|
+
@all_uri = URI.parse(base_url)
|
11
|
+
@get_uri = URI.parse(base_url + "/#{@notification_id}")
|
12
|
+
@params = {
|
8
13
|
foo: "bar",
|
9
14
|
widget: "acme"
|
10
15
|
}
|
@@ -12,32 +17,58 @@ class NotificationTest < MiniTest::Test
|
|
12
17
|
OneSignal::OneSignal.api_key = @api_key
|
13
18
|
end
|
14
19
|
|
20
|
+
def test_all
|
21
|
+
response = mock_response_ok
|
22
|
+
OneSignal::OneSignal.expects(:send_get_request)
|
23
|
+
.with(uri: @all_uri, params: @params)
|
24
|
+
.returns(response)
|
25
|
+
assert_equal response, OneSignal::Notification.all(params: @params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_get
|
29
|
+
response = mock_response_ok
|
30
|
+
OneSignal::OneSignal.expects(:send_get_request)
|
31
|
+
.with(uri: @get_uri, params: @params)
|
32
|
+
.returns(response)
|
33
|
+
assert_equal response, OneSignal::Notification.get(id: @notification_id,
|
34
|
+
params: @params)
|
35
|
+
end
|
36
|
+
|
15
37
|
def test_create_raises_onesignal_error
|
16
38
|
response = mock_response_ko
|
17
39
|
OneSignal::OneSignal.expects(:send_post_request)
|
18
|
-
.with(uri: @
|
40
|
+
.with(uri: @create_uri, body: @params)
|
19
41
|
.returns(response)
|
20
42
|
assert_raises OneSignal::OneSignalError do
|
21
|
-
OneSignal::Notification.create(params: @
|
43
|
+
OneSignal::Notification.create(params: @params)
|
22
44
|
end
|
23
45
|
end
|
24
46
|
|
25
47
|
def test_create_raises_no_recipients_error
|
26
48
|
response = mock_response_no_recipients
|
27
49
|
OneSignal::OneSignal.expects(:send_post_request)
|
28
|
-
.with(uri: @
|
50
|
+
.with(uri: @create_uri, body: @params)
|
29
51
|
.returns(response)
|
30
52
|
assert_raises OneSignal::NoRecipientsError do
|
31
|
-
OneSignal::Notification.create(params: @
|
53
|
+
OneSignal::Notification.create(params: @params)
|
32
54
|
end
|
33
55
|
end
|
34
56
|
|
35
57
|
def test_create
|
36
58
|
response = mock_response_ok
|
37
59
|
OneSignal::OneSignal.expects(:send_post_request)
|
38
|
-
.with(uri: @
|
60
|
+
.with(uri: @create_uri, body: @params)
|
61
|
+
.returns(response)
|
62
|
+
assert_equal response, OneSignal::Notification.create(params: @params)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_update
|
66
|
+
response = mock_response_ok
|
67
|
+
OneSignal::OneSignal.expects(:send_put_request)
|
68
|
+
.with(uri: @update_uri, body: @params)
|
39
69
|
.returns(response)
|
40
|
-
assert_equal response, OneSignal::Notification.
|
70
|
+
assert_equal response, OneSignal::Notification.update(id: @notification_id,
|
71
|
+
params: @params)
|
41
72
|
end
|
42
73
|
|
43
74
|
end
|
data/test/one_signal_test.rb
CHANGED
@@ -104,6 +104,23 @@ class OneSignalTest < MiniTest::Test
|
|
104
104
|
assert_equal response, OneSignal::OneSignal.send_post_request(uri: @uri, body: @body)
|
105
105
|
end
|
106
106
|
|
107
|
+
def test_send_delete_request
|
108
|
+
# test request creation
|
109
|
+
request = build_mock_request(body: @body)
|
110
|
+
Net::HTTP::Delete.expects(:new).with(@uri.request_uri).returns(request)
|
111
|
+
|
112
|
+
# test http object creation
|
113
|
+
http = build_mock_http_object
|
114
|
+
Net::HTTP.expects(:new).with(@uri.host, @uri.port).returns(http)
|
115
|
+
|
116
|
+
# test send request
|
117
|
+
response = mock()
|
118
|
+
http.expects(:request).with(request).returns(response)
|
119
|
+
|
120
|
+
OneSignal::OneSignal.api_key = @api_key
|
121
|
+
assert_equal response, OneSignal::OneSignal.send_delete_request(uri: @uri, body: @body)
|
122
|
+
end
|
123
|
+
|
107
124
|
def test_send_put_request
|
108
125
|
# test request creation
|
109
126
|
request = build_mock_request(body: @body)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: one_signal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Balthazar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|