opensips-pi-rest 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Locaweb <development@locaweb.com.br>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Opensips-Pi-REST
2
+ ***
3
+
4
+ A Restful API to expose Opensips::Pi provisioning services to the web.
5
+
6
+
7
+ ## Installation
8
+ ***
9
+
10
+ gem install opensips-pi-rest
11
+
12
+ ## Usage
13
+ ***
14
+
15
+ $ opensips-pi-rest start|stop
16
+
17
+ ## Configuration
18
+ ***
19
+
20
+ To configure the opensips-pi gem and customize bin path and/or logger impl, just create a ruby script as follows:
21
+
22
+ Opensips::Pi.bin = "PATH/TO/opensipsctl"
23
+ Opensips::Pi.logger = ACustomLogger.class
24
+
25
+ Then, you should run opensips-pi-rest binary with a environment variable as follows:
26
+
27
+ CONFIG=path/to/custom_config.rb opensips-pi-rest start
28
+
29
+ ## Contributing
30
+
31
+ 1. Fork it
32
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
33
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
34
+ 4. Push to the branch (`git push origin my-new-feature`)
35
+ 5. Create new Pull Request
36
+
37
+ ## License
38
+
39
+ This project is released under the MIT License. See LICENSE.txt for more information.
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Run-level Startup script for Opensips-pi-rest web services
4
+ #
5
+
6
+ path = Gem::Specification.find_by_name("opensips-pi-rest").gem_dir
7
+ pid_name = "/tmp/opensips-pi-rest.pid"
8
+
9
+ case ARGV[0]
10
+ when "start"
11
+ puts "Starting..."
12
+ system "rackup #{path}/config.ru -D -P #{pid_name}"
13
+ puts "OK"
14
+ when "stop"
15
+ puts "Stopping..."
16
+ system "kill -KILL `cat #{pid_name}`"
17
+ puts "OK"
18
+ else
19
+ puts "Usage: start|stop"
20
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
5
+
6
+ require 'lib/opensips-pi-rest'
7
+ require ENV['CONFIG'] if ENV['CONFIG']
8
+
9
+ map('/subscribers') { run SubscribersApp }
@@ -0,0 +1,13 @@
1
+ require "sinatra"
2
+ require "active_support/all"
3
+ require "opensips-pi"
4
+ require "opensips-pi-rest/version"
5
+ require "opensips-pi-rest/subscribers_app"
6
+
7
+ module Opensips
8
+ module Pi
9
+ module Rest
10
+
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ class SubscribersApp < Sinatra::Base
2
+
3
+ post "/" do
4
+ required_params :username, :password do
5
+ Opensips::Pi.add(params[:username], params[:password], params[:domain]).tap do |response|
6
+ halt 400, response.last unless response.first
7
+ end
8
+ end
9
+
10
+ 200
11
+ end
12
+
13
+ delete "/:id" do
14
+ Opensips::Pi.remove(params[:id],params[:domain]).tap do |response|
15
+ halt 400, response.last unless response.first
16
+ end
17
+
18
+ 200
19
+ end
20
+
21
+ put "/:id/password" do
22
+ Opensips::Pi.password(params[:id],params[:password],params[:domain]).tap do |response|
23
+ halt 400, response.last unless response.first
24
+ end
25
+
26
+ 200
27
+ end
28
+
29
+ private
30
+ def required_params *keys
31
+ keys.each do |k|
32
+ halt 400 unless params[k].present?
33
+ end
34
+
35
+ yield
36
+ end
37
+ end
@@ -0,0 +1,7 @@
1
+ module Opensips
2
+ module Pi
3
+ module Rest
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opensips-pi-rest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexandre Cardoso
9
+ - Lenon Marcel
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2013-03-15 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: sinatra
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ! '>='
29
+ - !ruby/object:Gem::Version
30
+ version: '0'
31
+ - !ruby/object:Gem::Dependency
32
+ name: activesupport
33
+ requirement: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: opensips-pi
49
+ requirement: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ - !ruby/object:Gem::Dependency
64
+ name: rspec
65
+ requirement: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 2.13.0
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 2.13.0
79
+ - !ruby/object:Gem::Dependency
80
+ name: guard-rspec
81
+ requirement: !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ type: :development
88
+ prerelease: false
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ! '>='
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ - !ruby/object:Gem::Dependency
96
+ name: rack-test
97
+ requirement: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ none: false
107
+ requirements:
108
+ - - ! '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Opensips::Pi REST API
112
+ email:
113
+ - accbel@gmail.com
114
+ - lenon.marcel@gmail.com
115
+ executables:
116
+ - opensips-pi-rest
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - README.md
121
+ - LICENSE.txt
122
+ - config.ru
123
+ - bin/opensips-pi-rest
124
+ - lib/opensips-pi-rest/subscribers_app.rb
125
+ - lib/opensips-pi-rest/version.rb
126
+ - lib/opensips-pi-rest.rb
127
+ homepage: https://github.com/locaweb/opensips-pi-rest
128
+ licenses: []
129
+ post_install_message:
130
+ rdoc_options: []
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 1.8.24
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: Restful API to expose Opensips::Pi provisioning services to the web
151
+ test_files: []