Ruby Examples

This ruby script (httprestapi) is an example of how to use TelcoBridges RESTful Northbound Interface.

  • The script can be executed from any computer having access to the management web interface.

  • The script can also be copied on the internal host of a Tmedia and executed from a SSH client (as shown in the examples below using 127.0.0.1:12358).

Download script

Usage

./httprestapi.rb <URI> <user> <password> <http request>

  With <URI> = http://ip:port
    Example: ./httprestapi.rb 'http://127.0.0.1:12358' 'root' 'password' <http request>

  With <http request> = <GET|PUT|POST|DELETE> <element path> [json | -i jsonfile | -o jsonfile]
    -i jsonfile = input json file used for PUT or POST http request
    -o jsonfile = output json file used for GET http request

GET

Get the configuration collection list and display the JSON returned in the body of the HTTP response.

./httprestapi.rb 'http://127.0.0.1:12358' GET '/configurations'

Show the use of "recursive=yes" to get all sub-element of configuration. Put the returned JSON in "test_configuration.json" file.

./httprestapi.rb 'http://127.0.0.1:12358' GET '/configurations/test?recursive=yes' '-o test_configuration.json'

Use "documentation=yes" to return documentation of all attributes of an element. Below example returns documentation for a new route element.

./httprestapi.rb 'http://127.0.0.1:12358' GET '/configurations/test/routes/new?documentation=yes'

Get request can also be used to retrieve the status of some elements of the active configuration.

./httprestapi.rb 'http://127.0.0.1:12358' GET '/configurations/test/naps/xtel/status'

PUT

Modify attributes of an element. Below example renames the route element named "Test" to "NewName".

./httprestapi.rb 'http://127.0.0.1:12358' PUT '/configurations/test/routes/test_route' '{"name":"new_route_name"}' 

Modify attributes of an element using a JSON file for the HTTP request.

./httprestapi.rb 'http://127.0.0.1:12358' PUT '/configurations/test/routes/test_route' '-i modified_route.json' 

Activate "demo" configuration

./httprestapi.rb 'http://127.0.0.1:12358' PUT '/systems/system_1' '{"target_configuration":"demo"}' 

POST

Create a new element. Below example add a new route named "xtel_to_SBC_1".

./httprestapi.rb 'http://127.0.0.1:12358' POST '/configurations/test/routes' '{"name":"xtel_to_SBC_1","nap":"xtel","remapped_nap":"SBC_1"}' 

Create a new element using a JSON file for the HTTP request.

./httprestapi.rb 'http://127.0.0.1:12358' POST '/configurations/test/routes' '-i new_route.json' 

Create a new configuration using a JSON file for the HTTP request.

./httprestapi.rb 'http://127.0.0.1:12358' POST '/configurations' '-i test_configuration.json' 

DELETE

Delete an element. Below example delete the route named "xtel_to_SBC_1".

./httprestapi.rb 'http://127.0.0.1:12358' DELETE '/configurations/test/routes/xtel_to_SBC_1' 

Using JSON files

Modify an element

1. Get route configuration in JSON file

./httprestapi.rb 'http://127.0.0.1:12358' GET '/configurations/test/routes/test_route' '-o routes.json'

2. Edit JSON file attributes

vi route.json

3. Modify element from JSON file

./httprestapi.rb 'http://127.0.0.1:12358' PUT '/configurations/test/routes/test_route' '-i routes.json'

Create a new element

1. Get an element default attributes value in a JSON file

./httprestapi.rb 'http://127.0.0.1:12358' GET '/configurations/test/routes/new' '-o routes.json'

2. Edit JSON file attributes

vi route.json

3. Create new element from JSON file

./httprestapi.rb 'http://127.0.0.1:12358' POST '/configurations/test/routes/new_route' '-i routes.json'

Last updated

Was this helpful?