one_signal 0.0.14 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.env.example +2 -0
- data/.github/workflows/ci.yml +24 -0
- data/CHANGELOG.txt +16 -0
- data/LICENSE +158 -668
- data/README.md +27 -5
- data/example.rb +42 -298
- data/lib/one_signal/app.rb +16 -14
- data/lib/one_signal/notification.rb +33 -18
- data/lib/one_signal/one_signal.rb +32 -20
- data/lib/one_signal/player.rb +52 -17
- data/lib/one_signal/version.rb +1 -1
- data/one_signal.gemspec +2 -3
- data/test/app_test.rb +47 -6
- data/test/helper.rb +1 -1
- data/test/notification_test.rb +64 -8
- data/test/one_signal_test.rb +17 -14
- data/test/player_test.rb +114 -13
- metadata +11 -25
- data/.travis.yml +0 -5
data/test/helper.rb
CHANGED
data/test/notification_test.rb
CHANGED
@@ -10,35 +10,63 @@ class NotificationTest < MiniTest::Test
|
|
10
10
|
@delete_uri = URI.parse(base_url + "/#{@notification_id}")
|
11
11
|
@all_uri = URI.parse(base_url)
|
12
12
|
@get_uri = URI.parse(base_url + "/#{@notification_id}")
|
13
|
+
@api_key = "fake api key 123"
|
14
|
+
@api_key_2 = "fake api key 456"
|
13
15
|
@params = {
|
14
16
|
foo: "bar",
|
15
17
|
widget: "acme"
|
16
18
|
}
|
17
|
-
@
|
19
|
+
@opts = {
|
20
|
+
key1: "value1",
|
21
|
+
key2: "vaue2",
|
22
|
+
auth_key: @api_key_2
|
23
|
+
}
|
24
|
+
@default_opts = {
|
25
|
+
auth_key: @api_key
|
26
|
+
}
|
18
27
|
OneSignal::OneSignal.api_key = @api_key
|
19
28
|
end
|
20
29
|
|
21
30
|
def test_all
|
22
31
|
response = mock_response_ok
|
23
32
|
OneSignal::OneSignal.expects(:send_get_request)
|
24
|
-
.with(uri: @all_uri, params: @params)
|
33
|
+
.with(uri: @all_uri, params: @params, opts: @default_opts)
|
25
34
|
.returns(response)
|
26
35
|
assert_equal response, OneSignal::Notification.all(params: @params)
|
27
36
|
end
|
28
37
|
|
38
|
+
def test_all_with_auth_key
|
39
|
+
response = mock_response_ok
|
40
|
+
OneSignal::OneSignal.expects(:send_get_request)
|
41
|
+
.with(uri: @all_uri, params: @params, opts: @opts)
|
42
|
+
.returns(response)
|
43
|
+
assert_equal response, OneSignal::Notification.all(params: @params,
|
44
|
+
opts: @opts)
|
45
|
+
end
|
46
|
+
|
29
47
|
def test_get
|
30
48
|
response = mock_response_ok
|
31
49
|
OneSignal::OneSignal.expects(:send_get_request)
|
32
|
-
.with(uri: @get_uri, params: @params)
|
50
|
+
.with(uri: @get_uri, params: @params, opts: @default_opts)
|
33
51
|
.returns(response)
|
34
52
|
assert_equal response, OneSignal::Notification.get(id: @notification_id,
|
35
53
|
params: @params)
|
36
54
|
end
|
37
55
|
|
56
|
+
def test_get_with_auth_key
|
57
|
+
response = mock_response_ok
|
58
|
+
OneSignal::OneSignal.expects(:send_get_request)
|
59
|
+
.with(uri: @get_uri, params: @params, opts: @opts)
|
60
|
+
.returns(response)
|
61
|
+
assert_equal response, OneSignal::Notification.get(id: @notification_id,
|
62
|
+
params: @params,
|
63
|
+
opts: @opts)
|
64
|
+
end
|
65
|
+
|
38
66
|
def test_create_raises_onesignal_error
|
39
67
|
response = mock_response_ko
|
40
68
|
OneSignal::OneSignal.expects(:send_post_request)
|
41
|
-
.with(uri: @create_uri, body: @params)
|
69
|
+
.with(uri: @create_uri, body: @params, opts: @default_opts)
|
42
70
|
.returns(response)
|
43
71
|
assert_raises OneSignal::OneSignalError do
|
44
72
|
OneSignal::Notification.create(params: @params)
|
@@ -48,7 +76,7 @@ class NotificationTest < MiniTest::Test
|
|
48
76
|
def test_create_raises_no_recipients_error
|
49
77
|
response = mock_response_no_recipients
|
50
78
|
OneSignal::OneSignal.expects(:send_post_request)
|
51
|
-
.with(uri: @create_uri, body: @params)
|
79
|
+
.with(uri: @create_uri, body: @params, opts: @default_opts)
|
52
80
|
.returns(response)
|
53
81
|
assert_raises OneSignal::NoRecipientsError do
|
54
82
|
OneSignal::Notification.create(params: @params)
|
@@ -58,27 +86,55 @@ class NotificationTest < MiniTest::Test
|
|
58
86
|
def test_create
|
59
87
|
response = mock_response_ok
|
60
88
|
OneSignal::OneSignal.expects(:send_post_request)
|
61
|
-
.with(uri: @create_uri, body: @params)
|
89
|
+
.with(uri: @create_uri, body: @params, opts: @default_opts)
|
62
90
|
.returns(response)
|
63
91
|
assert_equal response, OneSignal::Notification.create(params: @params)
|
64
92
|
end
|
65
93
|
|
94
|
+
def test_create_with_auth_key
|
95
|
+
response = mock_response_ok
|
96
|
+
OneSignal::OneSignal.expects(:send_post_request)
|
97
|
+
.with(uri: @create_uri, body: @params, opts: @opts)
|
98
|
+
.returns(response)
|
99
|
+
assert_equal response, OneSignal::Notification.create(params: @params, opts: @opts)
|
100
|
+
end
|
101
|
+
|
66
102
|
def test_update
|
67
103
|
response = mock_response_ok
|
68
104
|
OneSignal::OneSignal.expects(:send_put_request)
|
69
|
-
.with(uri: @update_uri, body: @params)
|
105
|
+
.with(uri: @update_uri, body: @params, opts: @default_opts)
|
70
106
|
.returns(response)
|
71
107
|
assert_equal response, OneSignal::Notification.update(id: @notification_id,
|
72
108
|
params: @params)
|
73
109
|
end
|
74
110
|
|
111
|
+
def test_update_with_auth_key
|
112
|
+
response = mock_response_ok
|
113
|
+
OneSignal::OneSignal.expects(:send_put_request)
|
114
|
+
.with(uri: @update_uri, body: @params, opts: @opts)
|
115
|
+
.returns(response)
|
116
|
+
assert_equal response, OneSignal::Notification.update(id: @notification_id,
|
117
|
+
params: @params,
|
118
|
+
opts: @opts)
|
119
|
+
end
|
120
|
+
|
75
121
|
def test_delete
|
76
122
|
response = mock_response_ok
|
77
123
|
OneSignal::OneSignal.expects(:send_delete_request)
|
78
|
-
.with(uri: @delete_uri, params: @params)
|
124
|
+
.with(uri: @delete_uri, params: @params, opts: @default_opts)
|
79
125
|
.returns(response)
|
80
126
|
assert_equal response, OneSignal::Notification.delete(id: @notification_id,
|
81
127
|
params: @params)
|
82
128
|
end
|
83
129
|
|
130
|
+
def test_delete_with_auth_key
|
131
|
+
response = mock_response_ok
|
132
|
+
OneSignal::OneSignal.expects(:send_delete_request)
|
133
|
+
.with(uri: @delete_uri, params: @params, opts: @opts)
|
134
|
+
.returns(response)
|
135
|
+
assert_equal response, OneSignal::Notification.delete(id: @notification_id,
|
136
|
+
params: @params,
|
137
|
+
opts: @opts)
|
138
|
+
end
|
139
|
+
|
84
140
|
end
|
data/test/one_signal_test.rb
CHANGED
@@ -6,6 +6,7 @@ class OneSignalTest < MiniTest::Test
|
|
6
6
|
@api_key = "fake_api_123"
|
7
7
|
@body = "fake body"
|
8
8
|
@params = {foo: 'bar', widget: 'acme'}
|
9
|
+
@opts = {auth_key: @api_key}
|
9
10
|
@uri = URI.parse("https://www.example.com/foo/bar")
|
10
11
|
@default_timeout = 30
|
11
12
|
end
|
@@ -16,11 +17,11 @@ class OneSignalTest < MiniTest::Test
|
|
16
17
|
OneSignal::OneSignal.read_timeout = @default_timeout
|
17
18
|
end
|
18
19
|
|
19
|
-
def build_mock_request(body: nil)
|
20
|
+
def build_mock_request(body: nil, auth_key: nil)
|
20
21
|
request = mock()
|
21
22
|
request.expects(:body=).with(body.to_json) unless body.nil?
|
22
23
|
request.expects(:add_field).with("Content-Type", "application/json")
|
23
|
-
request.expects(:add_field).with("Authorization", "Basic #{
|
24
|
+
request.expects(:add_field).with("Authorization", "Basic #{auth_key}")
|
24
25
|
return request
|
25
26
|
end
|
26
27
|
|
@@ -67,7 +68,7 @@ class OneSignalTest < MiniTest::Test
|
|
67
68
|
|
68
69
|
def test_send_post_request
|
69
70
|
# test request creation
|
70
|
-
request = build_mock_request(body: @body)
|
71
|
+
request = build_mock_request(body: @body, auth_key: @api_key)
|
71
72
|
Net::HTTP::Post.expects(:new).with(@uri.request_uri).returns(request)
|
72
73
|
|
73
74
|
# test http object creation
|
@@ -78,8 +79,9 @@ class OneSignalTest < MiniTest::Test
|
|
78
79
|
response = mock()
|
79
80
|
http.expects(:request).with(request).returns(response)
|
80
81
|
|
81
|
-
OneSignal::OneSignal.
|
82
|
-
|
82
|
+
assert_equal response, OneSignal::OneSignal.send_post_request(uri: @uri,
|
83
|
+
body: @body,
|
84
|
+
opts: @opts)
|
83
85
|
end
|
84
86
|
|
85
87
|
def test_send_delete_request
|
@@ -87,7 +89,7 @@ class OneSignalTest < MiniTest::Test
|
|
87
89
|
expected_uri.query = URI.encode_www_form(@params)
|
88
90
|
|
89
91
|
# test request creation
|
90
|
-
request = build_mock_request
|
92
|
+
request = build_mock_request(auth_key: @api_key)
|
91
93
|
Net::HTTP::Delete.expects(:new).with(expected_uri.request_uri).returns(request)
|
92
94
|
|
93
95
|
# test http object creation
|
@@ -98,14 +100,14 @@ class OneSignalTest < MiniTest::Test
|
|
98
100
|
response = mock()
|
99
101
|
http.expects(:request).with(request).returns(response)
|
100
102
|
|
101
|
-
OneSignal::OneSignal.api_key = @api_key
|
102
103
|
assert_equal response, OneSignal::OneSignal.send_delete_request(uri: @uri,
|
103
|
-
|
104
|
+
params: @params,
|
105
|
+
opts: @opts)
|
104
106
|
end
|
105
107
|
|
106
108
|
def test_send_put_request
|
107
109
|
# test request creation
|
108
|
-
request = build_mock_request(body: @body)
|
110
|
+
request = build_mock_request(body: @body, auth_key: @api_key)
|
109
111
|
Net::HTTP::Put.expects(:new).with(@uri.request_uri).returns(request)
|
110
112
|
|
111
113
|
# test http object creation
|
@@ -116,8 +118,9 @@ class OneSignalTest < MiniTest::Test
|
|
116
118
|
response = mock()
|
117
119
|
http.expects(:request).with(request).returns(response)
|
118
120
|
|
119
|
-
OneSignal::OneSignal.
|
120
|
-
|
121
|
+
assert_equal response, OneSignal::OneSignal.send_put_request(uri: @uri,
|
122
|
+
body: @body,
|
123
|
+
opts: @opts)
|
121
124
|
end
|
122
125
|
|
123
126
|
def test_send_get_request
|
@@ -125,7 +128,7 @@ class OneSignalTest < MiniTest::Test
|
|
125
128
|
expected_uri.query = URI.encode_www_form(@params)
|
126
129
|
|
127
130
|
# test request creation
|
128
|
-
request = build_mock_request
|
131
|
+
request = build_mock_request(auth_key: @api_key)
|
129
132
|
Net::HTTP::Get.expects(:new).with(expected_uri.request_uri).returns(request)
|
130
133
|
|
131
134
|
# test http object creation
|
@@ -136,9 +139,9 @@ class OneSignalTest < MiniTest::Test
|
|
136
139
|
response = mock()
|
137
140
|
http.expects(:request).with(request).returns(response)
|
138
141
|
|
139
|
-
OneSignal::OneSignal.api_key = @api_key
|
140
142
|
assert_equal response, OneSignal::OneSignal.send_get_request(uri: @uri,
|
141
|
-
params: @params
|
143
|
+
params: @params,
|
144
|
+
opts: @opts)
|
142
145
|
end
|
143
146
|
|
144
147
|
end
|
data/test/player_test.rb
CHANGED
@@ -10,6 +10,7 @@ class PlayerTest < MiniTest::Test
|
|
10
10
|
@player_id = "fake-id-123"
|
11
11
|
@get_uri = URI.parse(base_url + "/#{@player_id}")
|
12
12
|
@update_uri = URI.parse(base_url + "/#{@player_id}")
|
13
|
+
@delete_uri = URI.parse(base_url + "/#{@player_id}")
|
13
14
|
@create_session_uri = URI.parse(base_url + "/#{@player_id}/on_session")
|
14
15
|
@create_purchase_uri = URI.parse(base_url + "/#{@player_id}/on_purchase")
|
15
16
|
@create_focus_uri = URI.parse(base_url + "/#{@player_id}/on_focus")
|
@@ -18,14 +19,23 @@ class PlayerTest < MiniTest::Test
|
|
18
19
|
foo: "bar",
|
19
20
|
widget: "acme"
|
20
21
|
}
|
21
|
-
@api_key = "fake api key"
|
22
|
+
@api_key = "fake api key 123"
|
23
|
+
@api_key_2 = "fake api key 456"
|
24
|
+
@opts = {
|
25
|
+
key1: "value1",
|
26
|
+
key2: "vaue2",
|
27
|
+
auth_key: @api_key_2
|
28
|
+
}
|
29
|
+
@default_opts = {
|
30
|
+
auth_key: @api_key
|
31
|
+
}
|
22
32
|
OneSignal::OneSignal.api_key = @api_key
|
23
33
|
end
|
24
34
|
|
25
35
|
def test_create_raises_error
|
26
36
|
response = mock_response_ko
|
27
37
|
OneSignal::OneSignal.expects(:send_post_request)
|
28
|
-
.with(uri: @create_uri, body: @params)
|
38
|
+
.with(uri: @create_uri, body: @params, opts: @default_opts)
|
29
39
|
.returns(response)
|
30
40
|
assert_raises OneSignal::OneSignalError do
|
31
41
|
OneSignal::Player.create(params: @params)
|
@@ -33,42 +43,73 @@ class PlayerTest < MiniTest::Test
|
|
33
43
|
end
|
34
44
|
|
35
45
|
def test_csv_export
|
36
|
-
@app_id = "foobar"
|
37
46
|
response = mock_response_ok
|
38
47
|
OneSignal::OneSignal.expects(:send_post_request)
|
39
|
-
.with(uri: @csv_export_uri, body:
|
48
|
+
.with(uri: @csv_export_uri, body: @params, opts: @default_opts)
|
49
|
+
.returns(response)
|
50
|
+
assert_equal response, OneSignal::Player.csv_export(params: @params)
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_csv_export_with_auth_key
|
54
|
+
response = mock_response_ok
|
55
|
+
OneSignal::OneSignal.expects(:send_post_request)
|
56
|
+
.with(uri: @csv_export_uri, body: @params, opts: @opts)
|
40
57
|
.returns(response)
|
41
|
-
assert_equal response, OneSignal::Player.csv_export(
|
58
|
+
assert_equal response, OneSignal::Player.csv_export(params: @params, opts: @opts)
|
42
59
|
end
|
43
60
|
|
44
61
|
def test_all
|
45
62
|
response = mock_response_ok
|
46
63
|
OneSignal::OneSignal.expects(:send_get_request)
|
47
|
-
.with(uri: @all_uri, params: @params)
|
64
|
+
.with(uri: @all_uri, params: @params, opts: @default_opts)
|
48
65
|
.returns(response)
|
49
66
|
assert_equal response, OneSignal::Player.all(params: @params)
|
50
67
|
end
|
51
68
|
|
69
|
+
def test_all_with_auth_key
|
70
|
+
response = mock_response_ok
|
71
|
+
OneSignal::OneSignal.expects(:send_get_request)
|
72
|
+
.with(uri: @all_uri, params: @params, opts: @opts)
|
73
|
+
.returns(response)
|
74
|
+
assert_equal response, OneSignal::Player.all(params: @params, opts: @opts)
|
75
|
+
end
|
76
|
+
|
52
77
|
def test_get
|
53
78
|
response = mock_response_ok
|
54
79
|
OneSignal::OneSignal.expects(:send_get_request)
|
55
|
-
.with(uri: @get_uri, params: nil)
|
80
|
+
.with(uri: @get_uri, params: nil, opts: @default_opts)
|
56
81
|
.returns(response)
|
57
82
|
assert_equal response, OneSignal::Player.get(id: @player_id)
|
58
83
|
end
|
59
84
|
|
85
|
+
def test_get_with_auth_key
|
86
|
+
response = mock_response_ok
|
87
|
+
OneSignal::OneSignal.expects(:send_get_request)
|
88
|
+
.with(uri: @get_uri, params: nil, opts: @opts)
|
89
|
+
.returns(response)
|
90
|
+
assert_equal response, OneSignal::Player.get(id: @player_id, opts: @opts)
|
91
|
+
end
|
92
|
+
|
60
93
|
def test_create
|
61
94
|
response = mock_response_ok
|
62
95
|
OneSignal::OneSignal.expects(:send_post_request)
|
63
|
-
.with(uri: @create_uri, body: @params)
|
96
|
+
.with(uri: @create_uri, body: @params, opts: @default_opts)
|
64
97
|
.returns(response)
|
65
98
|
assert_equal response, OneSignal::Player.create(params: @params)
|
66
99
|
end
|
67
100
|
|
101
|
+
def test_create_with_auth_key
|
102
|
+
response = mock_response_ok
|
103
|
+
OneSignal::OneSignal.expects(:send_post_request)
|
104
|
+
.with(uri: @create_uri, body: @params, opts: @opts)
|
105
|
+
.returns(response)
|
106
|
+
assert_equal response, OneSignal::Player.create(params: @params, opts: @opts)
|
107
|
+
end
|
108
|
+
|
68
109
|
def test_update_raises_error
|
69
110
|
response = mock_response_ko
|
70
111
|
OneSignal::OneSignal.expects(:send_put_request)
|
71
|
-
.with(uri: @update_uri, body: @params)
|
112
|
+
.with(uri: @update_uri, body: @params, opts: @default_opts)
|
72
113
|
.returns(response)
|
73
114
|
assert_raises OneSignal::OneSignalError do
|
74
115
|
OneSignal::Player.update(id: @player_id, params: @params)
|
@@ -78,36 +119,96 @@ class PlayerTest < MiniTest::Test
|
|
78
119
|
def test_update
|
79
120
|
response = mock_response_ok
|
80
121
|
OneSignal::OneSignal.expects(:send_put_request)
|
81
|
-
.with(uri: @update_uri, body: @params)
|
122
|
+
.with(uri: @update_uri, body: @params, opts: @default_opts)
|
82
123
|
.returns(response)
|
83
124
|
assert_equal response, OneSignal::Player.update(id: @player_id, params: @params)
|
84
125
|
end
|
85
126
|
|
127
|
+
def test_update_with_auth_key
|
128
|
+
response = mock_response_ok
|
129
|
+
OneSignal::OneSignal.expects(:send_put_request)
|
130
|
+
.with(uri: @update_uri, body: @params, opts: @opts)
|
131
|
+
.returns(response)
|
132
|
+
assert_equal response, OneSignal::Player.update(id: @player_id,
|
133
|
+
params: @params,
|
134
|
+
opts: @opts)
|
135
|
+
end
|
136
|
+
|
86
137
|
def test_create_session
|
87
138
|
response = mock_response_ok
|
88
139
|
OneSignal::OneSignal.expects(:send_post_request)
|
89
|
-
.with(uri: @create_session_uri, body: @params)
|
140
|
+
.with(uri: @create_session_uri, body: @params, opts: @default_opts)
|
90
141
|
.returns(response)
|
91
142
|
assert_equal response, OneSignal::Player.create_session(id: @player_id,
|
92
143
|
params: @params)
|
93
144
|
end
|
94
145
|
|
146
|
+
def test_create_session_with_auth_key
|
147
|
+
response = mock_response_ok
|
148
|
+
OneSignal::OneSignal.expects(:send_post_request)
|
149
|
+
.with(uri: @create_session_uri, body: @params, opts: @opts)
|
150
|
+
.returns(response)
|
151
|
+
assert_equal response, OneSignal::Player.create_session(id: @player_id,
|
152
|
+
params: @params,
|
153
|
+
opts: @opts)
|
154
|
+
end
|
155
|
+
|
95
156
|
def test_create_purchase
|
96
157
|
response = mock_response_ok
|
97
158
|
OneSignal::OneSignal.expects(:send_post_request)
|
98
|
-
.with(uri: @create_purchase_uri,
|
159
|
+
.with(uri: @create_purchase_uri,
|
160
|
+
body: @params,
|
161
|
+
opts: @default_opts)
|
99
162
|
.returns(response)
|
100
163
|
assert_equal response, OneSignal::Player.create_purchase(id: @player_id,
|
101
164
|
params: @params)
|
102
165
|
end
|
103
166
|
|
167
|
+
def test_create_purchase_with_auth_key
|
168
|
+
response = mock_response_ok
|
169
|
+
OneSignal::OneSignal.expects(:send_post_request)
|
170
|
+
.with(uri: @create_purchase_uri,
|
171
|
+
body: @params,
|
172
|
+
opts: @opts)
|
173
|
+
.returns(response)
|
174
|
+
assert_equal response, OneSignal::Player.create_purchase(id: @player_id,
|
175
|
+
params: @params,
|
176
|
+
opts: @opts)
|
177
|
+
end
|
178
|
+
|
104
179
|
def test_create_focus
|
105
180
|
response = mock_response_ok
|
106
181
|
OneSignal::OneSignal.expects(:send_post_request)
|
107
|
-
.with(uri: @create_focus_uri, body: @params)
|
182
|
+
.with(uri: @create_focus_uri, body: @params, opts: @default_opts)
|
108
183
|
.returns(response)
|
109
184
|
assert_equal response, OneSignal::Player.create_focus(id: @player_id,
|
110
185
|
params: @params)
|
111
186
|
end
|
112
187
|
|
188
|
+
def test_create_focus_with_auth_key
|
189
|
+
response = mock_response_ok
|
190
|
+
OneSignal::OneSignal.expects(:send_post_request)
|
191
|
+
.with(uri: @create_focus_uri, body: @params, opts: @opts)
|
192
|
+
.returns(response)
|
193
|
+
assert_equal response, OneSignal::Player.create_focus(id: @player_id,
|
194
|
+
params: @params,
|
195
|
+
opts: @opts)
|
196
|
+
end
|
197
|
+
|
198
|
+
def test_delete
|
199
|
+
response = mock_response_ok
|
200
|
+
OneSignal::OneSignal.expects(:send_delete_request)
|
201
|
+
.with(uri: @delete_uri, params: nil, opts: @default_opts)
|
202
|
+
.returns(response)
|
203
|
+
assert_equal response, OneSignal::Player.delete(id: @player_id)
|
204
|
+
end
|
205
|
+
|
206
|
+
def test_delete_with_auth_key
|
207
|
+
response = mock_response_ok
|
208
|
+
OneSignal::OneSignal.expects(:send_delete_request)
|
209
|
+
.with(uri: @delete_uri, params: nil, opts: @opts)
|
210
|
+
.returns(response)
|
211
|
+
assert_equal response, OneSignal::Player.delete(id: @player_id, opts: @opts)
|
212
|
+
end
|
213
|
+
|
113
214
|
end
|