Skip to content

Commit

Permalink
Add get_info_string() function (#10)
Browse files Browse the repository at this point in the history
Fixes: #8
  • Loading branch information
brianmay authored Oct 22, 2023
1 parent e1f8384 commit 5ffd14e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ futures = "0.3"
serde_json = "1.0"
uuid = { version = "1.4", features = ["v4"] }
thiserror = "1.0"
serde = "1.0.158"

[dev-dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
anyhow = "*"
regex ="*"
ntest = "0.9.0"
ntest = "0.9.0"
13 changes: 13 additions & 0 deletions src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::esl::EslConnectionType;
use crate::event::Event;
use crate::io::EslCodec;
use futures::SinkExt;
use serde::de::DeserializeOwned;
use serde_json::Value;
use std::collections::{HashMap, VecDeque};
use std::sync::atomic::Ordering;
Expand All @@ -30,6 +31,18 @@ pub struct EslConnection {
}

impl EslConnection {
/// Returns one of the session parameters as a string
pub fn get_info_string(&self, key: &str) -> Option<String> {
let value = self.connection_info.as_ref()?.get(key)?.clone();
serde_json::from_value(value).ok()?
}

/// Returns one of the session parameters as any deserializable type
pub fn get_info<V: DeserializeOwned>(&self, key: &str) -> Option<V> {
let value = self.connection_info.as_ref()?.get(key)?.clone();
serde_json::from_value(value).ok()?
}

/// returns call uuid in outbound mode
pub async fn call_uuid(&self) -> Option<String> {
self.call_uuid.clone()
Expand Down

0 comments on commit 5ffd14e

Please sign in to comment.