Class: RubyAsterisk::ARI::Client
- Inherits:
-
Object
- Object
- RubyAsterisk::ARI::Client
- Defined in:
- lib/ruby-asterisk/ari/client.rb
Overview
HTTP client for the Asterisk REST Interface (ARI). Wraps Faraday to provide authenticated GET, POST, and DELETE requests and maps HTTP error responses to RubyAsterisk::Error exceptions.
Instance Attribute Summary collapse
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
Instance Method Summary collapse
- #asterisk_info ⇒ Object
- #bridges ⇒ Object
- #channels ⇒ Object
- #delete(path, params = {}) ⇒ Object
- #endpoints ⇒ Object
- #get(path, params = {}) ⇒ Object
-
#initialize(base_url, api_key, app_name) ⇒ Client
constructor
A new instance of Client.
- #playbacks ⇒ Object
- #post(path, body = {}) ⇒ Object
Constructor Details
#initialize(base_url, api_key, app_name) ⇒ Client
Returns a new instance of Client.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby-asterisk/ari/client.rb', line 20 def initialize(base_url, api_key, app_name) @base_url = base_url @api_key = api_key @app_name = app_name # ARI credentials may be supplied as "user:password" (the standard # api_key form). Split on the first colon; a bare key means empty password. user, pass = api_key.to_s.split(':', 2) pass ||= '' @connection = Faraday.new(url: base_url) do |conn| conn.request :authorization, :basic, user, pass conn.headers['Content-Type'] = 'application/json' conn.headers['Accept'] = 'application/json' end end |
Instance Attribute Details
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
18 19 20 |
# File 'lib/ruby-asterisk/ari/client.rb', line 18 def app_name @app_name end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
18 19 20 |
# File 'lib/ruby-asterisk/ari/client.rb', line 18 def base_url @base_url end |
Instance Method Details
#asterisk_info ⇒ Object
50 51 52 |
# File 'lib/ruby-asterisk/ari/client.rb', line 50 def asterisk_info get('/ari/asterisk/info') end |
#bridges ⇒ Object
58 59 60 |
# File 'lib/ruby-asterisk/ari/client.rb', line 58 def bridges Resources::Collection.new(Resources::Bridge, '/ari/bridges', self) end |
#channels ⇒ Object
54 55 56 |
# File 'lib/ruby-asterisk/ari/client.rb', line 54 def channels Resources::Collection.new(Resources::Channel, '/ari/channels', self) end |
#delete(path, params = {}) ⇒ Object
45 46 47 48 |
# File 'lib/ruby-asterisk/ari/client.rb', line 45 def delete(path, params = {}) response = @connection.delete(path, params) handle_response(response) end |
#endpoints ⇒ Object
66 67 68 |
# File 'lib/ruby-asterisk/ari/client.rb', line 66 def endpoints Resources::Collection.new(Resources::Endpoint, '/ari/endpoints', self) end |
#get(path, params = {}) ⇒ Object
35 36 37 38 |
# File 'lib/ruby-asterisk/ari/client.rb', line 35 def get(path, params = {}) response = @connection.get(path, params) handle_response(response) end |
#playbacks ⇒ Object
62 63 64 |
# File 'lib/ruby-asterisk/ari/client.rb', line 62 def playbacks Resources::Collection.new(Resources::Playback, '/ari/playbacks', self) end |
#post(path, body = {}) ⇒ Object
40 41 42 43 |
# File 'lib/ruby-asterisk/ari/client.rb', line 40 def post(path, body = {}) response = @connection.post(path, body.to_json) handle_response(response) end |