use http::Method;
use serde::Deserialize;
use crate::core::operation::Operation;
use crate::error::Result;
#[allow(missing_docs)]
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct LocationContactsResponse {
pub friends: Vec<crate::types::ContactLocation>,
}
#[allow(missing_docs)]
#[derive(Debug, Clone, Deserialize)]
#[non_exhaustive]
pub struct RefreshLocationResponse {
pub success: Option<bool>,
pub friends: Option<Vec<crate::types::ContactLocation>>,
}
#[derive(Debug, Clone, Default)]
pub struct ListLocationContacts;
impl Operation for ListLocationContacts {
type Output = LocationContactsResponse;
const METHOD: Method = Method::GET;
fn path(&self) -> String {
"/location/contacts".into()
}
}
#[allow(missing_docs)]
#[derive(Debug, Clone)]
pub struct GetLocationContact {
pub handle: String,
}
impl Operation for GetLocationContact {
type Output = crate::types::ContactLocation;
const METHOD: Method = Method::GET;
fn path(&self) -> String {
format!("/location/contacts/{}", self.handle)
}
}
#[derive(Debug, Clone, Default)]
pub struct RefreshLocationContacts;
impl Operation for RefreshLocationContacts {
type Output = RefreshLocationResponse;
const METHOD: Method = Method::POST;
fn path(&self) -> String {
"/location/contacts/refresh".into()
}
}
#[derive(Debug)]
pub struct Location<'c, C> {
pub(crate) client: &'c C,
}
#[cfg(feature = "async")]
impl crate::Client {
pub fn location(&self) -> Location<'_, crate::Client> {
Location { client: self }
}
}
#[cfg(feature = "sync")]
impl crate::BlockingClient {
pub fn location(&self) -> Location<'_, crate::BlockingClient> {
Location { client: self }
}
}
#[cfg(feature = "async")]
impl Location<'_, crate::Client> {
pub async fn list(&self) -> Result<LocationContactsResponse> {
self.client.send(ListLocationContacts).await
}
pub async fn get(&self, handle: impl Into<String>) -> Result<crate::types::ContactLocation> {
self.client
.send(GetLocationContact {
handle: handle.into(),
})
.await
}
pub async fn refresh(&self) -> Result<RefreshLocationResponse> {
self.client.send(RefreshLocationContacts).await
}
}
#[cfg(feature = "sync")]
impl Location<'_, crate::BlockingClient> {
pub fn list(&self) -> Result<LocationContactsResponse> {
self.client.send(ListLocationContacts)
}
pub fn get(&self, handle: impl Into<String>) -> Result<crate::types::ContactLocation> {
self.client.send(GetLocationContact {
handle: handle.into(),
})
}
pub fn refresh(&self) -> Result<RefreshLocationResponse> {
self.client.send(RefreshLocationContacts)
}
}
#[cfg(test)]
#[allow(
clippy::unwrap_used,
clippy::expect_used,
clippy::panic,
clippy::print_stdout,
clippy::unreadable_literal
)]
mod tests {
use super::*;
use crate::core::operation::Operation;
#[test]
fn list_location_contacts_method_is_get() {
assert_eq!(ListLocationContacts::METHOD, http::Method::GET);
}
#[test]
fn list_location_contacts_path() {
assert_eq!(ListLocationContacts.path(), "/location/contacts");
}
#[test]
fn get_location_contact_method_is_get() {
assert_eq!(GetLocationContact::METHOD, http::Method::GET);
}
#[test]
fn get_location_contact_path_interpolates_handle() {
let op = GetLocationContact {
handle: "abc123".into(),
};
assert_eq!(op.path(), "/location/contacts/abc123");
}
#[test]
fn refresh_location_contacts_method_is_post() {
assert_eq!(RefreshLocationContacts::METHOD, http::Method::POST);
}
#[test]
fn refresh_location_contacts_path() {
assert_eq!(RefreshLocationContacts.path(), "/location/contacts/refresh");
}
}