-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
509: Add total field to get-tasks route r=curquiza a=hmacr # Pull Request ## Related issue Fixes #504 ## What does this PR do? - Adds `total` field to `get-tasks` route ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! 516: Implement client for experimental-features API r=curquiza a=hmacr # Pull Request ## Related issue Needed for #498 & #501, since these issues involve updating the experimental-feature as a pre-requisite ## What does this PR do? - Introduces the experimental-features client in the SDK - Implements the `get` and `patch` endpoint. - Adds code-samples and tests. ## PR checklist Please check if your PR fulfills the following requirements: - [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)? - [x] Have you read the contributing guidelines? - [x] Have you made sure that the title is accurate and descriptive of the changes? Thank you so much for contributing to Meilisearch! Co-authored-by: hmacr <hmac.devo@gmail.com> Co-authored-by: Clémentine U. - curqui <clementine@meilisearch.com>
- Loading branch information
Showing
4 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
use crate::{ | ||
request::{request, Method}, | ||
Client, Error, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// Struct representing the experimental features result from the API. | ||
#[derive(Clone, Debug, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ExperimentalFeaturesResult { | ||
pub score_details: bool, | ||
pub vector_store: bool, | ||
} | ||
|
||
/// Struct representing the experimental features request. | ||
/// | ||
/// You can build this struct using the builder pattern. | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// # use meilisearch_sdk::{Client, ExperimentalFeatures}; | ||
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); | ||
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); | ||
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); | ||
/// let mut features = ExperimentalFeatures::new(&client); | ||
/// features.set_score_details(true); | ||
/// ``` | ||
#[derive(Debug, Serialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct ExperimentalFeatures<'a> { | ||
#[serde(skip_serializing)] | ||
client: &'a Client, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub score_details: Option<bool>, | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub vector_store: Option<bool>, | ||
} | ||
|
||
impl<'a> ExperimentalFeatures<'a> { | ||
pub fn new(client: &'a Client) -> Self { | ||
ExperimentalFeatures { | ||
client, | ||
score_details: None, | ||
vector_store: None, | ||
} | ||
} | ||
|
||
pub fn set_score_details(&mut self, score_details: bool) -> &mut Self { | ||
self.score_details = Some(score_details); | ||
self | ||
} | ||
|
||
pub fn set_vector_store(&mut self, vector_store: bool) -> &mut Self { | ||
self.vector_store = Some(vector_store); | ||
self | ||
} | ||
|
||
/// Get all the experimental features | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// # use meilisearch_sdk::{Client, ExperimentalFeatures}; | ||
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); | ||
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); | ||
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); | ||
/// futures::executor::block_on(async move { | ||
/// let features = ExperimentalFeatures::new(&client); | ||
/// features.get().await.unwrap(); | ||
/// }); | ||
/// ``` | ||
pub async fn get(&self) -> Result<ExperimentalFeaturesResult, Error> { | ||
request::<(), (), ExperimentalFeaturesResult>( | ||
&format!("{}/experimental-features", self.client.host), | ||
self.client.get_api_key(), | ||
Method::Get { query: () }, | ||
200, | ||
) | ||
.await | ||
} | ||
|
||
/// Update the experimental features | ||
/// | ||
/// # Example | ||
/// | ||
/// ``` | ||
/// # use meilisearch_sdk::{Client, ExperimentalFeatures}; | ||
/// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700"); | ||
/// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey"); | ||
/// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY)); | ||
/// futures::executor::block_on(async move { | ||
/// let mut features = ExperimentalFeatures::new(&client); | ||
/// features.set_score_details(true); | ||
/// features.update().await.unwrap(); | ||
/// }); | ||
/// ``` | ||
pub async fn update(&self) -> Result<ExperimentalFeaturesResult, Error> { | ||
request::<(), &Self, ExperimentalFeaturesResult>( | ||
&format!("{}/experimental-features", self.client.host), | ||
self.client.get_api_key(), | ||
Method::Patch { | ||
query: (), | ||
body: self, | ||
}, | ||
200, | ||
) | ||
.await | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use meilisearch_test_macro::meilisearch_test; | ||
|
||
#[meilisearch_test] | ||
async fn test_experimental_features_get(client: Client) { | ||
let mut features = ExperimentalFeatures::new(&client); | ||
features.set_score_details(false); | ||
features.set_vector_store(false); | ||
let _ = features.update().await.unwrap(); | ||
|
||
let res = features.get().await.unwrap(); | ||
|
||
assert!(!res.score_details); | ||
assert!(!res.vector_store); | ||
} | ||
|
||
#[meilisearch_test] | ||
async fn test_experimental_features_enable_score_details(client: Client) { | ||
let mut features = ExperimentalFeatures::new(&client); | ||
features.set_score_details(true); | ||
|
||
let res = features.update().await.unwrap(); | ||
|
||
assert!(res.score_details); | ||
} | ||
|
||
#[meilisearch_test] | ||
async fn test_experimental_features_enable_vector_store(client: Client) { | ||
let mut features = ExperimentalFeatures::new(&client); | ||
features.set_vector_store(true); | ||
|
||
let res = features.update().await.unwrap(); | ||
|
||
assert!(res.vector_store); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters