# Ruby Examples

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

{% file src="/files/2wlOc07yTv8lDOg20zzf" %}

* 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 *T*media and executed from a SSH client (as shown in the examples below using 127.0.0.1:12358).

### Download script

{% file src="/files/Ju4ToA6VS8rlQuZ6LYtC" %}

### 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'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://prosbcdocs.telcobridges.com/tools-tips-and-tricks/restful-api/ruby-examples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
