pub async fn action(
        &self,
        url: &Uri,
        action: &str,
        payload: &str,
    ) -> Result<HashMap<String, String>> {
        let body = format!(
            r#"
            <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
                s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
                <s:Body>
                    <u:{action} xmlns:u="{service}">
                        {payload}
                    </u:{action}>
                </s:Body>
            </s:Envelope>"#,
            service = &self.service_type,
            action = action,
            payload = payload
        );

        let soap_action = format!("\"{}#{}\"", &self.service_type, action);

        let request = Request::post(self.control_url(url))
            .header("CONTENT-TYPE", "xml")
            .header("SOAPAction", soap_action)
            .body(body.into())
            .expect("infallible");
        let doc = hyper::Client::new()
            .request(request)
            .await?
            .err_if_not_200()?
            .into_body()
            .text()
            .await?;
        let doc = std::str::from_utf8(&doc)?;

        let document = Document::parse(&doc)?;
        let response = utils::find_root(&document, "Body", "UPnP Response")?
            .first_element_child()
            .ok_or_else(|| {
                Error::XmlMissingElement("Body".to_string(), format!("{}Response", action))
            })?;

        if response.tag_name().name().eq_ignore_ascii_case("Fault") {
            return Err(UPnPError::from_fault_node(response)?.into());
        }

        let values: HashMap<_, _> = response
            .children()
            .filter(Node::is_element)
            .filter_map(|node| -> Option<(String, String)> {
                if let Some(text) = node.text() {
                    Some((node.tag_name().name().to_string(), text.to_string()))
                } else {
                    None
                }
            })
            .collect();

        Ok(values)
    }
/// Execute some UPnP Action on this service.
/// The URL is usually obtained by the device this service was found on.
/// The payload is xml-formatted data.
///
/// # Example usage:
///
/// ```rust,no_run
/// # use ssdp_client::URN;
/// # async fn rendering_control_example() -> Result<(), rupnp::Error> {
/// # let some_url = unimplemented!();
/// use rupnp::ssdp::URN;
/// use rupnp::Device;
///
/// let urn = URN::service("schemas-upnp-org", "RenderingControl", 1);
///
/// let device = Device::from_url( some_url ).await?;
/// let service = device.find_service(&urn)
///     .expect("service exists");
///
/// let args = "<InstanceID>0</InstanceID><Channel>Master</Channel>";
/// let response = service.action(device.url(), "GetVolume", args).await?;
///
/// let volume = response
///     .get("CurrentVolume")
///     .expect("exists");
///
/// println!("Volume: {}", volume);
/// # Ok(())
/// # }
/// ```
Execute some UPnP Action on this service.
The URL is usually obtained by the device this service was found on.
The payload is xml-formatted data.
Execute some UPnP Action on this service . The URL is usually obtained by the device this service was found on . The payload is xml - formatted data .
pub async fn action(
        &self,
        url: &Uri,
        action: &str,
        payload: &str,
    ) -> Result<HashMap<String, String>> {
        let body = format!(
            r#"
            <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
                s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
                <s:Body>
                    <u:{action} xmlns:u="{service}">
                        {payload}
                    </u:{action}>
                </s:Body>
            </s:Envelope>"#,
            service = &self.service_type,
            action = action,
            payload = payload
        );
        let soap_action = format!("\"{}#{}\"", &self.service_type, action);
        let request = Request::post(self.control_url(url))
            .header("CONTENT-TYPE", "xml")
            .header("SOAPAction", soap_action)
            .body(body.into())
            .expect("infallible");
        let doc = hyper::Client::new()
            .request(request)
            .await?
            .err_if_not_200()?
            .into_body()
            .text()
            .await?;
        let doc = std::str::from_utf8(&doc)?;
        let document = Document::parse(&doc)?;
        let response = utils::find_root(&document, "Body", "UPnP Response")?
            .first_element_child()
            .ok_or_else(|| {
                Error::XmlMissingElement("Body".to_string(), format!("{}Response", action))
            })?;
        if response.tag_name().name().eq_ignore_ascii_case("Fault") {
            return Err(UPnPError::from_fault_node(response)?.into());
        }
        let values: HashMap<_, _> = response
            .children()
            .filter(Node::is_element)
            .filter_map(|node| -> Option<(String, String)> {
                if let Some(text) = node.text() {
                    Some((node.tag_name().name().to_string(), text.to_string()))
                } else {
                    None
                }
            })
            .collect();
        Ok(values)
    }
pub async fn action ( & self , url : & Uri , action : & str , payload : & str , ) -> Result < HashMap < String , String > > { let body = format ! ( r#"
            <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
                s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
                <s:Body>
                    <u:{action} xmlns:u="{service}">
                        {payload}
                    </u:{action}>
                </s:Body>
            </s:Envelope>"# service self service_type action action payload payload ) ; let soap_action = format ! ( " \" \" " self service_type action ) ; let request = Request :: post ( self . control_url ( url ) ) . header ( " " , " " ) . header ( " " , soap_action ) . body ( body . into ( ) ) . expect ( " " ) ; let doc = hyper :: Client :: new ( ) . request ( request ) . await ? . err_if_not_200 ( ) ? . into_body ( ) . text ( ) . await ? ; let doc = std :: str :: from_utf8 ( & doc ) ? ; let document = Document :: parse ( & doc ) ? ; let response = utils :: find_root ( & document , " " , " " ) ? . first_element_child ( ) . ok_or_else ( | | { Error :: XmlMissingElement ( " " . to_string ( ) , format ! ( " " action ) ) } ) ? ; if response . tag_name ( ) . name ( ) . eq_ignore_ascii_case ( " " ) { return Err ( UPnPError :: from_fault_node ( response ) ? . into ( ) ) ; } let values : HashMap < _ , _ > = response . children ( ) . filter ( Node :: is_element ) . filter_map ( | node | -> Option < ( String , String ) > { if let Some ( text ) = node . text ( ) { Some ( ( node . tag_name ( ) . name ( ) . to_string ( ) , text . to_string ( ) ) ) } else { None } } ) . collect ( ) ; Ok ( values ) }
Execute some UPnP Action on this service.
Execute some UPnP Action on this service .
&self
url
&Uri
action
&str
payload
&str
&self
url
&Uri
action
&str
payload
&str
example usage:
None
use ssdp_client::urn;
None
async fn rendering_control_example() -> result<(), rupnp::error> {
None
let some_url = unimplemented!();
use rupnp::ssdp::URN;
use rupnp::Device.

let urn = URN::service("schemas-upnp-org", "RenderingControl", 1).

let device = Device::from_url( some_url ).await?;
let service = device.find_service(&urn)
.expect("service exists").

let args = "0Master";
let response = service.action(device.url(), "GetVolume", args).await?.

let volume = response
.get("CurrentVolume")
.expect("exists").

println!("Volume: {}", volume).
use rupnp :: ssdp :: URN ; use rupnp :: Device . let urn = URN :: service ( " schemas - upnp - org " " RenderingControl " 1 ) . let device = Device :: from_url ( some_url ) . await? ; let service = device . find_service ( &urn ) . expect ( " service exists " ) . let args = " 0Master " ; let response = service . action ( device . url () " GetVolume " args ) . await? . let volume = response . get ( " CurrentVolume " ) . expect ( " exists " ) . println! ( " Volume : {} " volume ) .
ok(())
None
}
None