🏡 index : ~doyle/sonos.rs.git

author Jordan Doyle <jordan@doyle.la> 2020-02-20 19:54:00.0 +00:00:00
committer Jordan Doyle <jordan@doyle.la> 2020-02-20 19:54:00.0 +00:00:00
commit
566818f69e6ccc4457dd80c359a36a89823f5b09 [patch]
tree
4b2f711d7791ebfcacb3a6f542611e3b0f07fbd7
parent
b6a77e565a4df565dae99d8154d085e0acbc6c63
download
566818f69e6ccc4457dd80c359a36a89823f5b09.tar.gz

Bump dependency versions



Diff

 Cargo.toml    |  4 ++--
 src/device.rs | 22 ++++++++++++++--------
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/Cargo.toml b/Cargo.toml
index 1634128..bf3a6e2 100644
--- a/Cargo.toml
+++ a/Cargo.toml
@@ -9,10 +9,10 @@
readme = "README.md"

[dependencies]
reqwest = "0.9"
reqwest = { version = "0.10", features = ["blocking"] }
log = "0.4"
ssdp = "0.7"
xmltree = "0.8"
xmltree = "0.10"
error-chain = "0.12"
regex = "1"
lazy_static = "1"
diff --git a/src/device.rs b/src/device.rs
index d5928ac..c4626e3 100644
--- a/src/device.rs
+++ a/src/device.rs
@@ -7,7 +7,7 @@
use std::time::Duration;
use error::*;
pub(crate) use self::xmltree::ParseError;
use self::xmltree::Element;
use self::xmltree::{Element, XMLNode};
use self::reqwest::header::HeaderMap;
use self::regex::Regex;

@@ -51,13 +51,13 @@

/// Get the text of the given element as a String

fn element_to_string(el: &Element) -> String {
    el.text.to_owned().unwrap_or_default()
    el.get_text().map(std::borrow::Cow::into_owned).unwrap_or_default()
}

impl Speaker {
    /// Create a new instance of this struct from an IP address

    pub fn from_ip(ip: IpAddr) -> Result<Speaker> {
        let resp = reqwest::get(&format!("http://{}:1400/xml/device_description.xml", ip))
        let resp = reqwest::blocking::get(&format!("http://{}:1400/xml/device_description.xml", ip))
            .chain_err(|| ErrorKind::DeviceUnreachable)?;

        if !resp.status().is_success() {
@@ -99,7 +99,7 @@

    /// Get the coordinator for this speaker.

    pub fn coordinator(&self) -> Result<IpAddr> {
        let mut resp = reqwest::get(&format!("http://{}:1400/status/topology", self.ip))
        let mut resp = reqwest::blocking::get(&format!("http://{}:1400/status/topology", self.ip))
            .chain_err(|| ErrorKind::DeviceUnreachable)?;

        if !resp.status().is_success() {
@@ -126,12 +126,18 @@
        let group = &zone_players
            .children
            .iter()
            .map(XMLNode::as_element)
            .filter(Option::is_some)
            .map(Option::unwrap)
            .find(|child| child.attributes["uuid"] == self.uuid)
            .chain_err(|| ErrorKind::DeviceNotFound(self.uuid.to_string()))?
            .attributes["group"];

        Ok(COORDINATOR_REGEX
            .captures(zone_players.children.iter()
                .map(XMLNode::as_element)
                .filter(Option::is_some)
                .map(Option::unwrap)
                // get the coordinator for the given group
                .find(|child|
                    child.attributes.get("coordinator").unwrap_or(&"false".to_string()) == "true" &&
@@ -167,7 +173,7 @@
        headers.insert("SOAPAction", format!("\"{}#{}\"", service, action).parse()
            .map_err(|_| "service/action caused an invalid header")?);

        let client = reqwest::Client::new();
        let client = reqwest::blocking::Client::new();
        let coordinator = if coordinator {
            self.coordinator()?
        } else {
@@ -428,11 +434,7 @@
            false,
        )?;

        let volume = res.get_child("CurrentVolume")
            .chain_err(|| ErrorKind::ParseError)?
            .text
            .to_owned()
            .chain_err(|| ErrorKind::ParseError)?
        let volume = element_to_string(res.get_child("CurrentVolume").chain_err(|| ErrorKind::ParseError)?)
            .parse::<u8>()
            .chain_err(|| ErrorKind::ParseError)?;