Creates a new client for the cloud service that talks to `api_address`.
(api_address: &str)
| 97 | impl CloudService { |
| 98 | /// Creates a new client for the cloud service that talks to `api_address`. |
| 99 | pub fn new(api_address: &str) -> io::Result<Self> { |
| 100 | let url = match Url::parse(api_address) { |
| 101 | Ok(url) => url, |
| 102 | Err(e) => { |
| 103 | return Err(io::Error::new( |
| 104 | io::ErrorKind::InvalidInput, |
| 105 | format!("Invalid base API address: {}", e), |
| 106 | )); |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | if !(url.path().is_empty() || url.path() == "/") { |
| 111 | return Err(io::Error::new( |
| 112 | io::ErrorKind::InvalidInput, |
| 113 | "Invalid base API address: cannot contain a path".to_owned(), |
| 114 | )); |
| 115 | } |
| 116 | |
| 117 | let auth_data = Rc::from(RefCell::from(None)); |
| 118 | |
| 119 | Ok(Self { api_address: url, client: reqwest::Client::default(), auth_data }) |
| 120 | } |
| 121 | |
| 122 | /// Generates a service URL with the given `path`. |
| 123 | fn make_url(&self, path: &str) -> Url { |