Skip to content

Commit

Permalink
references. more work needed
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilgardis committed Aug 27, 2021
1 parent 8fd9309 commit 8d646a2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/mock_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async fn run() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>
.await?;

let user = client
.get_user_from_id(&*user_id, &token)
.get_user_from_id(&user_id, &token)
.await?
.expect("no user found");

Expand Down
8 changes: 4 additions & 4 deletions src/helix/client_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ impl<'a, C: crate::HttpClient<'a> + Sync> HelixClient<'a, C> {
/// Get [User](helix::users::User) from user id
pub async fn get_user_from_id<T>(
&'a self,
id: impl Into<types::UserId>,
id: impl AsRef<types::UserIdRef>,
token: &T,
) -> Result<Option<helix::users::User>, ClientError<'a, C>>
where
T: TwitchToken + ?Sized,
{
self.req_get(
helix::users::GetUsersRequest::builder()
.id(vec![id.into()])
.id(vec![id.as_ref()])
.build(),
token,
)
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<'a, C: crate::HttpClient<'a> + Sync> HelixClient<'a, C> {
/// ```
pub fn search_categories<T>(
&'a self,
query: impl Into<String>,
query: impl std::borrow::Borrow<&'a str>,
token: &'a T,
) -> std::pin::Pin<
Box<dyn futures::Stream<Item = Result<helix::search::Category, ClientError<'a, C>>> + 'a>,
Expand All @@ -110,7 +110,7 @@ impl<'a, C: crate::HttpClient<'a> + Sync> HelixClient<'a, C> {
T: TwitchToken + Send + Sync + ?Sized,
{
let req = helix::search::SearchCategoriesRequest::builder()
.query(query.into())
.query(*query.borrow())
.build();
make_stream(req, token, self, std::collections::VecDeque::from)
}
Expand Down
7 changes: 1 addition & 6 deletions src/helix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,7 @@ pub mod tags;
pub mod teams;
pub mod users;
pub mod videos;
#[allow(deprecated_in_future, deprecated)]
#[deprecated(
since = "0.6.0",
note = "webhooks are deprecated and decommisioned on 2021-09-16, use eventsub instead"
)]
pub mod webhooks;


pub(crate) mod ser;
pub(crate) use crate::deserialize_default_from_null;
Expand Down
2 changes: 1 addition & 1 deletion src/helix/search/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::{
types,
};
use serde::{Deserialize, Serialize};

use std::borrow::Cow;
pub mod search_categories;
pub mod search_channels;

Expand Down
18 changes: 9 additions & 9 deletions src/helix/search/search_categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,35 +45,35 @@ use helix::RequestGet;
/// [`search-categories`](https://dev.twitch.tv/docs/api/reference#search-categories)
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct SearchCategoriesRequest {
pub struct SearchCategoriesRequest<'a> {
/// URI encoded search query
#[builder(setter(into))]
pub query: String,
pub query: Cow<'a, str>,
/// Cursor for forward pagination: tells the server where to start fetching the next set of results, in a multi-page response. The cursor value specified here is from the pagination response field of a prior query.
#[builder(default)]
pub after: Option<helix::Cursor>,
pub after: Option<Cow<'a, helix::CursorRef>>,
/// Cursor for backward pagination: tells the server where to start fetching the next set of results, in a multi-page response. The cursor value specified here is from the pagination response field of a prior query.
#[builder(default)]
pub before: Option<helix::Cursor>,
pub before: Option<Cow<'a, helix::CursorRef>>,
/// Number of values to be returned per page. Limit: 100. Default: 20.
#[builder(setter(into), default)]
pub first: Option<String>,
pub first: Option<Cow<'a, str>>,
}

/// Return Values for [Search Categories](super::search_categories)
///
/// [`search-categories`](https://dev.twitch.tv/docs/api/reference#search-categories)
pub type Category = types::TwitchCategory;

impl Request for SearchCategoriesRequest {
impl Request for SearchCategoriesRequest<'_> {
type Response = Vec<Category>;

const PATH: &'static str = "search/categories";
#[cfg(feature = "twitch_oauth2")]
const SCOPE: &'static [twitch_oauth2::Scope] = &[];
}

impl RequestGet for SearchCategoriesRequest {
impl RequestGet for SearchCategoriesRequest<'_> {
fn parse_inner_response(
request: Option<Self>,
uri: &http::Uri,
Expand Down Expand Up @@ -101,8 +101,8 @@ impl RequestGet for SearchCategoriesRequest {
}
}

impl helix::Paginated for SearchCategoriesRequest {
fn set_pagination(&mut self, cursor: Option<helix::Cursor>) { self.after = cursor }
impl helix::Paginated for SearchCategoriesRequest<'_> {
fn set_pagination(&mut self, cursor: Option<helix::Cursor>) { self.after = cursor.map(Cow::Owned) }
}

#[cfg(test)]
Expand Down
12 changes: 7 additions & 5 deletions src/helix/users/get_users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
//! # let client: helix::HelixClient<'static, client::DummyHttpClient> = helix::HelixClient::default();
//! # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
//! # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
//! let s = twitch_api2::types::UserId::new("1234");
//! let request = get_users::GetUsersRequest::builder()
//! .id(vec!["1234".into()])
//! .id(vec!["1234".into(), "1234".into(), s.as_ref()])
//! .login(vec!["justintvfan".into()])
//! .build();
//! let response: Vec<get_users::User> = client.req_get(request, &token).await?.data;
Expand All @@ -45,10 +46,11 @@ use helix::RequestGet;
/// [`get-users`](https://dev.twitch.tv/docs/api/reference#get-users)
#[derive(PartialEq, typed_builder::TypedBuilder, Deserialize, Serialize, Clone, Debug)]
#[non_exhaustive]
pub struct GetUsersRequest {
pub struct GetUsersRequest<'a> {
/// User ID. Multiple user IDs can be specified. Limit: 100.
#[builder(default)]
pub id: Vec<types::UserId>,
#[serde(borrow = "'a")]
pub id: Vec<&'a types::UserIdRef>,
/// User login name. Multiple login names can be specified. Limit: 100.
#[builder(default)]
pub login: Vec<types::UserName>,
Expand Down Expand Up @@ -86,7 +88,7 @@ pub struct User {
pub view_count: usize,
}

impl Request for GetUsersRequest {
impl Request for GetUsersRequest<'_> {
type Response = Vec<User>;

#[cfg(feature = "twitch_oauth2")]
Expand All @@ -96,7 +98,7 @@ impl Request for GetUsersRequest {
const SCOPE: &'static [twitch_oauth2::Scope] = &[];
}

impl RequestGet for GetUsersRequest {}
impl RequestGet for GetUsersRequest<'_> {}

#[cfg(test)]
#[test]
Expand Down

0 comments on commit 8d646a2

Please sign in to comment.