opensips-pi-rest 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/opensips-pi-rest/subscribers_app.rb +34 -28
- data/lib/opensips-pi-rest/version.rb +1 -1
- metadata +1 -1
@@ -1,37 +1,43 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module Opensips
|
2
|
+
module Pi
|
3
|
+
module Rest
|
4
|
+
class SubscribersApp < Sinatra::Base
|
5
|
+
|
6
|
+
post "/" do
|
7
|
+
required_params :username, :password do
|
8
|
+
Opensips::Pi.add(params[:username], params[:password], params[:domain]).tap do |response|
|
9
|
+
halt 400, response.last unless response.first
|
10
|
+
end
|
11
|
+
end
|
9
12
|
|
10
|
-
|
11
|
-
|
13
|
+
200
|
14
|
+
end
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
16
|
+
delete "/:id" do
|
17
|
+
Opensips::Pi.remove(params[:id],params[:domain]).tap do |response|
|
18
|
+
halt 400, response.last unless response.first
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
200
|
22
|
+
end
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
put "/:id/password" do
|
25
|
+
Opensips::Pi.password(params[:id],params[:password],params[:domain]).tap do |response|
|
26
|
+
halt 400, response.last unless response.first
|
27
|
+
end
|
25
28
|
|
26
|
-
|
27
|
-
|
29
|
+
200
|
30
|
+
end
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
32
|
+
private
|
33
|
+
def required_params *keys
|
34
|
+
keys.each do |k|
|
35
|
+
halt 400 unless params[k].present?
|
36
|
+
end
|
34
37
|
|
35
|
-
|
38
|
+
yield
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
36
42
|
end
|
37
43
|
end
|