-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
343 additions
and
37 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
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
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
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,78 @@ | ||
//!Minds data | ||
|
||
use serde_derive::{Serialize, Deserialize}; | ||
|
||
use crate::data::PostFlags; | ||
|
||
///Auth payload | ||
#[derive(Serialize, Debug)] | ||
pub struct Auth<'a> { | ||
grant_type: &'static str, | ||
client_id: &'static str, | ||
username: &'a str, | ||
password: &'a str, | ||
} | ||
|
||
impl<'a> Auth<'a> { | ||
///Creates new payload | ||
pub fn new(username: &'a str, password: &'a str) -> Self { | ||
Auth { | ||
grant_type: "password", | ||
client_id: "mobile", | ||
username, | ||
password, | ||
} | ||
} | ||
} | ||
|
||
///Payload for successful authorization | ||
#[derive(Deserialize, Debug)] | ||
pub struct Oauth2 { | ||
///Access token | ||
pub access_token: String, | ||
///Expiration time(units?) | ||
pub expires_in: u64, | ||
///Request's textual status | ||
pub status: String, | ||
} | ||
|
||
///Payload for post | ||
#[derive(Serialize, Debug)] | ||
pub struct Post<'a> { | ||
wire_threshold: Option<String>, | ||
message: &'a str, | ||
is_rich: u8, | ||
title: Option<String>, | ||
description: Option<String>, | ||
thumbnail: Option<String>, | ||
url: Option<String>, | ||
attachment_guid: &'a Option<String>, | ||
///Whether content is safe for work or not | ||
pub mature: u8, | ||
access_id: u8, | ||
} | ||
|
||
impl<'a> Post<'a> { | ||
///Creates new post | ||
pub fn new(message: &'a str, attachment_guid: &'a Option<String>, flags: &PostFlags) -> Self { | ||
Post { | ||
wire_threshold: None, | ||
message, | ||
is_rich: 0, | ||
title: None, | ||
description: None, | ||
thumbnail: None, | ||
url: None, | ||
attachment_guid, | ||
mature: flags.nsfw as u8, | ||
access_id: 2, | ||
} | ||
} | ||
} | ||
|
||
///Response to successful upload/post | ||
#[derive(Deserialize, Debug)] | ||
pub struct UploadResponse { | ||
///Newly created entity ID | ||
pub guid: String, | ||
} |
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,47 @@ | ||
use std::error::Error; | ||
use std::fmt; | ||
|
||
#[repr(u8)] | ||
#[derive(Debug)] | ||
///Minds errors | ||
pub enum MindsError { | ||
///Authorization failed. | ||
LoginFailed, | ||
///Failed to send request to upload image. | ||
ImageUploadSendError, | ||
///Server rejected image upload. | ||
ImageUploadServerReject, | ||
///Server responded with invalid data. | ||
/// | ||
///Should contain `id` | ||
ImageUploadInvalidResponse, | ||
///Failed to send request to perform text post. | ||
PostUploadSendError, | ||
///Server rejected posting. | ||
PostUploadServerReject, | ||
///Server responded with invalid data | ||
/// | ||
///Should contain `id` | ||
PostUploadInvalidResponse, | ||
|
||
} | ||
|
||
impl fmt::Display for MindsError { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.description()) | ||
} | ||
} | ||
|
||
impl Error for MindsError { | ||
fn description(&self) -> &str { | ||
match self { | ||
&MindsError::LoginFailed => "Login has failed", | ||
&MindsError::ImageUploadSendError => "Failed to send request to upload image", | ||
&MindsError::ImageUploadServerReject => "Server rejected upload of image", | ||
&MindsError::ImageUploadInvalidResponse => "Server sent invalid response. Doesn't contain field id", | ||
&MindsError::PostUploadSendError => "Failed to send request to perform text post", | ||
&MindsError::PostUploadServerReject => "Server rejected posting", | ||
&MindsError::PostUploadInvalidResponse => "Server sent invalid response. Doesn't contain field id", | ||
} | ||
} | ||
} |
Oops, something went wrong.