Skip to content

Commit

Permalink
Add support for custom urls
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonxslays committed Dec 28, 2021
1 parent 0780480 commit 34c2d96
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "piston_rspy"
description = "Python bindings for piston_rs."
version = "0.3.1"
version = "0.3.2"
edition = "2021"
authors = ["Jonxslays"]
readme = "README.md"
Expand All @@ -20,4 +20,4 @@ crate-type = ["cdylib"]
pyo3 = { version = "0.15", features = ["extension-module"] }
pyo3-asyncio = { version = "0.15", features = ["tokio-runtime"] }
tokio = { version = "1" }
piston_rs = "^0.4.0"
piston_rs = "^0.4.1"
26 changes: 26 additions & 0 deletions piston_rspy/piston_rspy.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,32 @@ class Client:
key: `str`
The api key to use.
Returns:
`Client`: The new client.
"""
...
@staticmethod
def with_url(url: str) -> Client:
"""Creates a new client with a custom url.
Args:
url: `str`
The url to use as the underlying Piston backend.
Returns:
`Client`: The new client.
"""
...
@staticmethod
def with_url_and_key(url: str, key: str) -> Client:
"""Creates a new client with a custom url, and an api key.
Args:
url: `str`
The url to use as the underlying Piston backend.
key: `str`
The api key to use.
Returns:
`Client`: The new client.
"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "piston_rspy"
version = "0.3.1"
version = "0.3.2"
description = "Python bindings for piston_rs."
readme = "README.md"
author = "Jonxslays"
Expand Down
49 changes: 49 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,55 @@ impl Client {
Self { inner, headers }
}

/// Creates a new Client with a custom url and an api key.
///
/// ### Args:
///
/// - url `str`:
/// The url to use as the underlying piston backend.
///
/// - key `str`:
/// The api key to use.
///
/// ### Returns:
///
/// - `Client`: The new client.
#[staticmethod]
#[pyo3(text_signature = "(key: str, /) -> Client")]
fn with_url_and_key(url: String, key: String) -> Self {
let inner = Client_::with_url_and_key(&url, &key);
let headers = inner
.get_headers()
.iter()
.map(|(key, value)| (key.to_string(), value.to_str().unwrap().to_string()))
.collect();

Self { inner, headers }
}

/// Creates a new Client with a custom url.
///
/// ### Args:
///
/// - url `str`:
/// The url to use as the underlying piston backend.
///
/// ### Returns:
///
/// - `Client`: The new client.
#[staticmethod]
#[pyo3(text_signature = "(key: str, /) -> Client")]
fn with_url(url: String) -> Self {
let inner = Client_::with_url(&url);
let headers = inner
.get_headers()
.iter()
.map(|(key, value)| (key.to_string(), value.to_str().unwrap().to_string()))
.collect();

Self { inner, headers }
}

/// Creates a new client, with an api key.
///
/// ### Args:
Expand Down

0 comments on commit 34c2d96

Please sign in to comment.