File tree Expand file tree Collapse file tree 3 files changed +23
-5
lines changed
Expand file tree Collapse file tree 3 files changed +23
-5
lines changed Original file line number Diff line number Diff line change 11use super :: { Api , Result } ;
22use reqwest:: RequestBuilder ;
33use serde_json:: Value ;
4+ use std:: time:: Duration ;
45
56/// Client for accessing Listen Notes API.
67pub struct Client < ' a > {
@@ -13,15 +14,32 @@ pub struct Client<'a> {
1314impl Client < ' _ > {
1415 /// Creates new Listen API Client.
1516 ///
17+ /// Uses default HTTP client with 30 second timeouts.
18+ ///
1619 /// To access production API:
1720 /// ```
18- /// let client = podcast_api::Client::new(reqwest::Client::new(), Some("YOUR-API-KEY"));
21+ /// let client = podcast_api::Client::new(Some("YOUR-API-KEY"));
1922 /// ```
2023 /// To access mock API:
2124 /// ```
22- /// let client = podcast_api::Client::new(reqwest::Client::new(), None);
25+ /// let client = podcast_api::Client::new(None);
2326 /// ```
24- pub fn new ( client : reqwest:: Client , id : Option < & str > ) -> Client {
27+ pub fn new ( id : Option < & str > ) -> Client {
28+ Client {
29+ client : reqwest:: ClientBuilder :: new ( )
30+ . timeout ( Duration :: from_secs ( 30 ) )
31+ . build ( )
32+ . expect ( "Client::new()" ) ,
33+ api : if let Some ( id) = id {
34+ Api :: Production ( id)
35+ } else {
36+ Api :: Mock
37+ } ,
38+ }
39+ }
40+
41+ /// Creates new Listen API Client with user provided HTTP Client.
42+ pub fn new_custom ( client : reqwest:: Client , id : Option < & str > ) -> Client {
2543 Client {
2644 client,
2745 api : if let Some ( id) = id {
Original file line number Diff line number Diff line change 1111//! let api_key = None;
1212//!
1313//! // Create client
14- //! let client = podcast_api::Client::new(reqwest::Client::new(), api_key);
14+ //! let client = podcast_api::Client::new(api_key);
1515//!
1616//! // Call API
1717//! match client
Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ mod mock {
88 use serde_json:: json;
99
1010 fn client < ' a > ( ) -> podcast_api:: Client < ' a > {
11- podcast_api:: Client :: new ( reqwest :: Client :: new ( ) , None )
11+ podcast_api:: Client :: new ( None )
1212 }
1313
1414 #[ test]
You can’t perform that action at this time.
0 commit comments