diff --git a/Cargo.lock b/Cargo.lock index 0ab90ef..573d2fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,7 +11,7 @@ dependencies = [ [[package]] name = "asterisk-ari-client-rs" -version = "0.1.0" +version = "0.1.1" dependencies = [ "async-trait", "base64", diff --git a/Cargo.toml b/Cargo.toml index 296a230..3d3fe7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "asterisk-ari-client-rs" -version = "0.1.0" +version = "0.1.1" authors = ["abezecny"] edition = "2018" description = "Simple Asterisk ARI library" @@ -8,7 +8,7 @@ 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 diff --git a/README.md b/README.md index 0404ace..90f2b63 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ Apart from that following channels' operations are supported: * play * stop_play * get_variable +* set_variable * hangup * continue_in_dialplan diff --git a/src/apis/channels.rs b/src/apis/channels.rs index da0009c..8765333 100644 --- a/src/apis/channels.rs +++ b/src/apis/channels.rs @@ -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; + /// 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<()>; diff --git a/src/client.rs b/src/client.rs index 1dda462..2ed62c9 100644 --- a/src/client.rs +++ b/src/client.rs @@ -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))