11//! # Clever-Cloud Sdk
22//!
3- //! This module provides a client and structures to interact with clever-cloud
4- //! api.
3+ //! This module provides a client and structures to interact with Clever Cloud API.
54
6- use std :: fmt:: Debug ;
5+ use core :: fmt;
76
7+ use :: oauth10a:: client:: { Execute , reqwest:: IntoUrl } ;
88use serde:: { Deserialize , Serialize , de:: DeserializeOwned } ;
99
1010use crate :: oauth10a:: {
11- Client as OAuthClient , ClientError , Request , RestClient ,
11+ Client as OAuthClient , ClientError , RestClient ,
1212 reqwest:: { self , Method } ,
1313} ;
1414
@@ -46,7 +46,7 @@ pub fn default_consumer_secret() -> String {
4646// -----------------------------------------------------------------------------
4747// Credentials structure
4848
49- #[ derive( Serialize , Deserialize , PartialEq , Eq , Clone , Debug ) ]
49+ #[ derive( Serialize , Deserialize , PartialEq , Eq , Clone ) ]
5050#[ serde( untagged) ]
5151pub enum Credentials {
5252 OAuth1 {
@@ -71,6 +71,16 @@ pub enum Credentials {
7171 } ,
7272}
7373
74+ impl fmt:: Debug for Credentials {
75+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
76+ match self {
77+ Self :: OAuth1 { .. } => f. write_str ( "OAuth1" ) ,
78+ Self :: Basic { .. } => f. write_str ( "Basic" ) ,
79+ Self :: Bearer { .. } => f. write_str ( "Bearer" ) ,
80+ }
81+ }
82+ }
83+
7484impl Default for Credentials {
7585 #[ tracing:: instrument( skip_all) ]
7686 fn default ( ) -> Self {
@@ -208,80 +218,69 @@ pub struct Client {
208218 endpoint : String ,
209219}
210220
211- impl Request for Client {
221+ impl Execute for Client {
212222 type Error = ClientError ;
213223
214224 #[ cfg_attr( feature = "tracing" , tracing:: instrument) ]
225+ fn execute (
226+ & self ,
227+ request : reqwest:: Request ,
228+ ) -> impl Future < Output = Result < reqwest:: Response , Self :: Error > > + Send + ' static {
229+ self . inner . execute ( request)
230+ }
231+ }
232+
233+ impl < X : IntoUrl + Send + fmt:: Debug > RestClient < X > for Client {
215234 fn request < T , U > (
216235 & self ,
217236 method : & Method ,
218- endpoint : & str ,
237+ endpoint : X ,
219238 payload : & T ,
220- ) -> impl Future < Output = Result < U , Self :: Error > >
239+ ) -> impl Future < Output = Result < U , Self :: Error > > + Send
221240 where
222- T : Serialize + Debug + Send + Sync ,
223- U : DeserializeOwned + Debug + Send + Sync ,
241+ T : ? Sized + Serialize + fmt :: Debug + Send + Sync ,
242+ U : DeserializeOwned + fmt :: Debug + Send + Sync ,
224243 {
225244 self . inner . request ( method, endpoint, payload)
226245 }
227246
228247 #[ cfg_attr( feature = "tracing" , tracing:: instrument) ]
229- fn execute (
230- & self ,
231- request : reqwest:: Request ,
232- ) -> impl Future < Output = Result < reqwest:: Response , Self :: Error > > {
233- self . inner . execute ( request)
234- }
235- }
236-
237- impl RestClient for Client {
238- type Error = ClientError ;
239-
240- #[ cfg_attr( feature = "tracing" , tracing:: instrument) ]
241- fn get < T > ( & self , endpoint : & str ) -> impl Future < Output = Result < T , Self :: Error > >
248+ fn get < T > ( & self , endpoint : X ) -> impl Future < Output = Result < T , Self :: Error > >
242249 where
243- T : DeserializeOwned + Debug + Send + Sync ,
250+ T : DeserializeOwned + fmt :: Debug + Send + Sync ,
244251 {
245252 self . inner . get ( endpoint)
246253 }
247254
248255 #[ cfg_attr( feature = "tracing" , tracing:: instrument) ]
249- fn post < T , U > (
250- & self ,
251- endpoint : & str ,
252- payload : & T ,
253- ) -> impl Future < Output = Result < U , Self :: Error > >
256+ fn post < T , U > ( & self , endpoint : X , payload : & T ) -> impl Future < Output = Result < U , Self :: Error > >
254257 where
255- T : Serialize + Debug + Send + Sync ,
256- U : DeserializeOwned + Debug + Send + Sync ,
258+ T : Serialize + fmt :: Debug + Send + Sync + ? Sized ,
259+ U : DeserializeOwned + fmt :: Debug + Send + Sync ,
257260 {
258261 self . inner . post ( endpoint, payload)
259262 }
260263
261264 #[ cfg_attr( feature = "tracing" , tracing:: instrument) ]
262- fn put < T , U > ( & self , endpoint : & str , payload : & T ) -> impl Future < Output = Result < U , Self :: Error > >
265+ fn put < T , U > ( & self , endpoint : X , payload : & T ) -> impl Future < Output = Result < U , Self :: Error > >
263266 where
264- T : Serialize + Debug + Send + Sync ,
265- U : DeserializeOwned + Debug + Send + Sync ,
267+ T : Serialize + fmt :: Debug + Send + Sync + ? Sized ,
268+ U : DeserializeOwned + fmt :: Debug + Send + Sync ,
266269 {
267270 self . inner . put ( endpoint, payload)
268271 }
269272
270273 #[ cfg_attr( feature = "tracing" , tracing:: instrument) ]
271- fn patch < T , U > (
272- & self ,
273- endpoint : & str ,
274- payload : & T ,
275- ) -> impl Future < Output = Result < U , Self :: Error > >
274+ fn patch < T , U > ( & self , endpoint : X , payload : & T ) -> impl Future < Output = Result < U , Self :: Error > >
276275 where
277- T : Serialize + Debug + Send + Sync ,
278- U : DeserializeOwned + Debug + Send + Sync ,
276+ T : Serialize + fmt :: Debug + Send + Sync + ? Sized ,
277+ U : DeserializeOwned + fmt :: Debug + Send + Sync ,
279278 {
280279 self . inner . patch ( endpoint, payload)
281280 }
282281
283282 #[ cfg_attr( feature = "tracing" , tracing:: instrument) ]
284- fn delete ( & self , endpoint : & str ) -> impl Future < Output = Result < ( ) , Self :: Error > > {
283+ fn delete ( & self , endpoint : X ) -> impl Future < Output = Result < ( ) , Self :: Error > > {
285284 self . inner . delete ( endpoint)
286285 }
287286}
0 commit comments