Skip to content

Commit

Permalink
ChannelsAPI.set_variable added
Browse files Browse the repository at this point in the history
  • Loading branch information
adambezecny committed Nov 15, 2021
1 parent c2eb1a4 commit 903f2ad
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "asterisk-ari-client-rs"
version = "0.1.0"
version = "0.1.1"
authors = ["abezecny"]
edition = "2018"
description = "Simple Asterisk ARI library"
license = "MIT OR Apache-2.0"
keywords = ["telephony", "asterisk"]
categories = ["multimedia", "multimedia::audio"]
repository = "https://github.com/jabber-tools/asterisk-ari-client-rs"
documentation = "https://docs.rs/jabber-tools/0.1.0"
documentation = "https://docs.rs/jabber-tools/0.1.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Apart from that following channels' operations are supported:
* play
* stop_play
* get_variable
* set_variable
* hangup
* continue_in_dialplan

Expand Down
3 changes: 3 additions & 0 deletions src/apis/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub trait ChannelsAPI {
/// Get the value of a channel variable
async fn get_variable(&self, channel_id: &str, var_name: &str) -> Result<String>;

/// Get the value of a channel variable
async fn set_variable(&self, channel_id: &str, var_name: &str, var_value: &str) -> Result<()>;

/// Hangs up the channel
async fn hangup(&self, channel_id: &str) -> Result<()>;

Expand Down
17 changes: 17 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,23 @@ impl ChannelsAPI for AriClient {
Ok(variable.value)
}

async fn set_variable(&self, channel_id: &str, var_name: &str, var_value: &str) -> Result<()> {
let resp = HTTP_CLIENT
.post(format!(
"{}/channels/{}/variable?variable={}&value={}",
self.url, channel_id, var_name, var_value
))
.headers(self.get_common_headers()?)
.send()
.await?;

let status = resp.status();
let body_str = resp.text().await?;

eval_status_code!(status, StatusCode::NO_CONTENT, Some(body_str));
Ok(())
}

async fn hangup(&self, channel_id: &str) -> Result<()> {
let resp = HTTP_CLIENT
.delete(format!("{}/channels/{}", self.url, channel_id))
Expand Down

0 comments on commit 903f2ad

Please sign in to comment.