1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#[macro_use]
extern crate serde_json;
#[macro_use]
extern crate serde_derive;
extern crate reqwest;
use reqwest::*;
use serde_json::{Result, Value};
const BASE_URL: &str = "https://repology.org/api/v1/";
#[derive(Debug, Clone)]
pub struct RepologyClient {
client: reqwest::Client,
}
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Package {
repo: String,
name: String,
version: String,
sub_repo: Option<String>,
orig_version: Option<String>,
status: Option<String>,
summary: Option<String>,
family: Option<String>,
categories: Option<Vec<String>>,
licenses: Option<Vec<String>>,
maintainers: Option<Vec<String>>,
www: Option<Vec<String>>,
downloads: Option<Vec<String>>
}
impl RepologyClient {
pub fn new() -> RepologyClient {
RepologyClient{
client: Client::new(),
}
}
pub fn project(self, package: &str) -> Vec<Package> {
let url = Url::parse(&format!("{}/project/{}",BASE_URL, package)).unwrap();
let mut resp = self.client.get(url.clone()).send().unwrap();
let package_data = resp.text().unwrap();
let json: Vec<Package> = serde_json::from_str(package_data.as_str()).unwrap();
return json;
}
pub fn multiple_projects(self, package: &str, limit: u64) -> String {
return String::from("");
}
}