From c8d86235c1371f1dbd5fbacbf5d8eaa9a990b5f5 Mon Sep 17 00:00:00 2001 From: mycognosist Date: Fri, 4 Feb 2022 10:06:36 +0200 Subject: [PATCH] add data type and methods to send invite requests --- src/api/dto/content.rs | 6 ++++++ src/api/helper.rs | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/api/dto/content.rs b/src/api/dto/content.rs index 7d8e9d2..344d295 100644 --- a/src/api/dto/content.rs +++ b/src/api/dto/content.rs @@ -189,3 +189,9 @@ pub struct FriendsHops { #[serde(skip_serializing_if = "Option::is_none")] pub start: Option, } + +/// Optional parameter for defining the number of times an invite can be used. +#[derive(Debug, Serialize, Deserialize)] +pub struct InviteCreateOptions { + pub uses: u16, +} diff --git a/src/api/helper.rs b/src/api/helper.rs index 6cee0e5..6b7e127 100644 --- a/src/api/helper.rs +++ b/src/api/helper.rs @@ -1,6 +1,7 @@ use crate::{ api::dto::content::{ - FriendsHops, RelationshipQuery, SubsetQuery, SubsetQueryOptions, TypedMessage, + FriendsHops, InviteCreateOptions, RelationshipQuery, SubsetQuery, SubsetQueryOptions, + TypedMessage, }, feed::Message, rpc::{Body, BodyType, RequestNo, RpcType, RpcWriter}, @@ -13,6 +14,8 @@ const MAX_RPC_BODY_LEN: usize = 65536; #[derive(Debug)] pub enum ApiMethod { + InviteCreate, + InviteUse, FriendsIsFollowing, FriendsIsBlocking, FriendsHops, @@ -31,6 +34,8 @@ impl ApiMethod { pub fn selector(&self) -> &'static [&'static str] { use ApiMethod::*; match self { + InviteCreate => &["invite", "create"], + InviteUse => &["invite", "use"], FriendsIsFollowing => &["friends", "isFollowing"], FriendsIsBlocking => &["friends", "isBlocking"], FriendsHops => &["friends", "hops"], @@ -48,6 +53,8 @@ impl ApiMethod { pub fn from_selector(s: &[&str]) -> Option { use ApiMethod::*; match s { + ["invite", "create"] => Some(InviteCreate), + ["invite", "use"] => Some(InviteUse), ["friends", "isFollowing"] => Some(FriendsIsFollowing), ["friends", "isBlocking"] => Some(FriendsIsBlocking), ["friends", "hops"] => Some(FriendsHops), @@ -82,6 +89,35 @@ impl ApiCaller { &mut self.rpc } + /// Send ["invite", "create"] request. + pub async fn invite_create_req_send(&mut self, uses: u16) -> Result { + let args = InviteCreateOptions { uses }; + let req_no = self + .rpc + .send_request( + ApiMethod::InviteCreate.selector(), + RpcType::Async, + &args, + &None::<()>, + ) + .await?; + Ok(req_no) + } + + /// Send ["invite", "use"] request. + pub async fn invite_use_req_send(&mut self, invite_code: &str) -> Result { + let req_no = self + .rpc + .send_request( + ApiMethod::InviteUse.selector(), + RpcType::Async, + &invite_code, + &None::<()>, + ) + .await?; + Ok(req_no) + } + /// Send ["friends", "isFollowing"] request. pub async fn friends_is_following_req_send( &mut self,