Skip to content

Commit

Permalink
Added some async tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
lephyrius committed Nov 10, 2023
1 parent aee4e63 commit 564c912
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ heck = "0.5.0-rc.1"

[dev-dependencies]
mockito = "1"
tokio = {version = "1", features = ["full"]}

[build-dependencies]
prost-build = "0.12.1"
Expand Down
2 changes: 1 addition & 1 deletion src/apicalypse_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[derive(Default)]
#[derive(Default, Clone)]
pub struct ApicalypseBuilder {
filter: String,
limit: usize,
Expand Down
39 changes: 25 additions & 14 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,13 @@ impl Client {
/// This is the raw version of the request method.
/// It allows you to pass a query string directly.
/// ```
/// use igdb_api_rust::client::Client;
/// let mut client = Client::new("test","test");
/// let query = "fields name; limit 5;";
/// let response = client.request_raw::<igdb_api_rust::igdb::Game>(query);
/// #[tokio::main]
/// async fn main() {
/// use igdb_api_rust::client::Client;
/// let mut client = Client::new("test","test");
/// let query = "fields name; limit 5;";
/// let response = client.request_raw::<igdb_api_rust::igdb::Game>(query).await;
/// }
/// ```
pub async fn request_raw<M: prost::Message + Default>(
&mut self,
Expand All @@ -107,15 +110,20 @@ impl Client {

/// Request the IGDB API for a protobuf response for the count endpoint.
/// ```
/// use igdb_api_rust::apicalypse_builder::ApicalypseBuilder;
/// use igdb_api_rust::client::Client;
/// let mut client = Client::new("test","test");
/// let query = ApicalypseBuilder::default().filter("id > 1337");
/// let response = client.request_count::<igdb_api_rust::igdb::Game>(query);
///#[tokio::main]
/// async fn main() {
/// use igdb_api_rust::apicalypse_builder::ApicalypseBuilder;
/// use igdb_api_rust::client::Client;
/// let mut client = Client::new("test","test");
/// let query = ApicalypseBuilder::default().filter("id > 1337").clone();
/// let response = client.request_count::<igdb_api_rust::igdb::Game>(&query).await;
/// println!("{:?}", response);
///
/// }
/// ```
pub async fn request_count<M: prost::Message + Default>(
&mut self,
query: &'static ApicalypseBuilder,
query: & ApicalypseBuilder,
) -> Result<Count, IGDBApiError> {
let query_string = query.to_query();
self.request_count_raw::<M>(query_string.as_str()).await
Expand All @@ -125,10 +133,13 @@ impl Client {
/// This is the raw version of the request_count method.
/// It allows you to pass a query string directly.
/// ```
/// use igdb_api_rust::client::Client;
/// let mut client = Client::new("test","test");
/// let query = "w id > 1337";
/// let response = client.request_count_raw::<igdb_api_rust::igdb::Game>(query);
/// #[tokio::main]
/// async fn main() {
/// use igdb_api_rust::client::Client;
/// let mut client = Client::new("test","test");
/// let query = "w id > 1337";
/// let response = client.request_count_raw::<igdb_api_rust::igdb::Game>(query).await;
/// }
/// ```
pub async fn request_count_raw<M: prost::Message + Default>(
&mut self,
Expand Down

0 comments on commit 564c912

Please sign in to comment.