-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 51ac7ad
Showing
98 changed files
with
4,666 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/Gemfile.lock | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
*.bundle | ||
*.so | ||
*.o | ||
*.a | ||
mkmf.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in asterisk-ari.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Copyright (c) 2014 Jan Svoboda | ||
|
||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# About | ||
|
||
This repository contains the ruby client library for the Asterisk REST Interface (ARI). | ||
It uses the swagger ARI json definitions to generate ruby classes. | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'asterisk-ari' | ||
``` | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install asterisk-ari | ||
|
||
## Usage | ||
|
||
```ruby | ||
# instantiate client | ||
@client = Ari::Client.new( | ||
url: 'http://127.0.0.1:8088/ari', | ||
api_key: 'asterisk:asterisk', | ||
app: 'my-app' | ||
) | ||
|
||
# originate | ||
@client.channels.originate endpoint: 'PJSIP/endpoint-name', extension: 11 | ||
|
||
# list all channels | ||
channels = @client.channels.list | ||
``` | ||
|
||
When working with only one client you can also use the following: | ||
|
||
```ruby | ||
Ari.client = Ari::Client.new( | ||
url: 'http://127.0.0.1:8088/ari', | ||
api_key: 'asterisk:asterisk', | ||
app: 'my-app' | ||
) | ||
|
||
# list channels | ||
channels = Ari::Channel.list | ||
``` | ||
|
||
### WebSocket events | ||
|
||
```ruby | ||
# listen to events | ||
@client.on :websocket_open do | ||
puts "Connected !" | ||
end | ||
|
||
@client.on :stasis_start do |e| | ||
puts "Received call to #{e.channel.dialplan.exten} !" | ||
|
||
e.channel.answer | ||
|
||
e.channel.on :channel_dtmf_received do |e| | ||
puts "Digit pressed: #{e.digit} on channel #{e.channel.name} !" | ||
end | ||
|
||
e.channel.on :stasis_end do |e| | ||
puts "Channel #{e.channel.name} left Stasis." | ||
end | ||
end | ||
|
||
# start websocket to receive events | ||
@client.connect_websocket | ||
sleep | ||
``` | ||
|
||
## Contributing | ||
|
||
1. Fork it ( https://github.com/svoboda-jan/asterisk-ari/fork ) | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create a new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "bundler/gem_tasks" | ||
require 'open-uri' | ||
require 'json' | ||
require 'ari/generators/resource_generator' | ||
|
||
desc "Generate resources from JSON specification" | ||
task :generate do | ||
|
||
base_url = 'http://svn.asterisk.org/svn/asterisk/trunk/rest-api/api-docs/%{resource_name}.json' | ||
resources = %w{ applications asterisk bridges channels deviceStates endpoints | ||
events mailboxes playbacks recordings sounds | ||
} | ||
|
||
resource_options = { | ||
asterisk: { | ||
resource_klass_name: 'AsteriskInfo' | ||
}, | ||
applications: { | ||
id_attribute_name: 'applicationName' | ||
}, | ||
events: { | ||
only_models: true | ||
} | ||
} | ||
|
||
models_path = File.join(__dir__, 'lib', 'ari', 'models.rb') | ||
FileUtils.rm_f models_path | ||
models_file = File.new(models_path, 'a') | ||
|
||
resources_path = File.join(__dir__, 'lib', 'ari', 'resources.rb') | ||
FileUtils.rm_f resources_path | ||
resources_file = File.new(resources_path, 'a') | ||
|
||
resources.each do |resource_name| | ||
url = base_url % { resource_name: resource_name } | ||
puts ">> generating #{resource_name} from #{url}" | ||
json = JSON.parse open(url).read | ||
generator = Ari::Generators::ResourceGenerator.new( | ||
resource_name, | ||
json, | ||
resource_options[resource_name.to_sym] || {} | ||
) | ||
generator.generate | ||
|
||
resources_file.puts "require 'ari/resources/#{generator.resource_name}'" | ||
generator.models.each do |model| | ||
next if model.name == generator.resource_name | ||
models_file.puts "require 'ari/models/#{model.name}'" | ||
end | ||
end | ||
|
||
models_file.close | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'asterisk/ari/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "asterisk-ari" | ||
spec.version = Asterisk::Ari::VERSION | ||
spec.authors = ["Jan Svoboda"] | ||
spec.email = ["[email protected]"] | ||
spec.summary = %q{Ruby client library for the Asterisk REST Interface (ARI).} | ||
spec.description = %q{Ruby client library for the Asterisk REST Interface (ARI).} | ||
spec.homepage = "" | ||
spec.license = "MIT" | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_development_dependency "bundler", "~> 1.7" | ||
spec.add_development_dependency "rake", "~> 10.0" | ||
|
||
spec.add_development_dependency "minitest", "~> 5.4.2" | ||
spec.add_development_dependency "vcr", "~> 2.9.3" | ||
spec.add_development_dependency "webmock", "~> 1.19.0" | ||
|
||
spec.add_development_dependency "active_support", "~> 4.1.6" | ||
|
||
spec.add_dependency "websocket-client-simple", "~> 0.2.0" | ||
spec.add_dependency "event_emitter", "~> 0.2.5" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require 'asterisk-ari' | ||
|
||
@client = Ari::Client.new( | ||
url: 'http://192.168.1.23:8088/ari', | ||
api_key: 'asterisk:asterisk', | ||
app: 'dialplan' | ||
) | ||
|
||
# list channels | ||
channels = @client.channels.list | ||
|
||
channels.each do |channel| | ||
puts "Channel ID #{channel.id}: #{channel.name}" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
require 'asterisk-ari' | ||
|
||
Ari.client = Ari::Client.new( | ||
url: 'http://192.168.1.23:8088/ari', | ||
api_key: 'asterisk:asterisk', | ||
app: 'dialplan' | ||
) | ||
|
||
@client.on :websocket_open do | ||
puts "Connected !" | ||
end | ||
|
||
@client.on :websocket_error do |err| | ||
puts "Error :( #{err}" | ||
end | ||
|
||
@client.on :stasis_start do |e| | ||
puts "Received call to #{e.channel.dialplan.exten} !" | ||
|
||
e.channel.answer | ||
|
||
e.channel.on :channel_dtmf_received do |e| | ||
puts "Digit pressed: #{e.digit} on channel #{e.channel.name} !" | ||
end | ||
|
||
e.channel.on :stasis_end do |e| | ||
puts "Channel #{e.channel.name} left Stasis." | ||
end | ||
end | ||
|
||
# start websocket to receive events | ||
@client.connect_websocket | ||
sleep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Ari | ||
|
||
def self.client | ||
return @@client if defined?(@@client) | ||
raise "ARI client not set. You can set it with ARI.client = client." | ||
end | ||
|
||
def self.client=(val) | ||
@@client = val | ||
end | ||
|
||
end |
Oops, something went wrong.