Skip to content

Commit a1ded65

Browse files
committed
feat: [torrust#1159] extract new package tracker api client
1 parent f6aca40 commit a1ded65

File tree

12 files changed

+345
-1
lines changed

12 files changed

+345
-1
lines changed

.github/workflows/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ jobs:
5858
cargo publish -p bittorrent-http-protocol
5959
cargo publish -p bittorrent-tracker-client
6060
cargo publish -p torrust-tracker
61+
cargo publish -p torrust-tracker-api-client
6162
cargo publish -p torrust-tracker-client
6263
cargo publish -p torrust-tracker-clock
6364
cargo publish -p torrust-tracker-configuration

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ rust-version.workspace = true
1616
version.workspace = true
1717

1818
[lib]
19-
name = "torrust_tracker_lib"
19+
name = "torrust_tracker_lib"
2020

2121
[workspace.package]
2222
authors = ["Nautilus Cyberneering <[email protected]>, Mick van Dijke <[email protected]>"]
@@ -108,6 +108,7 @@ members = [
108108
"packages/primitives",
109109
"packages/test-helpers",
110110
"packages/torrent-repository",
111+
"packages/tracker-api-client",
111112
"packages/tracker-client",
112113
]
113114

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[package]
2+
description = "A library to interact with the Torrust Tracker REST API."
3+
keywords = ["bittorrent", "client", "tracker"]
4+
license = "LGPL-3.0"
5+
name = "torrust-tracker-api-client"
6+
readme = "README.md"
7+
8+
authors.workspace = true
9+
documentation.workspace = true
10+
edition.workspace = true
11+
homepage.workspace = true
12+
publish.workspace = true
13+
repository.workspace = true
14+
rust-version.workspace = true
15+
version.workspace = true
16+
17+
[dependencies]
18+
hyper = "1"
19+
reqwest = { version = "0", features = ["json"] }
20+
serde = { version = "1", features = ["derive"] }
21+
uuid = { version = "1", features = ["v4"] }

packages/tracker-api-client/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Torrust Tracker API Client
2+
3+
A library to interact with the Torrust Tracker REST API.
4+
5+
## License
6+
7+
**Copyright (c) 2024 The Torrust Developers.**
8+
9+
This program is free software: you can redistribute it and/or modify it under the terms of the [GNU Lesser General Public License][LGPL_3_0] as published by the [Free Software Foundation][FSF], version 3.
10+
11+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the [GNU Lesser General Public License][LGPL_3_0] for more details.
12+
13+
You should have received a copy of the *GNU Lesser General Public License* along with this program. If not, see <https://www.gnu.org/licenses/>.
14+
15+
Some files include explicit copyright notices and/or license notices.
16+
17+
### Legacy Exception
18+
19+
For prosperity, versions of Torrust BitTorrent Tracker Client that are older than five years are automatically granted the [MIT-0][MIT_0] license in addition to the existing [LGPL-3.0-only][LGPL_3_0] license.
20+
21+
[LGPL_3_0]: ./LICENSE
22+
[MIT_0]: ./docs/licenses/LICENSE-MIT_0
23+
[FSF]: https://www.fsf.org/
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
MIT No Attribution
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
software and associated documentation files (the "Software"), to deal in the Software
5+
without restriction, including without limitation the rights to use, copy, modify,
6+
merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
7+
permit persons to whom the Software is furnished to do so.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
10+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
11+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
12+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
13+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
14+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
pub type ReqwestQuery = Vec<ReqwestQueryParam>;
2+
pub type ReqwestQueryParam = (String, String);
3+
4+
/// URL Query component
5+
#[derive(Default, Debug)]
6+
pub struct Query {
7+
params: Vec<QueryParam>,
8+
}
9+
10+
impl Query {
11+
#[must_use]
12+
pub fn empty() -> Self {
13+
Self { params: vec![] }
14+
}
15+
16+
#[must_use]
17+
pub fn params(params: Vec<QueryParam>) -> Self {
18+
Self { params }
19+
}
20+
21+
pub fn add_param(&mut self, param: QueryParam) {
22+
self.params.push(param);
23+
}
24+
}
25+
26+
impl From<Query> for ReqwestQuery {
27+
fn from(url_search_params: Query) -> Self {
28+
url_search_params
29+
.params
30+
.iter()
31+
.map(|param| ReqwestQueryParam::from((*param).clone()))
32+
.collect()
33+
}
34+
}
35+
36+
/// URL query param
37+
#[derive(Clone, Debug)]
38+
pub struct QueryParam {
39+
name: String,
40+
value: String,
41+
}
42+
43+
impl QueryParam {
44+
#[must_use]
45+
pub fn new(name: &str, value: &str) -> Self {
46+
Self {
47+
name: name.to_string(),
48+
value: value.to_string(),
49+
}
50+
}
51+
}
52+
53+
impl From<QueryParam> for ReqwestQueryParam {
54+
fn from(param: QueryParam) -> Self {
55+
(param.name, param.value)
56+
}
57+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod http;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#[must_use]
2+
pub fn connection_with_invalid_token(bind_address: &str) -> ConnectionInfo {
3+
ConnectionInfo::authenticated(bind_address, "invalid token")
4+
}
5+
6+
#[must_use]
7+
pub fn connection_with_no_token(bind_address: &str) -> ConnectionInfo {
8+
ConnectionInfo::anonymous(bind_address)
9+
}
10+
11+
#[derive(Clone)]
12+
pub struct ConnectionInfo {
13+
pub bind_address: String,
14+
pub api_token: Option<String>,
15+
}
16+
17+
impl ConnectionInfo {
18+
#[must_use]
19+
pub fn authenticated(bind_address: &str, api_token: &str) -> Self {
20+
Self {
21+
bind_address: bind_address.to_string(),
22+
api_token: Some(api_token.to_string()),
23+
}
24+
}
25+
26+
#[must_use]
27+
pub fn anonymous(bind_address: &str) -> Self {
28+
Self {
29+
bind_address: bind_address.to_string(),
30+
api_token: None,
31+
}
32+
}
33+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod common;
2+
pub mod connection_info;
3+
pub mod v1;

0 commit comments

Comments
 (0)