Skip to content

Commit

Permalink
docs: Add some API documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mossop authored and andrey-yantsen committed Jan 25, 2023
1 parent 00643a3 commit 0364392
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/plex-api/src/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ impl HttpClient {
request
}

/// Verifies that this client has an authentication token.
pub fn is_authenticated(&self) -> bool {
!self.x_plex_token.is_empty()
}

/// Begins building a request using the HTTP POST method.
pub fn post<T>(&self, path: T) -> RequestBuilder<'_, T>
where
PathAndQuery: TryFrom<T>,
Expand Down Expand Up @@ -127,6 +129,7 @@ impl HttpClient {
}
}

/// Begins building a request using the HTTP GET method.
pub fn get<T>(&self, path: T) -> RequestBuilder<'_, T>
where
PathAndQuery: TryFrom<T>,
Expand Down Expand Up @@ -155,6 +158,7 @@ impl HttpClient {
}
}

/// Begins building a request using the HTTP PUT method.
pub fn put<T>(&self, path: T) -> RequestBuilder<'_, T>
where
PathAndQuery: TryFrom<T>,
Expand Down Expand Up @@ -183,6 +187,7 @@ impl HttpClient {
}
}

/// Begins building a request using the HTTP DELETE method.
pub fn delete<T>(&self, path: T) -> RequestBuilder<'_, T>
where
PathAndQuery: TryFrom<T>,
Expand Down Expand Up @@ -241,6 +246,7 @@ where
PathAndQuery: TryFrom<P>,
<PathAndQuery as TryFrom<P>>::Error: Into<http::Error>,
{
/// Adds a body to the request.
pub fn body<B>(self, body: B) -> Result<Request<'a, B>>
where
B: Into<AsyncBody> + std::fmt::Debug,
Expand All @@ -256,13 +262,15 @@ where
})
}

/// Adds a form encoded parameters to the request body.
pub fn form(self, params: &[(&str, &str)]) -> Result<Request<'a, String>> {
let body = serde_urlencoded::to_string(params)?;
self.header("Content-type", "application/x-www-form-urlencoded")
.header("Content-Length", body.len().to_string())
.body(body)
}

/// Adds a request header.
pub fn header<K, V>(self, key: K, value: V) -> RequestBuilder<'a, P>
where
http::header::HeaderName: TryFrom<K>,
Expand All @@ -278,6 +286,7 @@ where
}
}

/// Sends this request generating a response.
pub async fn send(self) -> Result<HttpResponse<AsyncBody>> {
self.body(())?.send().await
}
Expand Down

0 comments on commit 0364392

Please sign in to comment.