~gbmor/rustwtxt

a4d79cbbebaed0d7b4148aa3036363b7ea638fce — Ben Morrison 1 year, 6 months ago cc750ec
moved to ureq for requests
updated doctest for parse::metadata so it no longer panics
3 files changed, 28 insertions(+), 13 deletions(-)

M Cargo.toml
M src/lib.rs
M src/parse.rs
M Cargo.toml => Cargo.toml +2 -5
@@ 17,12 17,9 @@ codecov = { repository = "rustwtxt/rustwtxt", branch = "master", service = "gith
maintenance = { status = "experimental" }

[dependencies]
failure = "^0.1.6"
regex = "1"

[dependencies.http_req]
version = "0.5"
default-features=false
features=["rust-tls"]
ureq = "^0.11.3"

[profile.release]
opt-level = 3

M src/lib.rs => src/lib.rs +19 -7
@@ 7,8 7,9 @@

use std::collections::BTreeMap;

use http_req::request;
use failure::format_err;
use regex::Regex;
use ureq;

pub mod parse;



@@ 166,10 167,22 @@ impl Tweet {
///           };
/// ```
pub fn pull_twtxt(url: &str) -> Result<String> {
    let mut buf = Vec::new();
    request::get(&url, &mut buf)?;
    let res = std::str::from_utf8(&buf)?.into();
    Ok(res)
    let resp = ureq::get(&url).timeout_connect(5000).call();
    if resp.error() {
        return Err(Box::new(failure::Error::compat(format_err!(
            "{} :: {}",
            resp.status(),
            &url
        ))));
    }

    if let Ok(val) = resp.into_string() {
        return Ok(val);
    }
    Err(Box::new(failure::Error::compat(format_err!(
        "{} :: Internal Error",
        &url
    ))))
}

/// Wrapper to apply a function to each line of a `twtxt.txt` file,


@@ 190,9 203,8 @@ pub fn mutate(twtxt: &str, f: fn(&str) -> String) -> Vec<String> {
    twtxt
        .to_owned()
        .lines()
        .map(|line| f(line).to_string())
        .map(|line| f(line))
        .collect::<Vec<String>>()
        .clone()
}

#[cfg(test)]

M src/parse.rs => src/parse.rs +7 -1
@@ 34,7 34,13 @@ impl std::error::Error for ErrorKind {}
/// ```
/// # use rustwtxt;
/// # use rustwtxt::parse;
/// let twtxt = rustwtxt::pull_twtxt("https://example.org/twtxt.txt").unwrap();
///
/// let twtxt = if let Ok(val) = rustwtxt::pull_twtxt("https://example.org/twtxt.txt") {
///     val
/// } else {
///     String::new()
/// };
///
/// let out = parse::metadata(&twtxt, "nick");
/// ```
pub fn metadata(twtxt: &str, keyword: &str) -> TwtxtErr<String> {