use reqwest::{self,Url}; use serde::{Deserialize}; use git2::Repository; use std::error::Error; use std::path::Path; static AUR_URL: &str = "https://aur.archlinux.org/"; static AUR_RPC_VER:&str = "5"; lazy_static!{ static ref AUR_RPC_URL: String = Url::parse(AUR_URL).unwrap().join("/rpc").unwrap().to_string(); static ref AUR_GIT_URL: Url = Url::parse(AUR_URL).unwrap(); } #[allow(non_snake_case)] #[derive(Deserialize)] pub struct Package{ pub ID : i32, pub Name : String, pub PackageBaseID : i32, pub PackageBase : Option, pub Version : String, pub Description : Option, pub URL : Option, pub NumVotes : i32, pub Popularity : f64, pub OutOfDate : Option, pub Maintainer : Option, pub FirstSubmitted : i32, pub LastModified : i32, pub URLPath : String, pub Depends : Option>, pub MakeDepends : Option>, pub CheckDepends : Option>, pub Conflicts : Option>, pub Provides : Option>, pub Replaces : Option>, pub OptDepends : Option>, pub Groups : Option>, pub License : Option>, pub Keywords : Option>, } #[derive(Deserialize)] pub struct Response { pub error : Option, pub version: i32, pub r#type : String, pub resultcount : i32, pub results: Vec, } pub fn search(arg: &str) -> Result> { let url = Url::parse_with_params(&AUR_RPC_URL,&[ ("v", AUR_RPC_VER), ("type", "search"), ("arg", arg)])?; let resp: Response = reqwest::get(url.as_str())? .json()?; Ok(resp) } pub fn info(needles: &[&str]) -> Result>{ let mut args = Vec::new(); args.push(("v", AUR_RPC_VER)); args.push(("type", "info")); for n in needles{ args.push(("arg[]", n)); } let url = Url::parse_with_params(&AUR_RPC_URL, &args)?; let resp: Response = reqwest::get(url.as_str())? .json()?; Ok(resp) } pub fn clone(package: &str, p: &Path) -> Result>{ Ok(Repository::clone( &AUR_GIT_URL.join(package)? .join(".git")? .to_string(), p )?) }