Skip to content

Commit

Permalink
Fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
ANF-Studios committed Jan 23, 2021
1 parent 39f8dac commit f60c559
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ More from the [examples](./examples/) and [documentation](https://docs.rs/pastem
| Edit pastes |||
| Delete pastes |||
| Get Users |||
| Check if a user exists || |
| Check if a user exists | | |
| Get a language by name |||
| Get a language by extension |||
| Time expires in to a unix timestamp |||
Expand Down
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// h
#[allow(dead_code, unused_variables)]
pub mod user {
const USER_ENDPOINT: &str = "https://paste.myst.rs/user/";
const USER_ENDPOINT: &str = "https://paste.myst.rs/api/v2/user/";

pub fn user_exists(username: &str) -> Result<bool, reqwest::Error> {
let result = reqwest::blocking::Client::builder()
Expand All @@ -13,6 +14,17 @@ pub mod user {
Ok(user_exists)
}

pub async fn user_exists_async(username: &str) -> Result<bool, reqwest::Error> {
let result = reqwest::Client::builder()
.build()?
.get(&parse_user_get(username))
.send().await?;
let mut user_exists: bool = false;
if result.status().as_u16() == 200 { user_exists = true; }
else if result.status().as_u16() == 404 { user_exists = false; }
Ok(user_exists)
}

/// Parses a user `GET` url endpoint.
fn parse_user(username: &str) -> String { return format!("{}{}", USER_ENDPOINT, username) }
/// Parses a user exists url endpoint.
Expand All @@ -24,7 +36,7 @@ pub mod user {
/// `GET` and `POST` (send) a paste
/// to [pastemyst](https://paste.myst.rs).
///
/// ### [API Docs]
/// ### API Docs
/// Here is the official PasteMyst API
/// documentation:
/// https://paste.myst.rs/api-docs/index
Expand Down

0 comments on commit f60c559

Please sign in to comment.