-
-
Notifications
You must be signed in to change notification settings - Fork 7
chore(lib): continuation of v3 refactor (see #117) #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3c81982
fix!: adjustments after refactor
Rolv-Apneseth 198feec
Update README.md
Rolv-Apneseth b3f3450
docs(changelog): remove mention of support for markdown and typst fil…
Rolv-Apneseth 3744b2f
refactor: use `check::Request`, `check::Response` and `check::Respons…
Rolv-Apneseth 4253d2f
chore: formatting
Rolv-Apneseth fccae51
fix: minimum Rust version needs to be higher for `clap`
Rolv-Apneseth 2f2c7f6
fix: doc test
Rolv-Apneseth 43de210
refactor: use crate's result type for the `check` method on `Client`
Rolv-Apneseth 917e6c8
refactor: use crate's result type for the `languages` method on `Client`
Rolv-Apneseth 82a3e5c
Merge branch 'v3' into v3-continued
jeertmans c823438
Update src/api/mod.rs
Rolv-Apneseth 7ad54db
Update src/api/mod.rs
Rolv-Apneseth ca1db35
fix: convert `reqwest` error
Rolv-Apneseth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,64 +1,71 @@ | ||
/// Raw bindings to the LanguageTool API v1.1.2. | ||
/// | ||
/// The current bindings were generated using the | ||
/// [HTTP API documentation](https://languagetool.org/http-api/). | ||
/// | ||
/// Unfortunately, the LanguageTool API is not as documented as we could | ||
/// hope, and resquests might return undocumented fields. Those are deserialized | ||
/// to the `undocumented` field. | ||
//! Raw bindings to the LanguageTool API v1.1.2. | ||
//! | ||
//! The current bindings were generated using the | ||
//! [HTTP API documentation](https://languagetool.org/http-api/). | ||
//! | ||
//! Unfortunately, the LanguageTool API is not as documented as we could | ||
//! hope, and requests might return undocumented fields. Those are de-serialized | ||
//! to the `undocumented` field. | ||
pub mod check; | ||
pub mod languages; | ||
pub mod server; | ||
pub mod words; | ||
|
||
/// A HTTP client for making requests to some LanguageTool server. | ||
/// A HTTP client for making requests to a LanguageTool server. | ||
#[derive(Debug)] | ||
pub struct Client { | ||
/// Server's hostname. | ||
hostname: String, | ||
/// Server's port. | ||
port: Option<String>, | ||
/// Inner client to perform HTTP requets. | ||
/// Inner client to perform HTTP requests. | ||
client: reqwest::Client, | ||
} | ||
|
||
impl Default for Client { | ||
fn default() -> Self { | ||
Self { | ||
hostname: "https://api.languagetoolplus.com".to_string(), | ||
..Default::default() | ||
port: None, | ||
client: Default::default(), | ||
} | ||
} | ||
} | ||
|
||
impl Client { | ||
/// Construct a HTTP url base on the current hostname, optional port, | ||
/// Construct an HTTP URL base on the current hostname, optional port, | ||
/// and provided endpoint. | ||
#[inline] | ||
#[must_use] | ||
pub fn url(&self, endpoint: &str) -> String { | ||
let hostname = self.hostname; | ||
match self.port { | ||
let hostname = &self.hostname; | ||
match &self.port { | ||
Some(p) => format!("{hostname}:{p}/v2{endpoint}"), | ||
None => format!("{hostname}/v2{endpoint}"), | ||
} | ||
} | ||
|
||
/// Send a check request to the server and await for the response. | ||
pub async fn check(&self, request: &check::Request) -> Result<check::Response> { | ||
pub async fn check( | ||
&self, | ||
request: &check::CheckRequest, | ||
) -> reqwest::Result<check::CheckResponse> { | ||
self.client | ||
.post(self.url("/check")) | ||
.query(request) | ||
.send() | ||
.await? | ||
.json::<check::Response>() | ||
.json::<check::CheckResponse>() | ||
.await | ||
} | ||
|
||
/// Send a words request to the server and await for the response. | ||
pub async fn languages(&self, request: &languages::Request) -> Result<languages::Response> { | ||
/// Send a request for the list of supported languages to the server and await for the response. | ||
pub async fn languages(&self) -> reqwest::Result<languages::Response> { | ||
self.client | ||
.get(self.url("/languages")) | ||
.query(request) | ||
.send() | ||
.await? | ||
.json::<check::Response>() | ||
.json::<languages::Response>() | ||
.await | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.