summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bin/main.rs2
-rw-r--r--src/client.rs9
-rw-r--r--src/helix/namespaces/auth.rs2
-rw-r--r--src/helix/namespaces/clips.rs9
-rw-r--r--src/helix/namespaces/mod.rs2
-rw-r--r--src/helix/namespaces/users.rs17
-rw-r--r--src/helix/namespaces/videos.rs20
-rw-r--r--src/namespace/auth.rs13
-rw-r--r--src/types.rs11
9 files changed, 48 insertions, 37 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs
index 9be688b..b8025d9 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -70,7 +70,7 @@ fn main() {
let u = helix_client
.users()
- .users(vec!(), vec!("freakey"))
+ .users(&vec!(), &vec!("freakey"))
.map(|res| {println!("{:?}", res); ()})
.map_err(|res| {println!("{:?}", res); ()});
diff --git a/src/client.rs b/src/client.rs
index 66f32d6..a8bc0b5 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -28,6 +28,7 @@ pub trait PaginationTrait {
fn cursor<'a>(&'a self) -> Option<&'a str>;
}
+pub type ParamList<'a> = BTreeMap<&'a str, &'a dyn ToString>;
#[derive(Clone)]
pub struct Client {
@@ -408,7 +409,7 @@ struct RequestRef {
impl RequestRef {
pub fn new(url: String,
- params: BTreeMap<&str, &str>,
+ params: BTreeMap<&str, &dyn ToString>,
client: Client,
method: Method,
ratelimit: Option<RatelimitKey>,
@@ -416,7 +417,7 @@ impl RequestRef {
{
let mut owned_params = BTreeMap::new();
for (key, value) in params {
- owned_params.insert(key.to_owned(), value.to_owned());
+ owned_params.insert(key.to_string(), value.to_string());
}
RequestRef {
@@ -461,7 +462,7 @@ pub struct IterableApiRequest<T> {
impl<T: DeserializeOwned + PaginationTrait + 'static + Send> ApiRequest<T> {
pub fn new(url: String,
- params: BTreeMap<&str, &str>,
+ params: BTreeMap<&str, &dyn ToString>,
client: Client,
method: Method,
ratelimit: Option<RatelimitKey>,
@@ -480,7 +481,7 @@ impl<T: DeserializeOwned + PaginationTrait + 'static + Send> ApiRequest<T> {
impl<T: DeserializeOwned + PaginationTrait + 'static + Send> IterableApiRequest<T> {
pub fn new(url: String,
- params: BTreeMap<&str, &str>,
+ params: BTreeMap<&str, &dyn ToString>,
client: Client,
method: Method,
ratelimit: Option<RatelimitKey>
diff --git a/src/helix/namespaces/auth.rs b/src/helix/namespaces/auth.rs
index 1900fbf..d006e2f 100644
--- a/src/helix/namespaces/auth.rs
+++ b/src/helix/namespaces/auth.rs
@@ -8,7 +8,7 @@ type AuthNamespace = Namespace<Auth>;
impl AuthNamespace {
pub fn client_credentials(self, secret: &str)
-> ApiRequest<Credentials> {
- auth::client_credentials(self.client.inner, secret)
+ auth::client_credentials(self.client.inner, &secret)
}
}
diff --git a/src/helix/namespaces/clips.rs b/src/helix/namespaces/clips.rs
index 1de2e33..c4595ce 100644
--- a/src/helix/namespaces/clips.rs
+++ b/src/helix/namespaces/clips.rs
@@ -1,12 +1,11 @@
use super::*;
use super::models::{DataContainer, Clip};
-use crate::types::ClipId;
pub struct Clips {}
type ClipsNamespace = Namespace<Clips>;
impl ClipsNamespace {
- pub fn clip(self, id: &ClipId) -> ApiRequest<DataContainer<Clip>> {
+ pub fn clip<S: ToString>(self, id: &S) -> ApiRequest<DataContainer<Clip>> {
use self::clip;
clip(self.client, id)
}
@@ -19,15 +18,15 @@ impl Client {
}
-pub fn clip(client: Client, id: &ClipId)
+pub fn clip<S: ToString>(client: Client, id: &S)
-> ApiRequest<DataContainer<Clip>>
{
let client = client.inner;
let url =
String::from("https://") +
- client.domain() + "/helix/clips" + "?id=" + id.as_ref();
+ client.domain() + "/helix/clips" + "?id=" + &id.to_string();
- let params = BTreeMap::new();
+ let params : ParamList = BTreeMap::new();
ApiRequest::new(url, params, client, Method::GET, Some(RatelimitKey::Default))
}
diff --git a/src/helix/namespaces/mod.rs b/src/helix/namespaces/mod.rs
index 8adc1e3..1d4239a 100644
--- a/src/helix/namespaces/mod.rs
+++ b/src/helix/namespaces/mod.rs
@@ -1,7 +1,7 @@
use std::marker::PhantomData;
pub use super::Client;
-pub use crate::client::{RatelimitKey, ClientTrait, ApiRequest, IterableApiRequest};
+pub use crate::client::{RatelimitKey, ClientTrait, ApiRequest, IterableApiRequest, ParamList};
pub use std::collections::BTreeMap;
pub use reqwest::Method;
pub use super::models;
diff --git a/src/helix/namespaces/users.rs b/src/helix/namespaces/users.rs
index 20f2914..2e922d6 100644
--- a/src/helix/namespaces/users.rs
+++ b/src/helix/namespaces/users.rs
@@ -1,13 +1,12 @@
use super::*;
use super::models::{DataContainer, User};
-use crate::types::UserId;
+use std::string::ToString;
pub struct Users {}
type UsersNamespace = Namespace<Users>;
impl UsersNamespace {
- pub fn users(self, ids: Vec<&UserId>, logins: Vec<&str>)
- -> ApiRequest<DataContainer<User>> {
+ pub fn users<S: ToString>(self, ids: &[S], logins: &[S]) -> ApiRequest<DataContainer<User>> {
use self::users;
users(self.client, ids, logins)
}
@@ -19,18 +18,18 @@ impl Client {
}
}
-pub fn users(
+pub fn users<S: ToString>(
client: Client,
- ids: Vec<&UserId>,
- logins: Vec<&str>,
+ ids: &[S],
+ logins: &[S],
) -> ApiRequest<DataContainer<User>> {
let client = client.inner;
let url =
String::from("https://") + client.domain() + &String::from("/helix/users");
- let mut params = BTreeMap::new();
+ let mut params: BTreeMap<&str, &dyn ToString> = BTreeMap::new();
for id in ids {
- params.insert("id", id.as_ref());
+ params.insert("id", id);
}
for login in logins {
@@ -41,5 +40,5 @@ pub fn users(
}
pub fn authed_as(client: Client) -> ApiRequest<DataContainer<User>> {
- users(client, Vec::with_capacity(0), Vec::with_capacity(0))
+ users(client, &[""], &[""])
}
diff --git a/src/helix/namespaces/videos.rs b/src/helix/namespaces/videos.rs
index 75b702e..9f2fd2b 100644
--- a/src/helix/namespaces/videos.rs
+++ b/src/helix/namespaces/videos.rs
@@ -7,7 +7,7 @@ pub struct Videos {}
type VideosNamespace = Namespace<Videos>;
impl VideosNamespace {
- pub fn by_id(self, ids: Vec<&VideoId>)
+ pub fn by_id<S: ToString>(self, ids: &[S])
-> IterableApiRequest<PaginationContainer<Video>> {
use self::by_id;
by_id(self.client, ids)
@@ -33,42 +33,42 @@ impl Client {
}
}
-pub fn by_id(client: Client, ids: Vec<&VideoId>)
+pub fn by_id<S: ToString>(client: Client, ids: &[S])
-> IterableApiRequest<PaginationContainer<Video>> {
let client = client.inner;
let url =
String::from("https://") + client.domain() + &String::from("/helix/videos");
- let mut params = BTreeMap::new();
+ let mut params: ParamList = BTreeMap::new();
for id in ids {
- params.insert("id", id.as_ref());
+ params.insert("id", id);
}
IterableApiRequest::new(url, params, client,
Method::GET, Some(RatelimitKey::Default))
}
-pub fn by_user(client: Client, user_id: &UserId)
+pub fn by_user<S: ToString>(client: Client, user_id: &S)
-> IterableApiRequest<PaginationContainer<Video>> {
let client = client.inner;
let url =
String::from("https://") + client.domain() + &String::from("/helix/videos");
- let mut params = BTreeMap::new();
- params.insert("user_id", user_id.as_ref());
+ let mut params: ParamList = BTreeMap::new();
+ params.insert("user_id", user_id);
IterableApiRequest::new(url, params, client,
Method::GET, Some(RatelimitKey::Default))
}
-pub fn for_game(client: Client, game_id: &GameId)
+pub fn for_game<S: ToString>(client: Client, game_id: &S)
-> IterableApiRequest<PaginationContainer<Video>> {
let client = client.inner;
let url =
String::from("https://") + client.domain() + &String::from("/helix/videos");
- let mut params = BTreeMap::new();
- params.insert("game_id", game_id.as_ref());
+ let mut params: ParamList = BTreeMap::new();
+ params.insert("game_id", game_id);
IterableApiRequest::new(url, params, client,
Method::GET, Some(RatelimitKey::Default))
diff --git a/src/namespace/auth.rs b/src/namespace/auth.rs
index c7a0c67..ff835bf 100644
--- a/src/namespace/auth.rs
+++ b/src/namespace/auth.rs
@@ -26,7 +26,7 @@ impl AuthNamespace {
pub fn client_credentials(self, secret: &str)
-> ApiRequest<Credentials> {
use self::client_credentials;
- client_credentials(self.client, secret)
+ client_credentials(self.client, &secret.to_owned())
}
}
@@ -37,18 +37,19 @@ impl Client {
}
//TODO: Implement scopes
-pub fn client_credentials(client: Client, secret: &str)
+pub fn client_credentials<S: ToString>(client: Client, secret: &S)
-> ApiRequest<Credentials> {
let url =
String::from("https://") +
client.auth_domain() + "/oauth2/token";
- let mut params = BTreeMap::new();
- params.insert("client_id", client.id());
+ let mut params : BTreeMap<&str, &dyn ToString> = BTreeMap::new();
+ let client_id = &client.id();
+ params.insert("client_id", &client_id);
params.insert("client_secret", secret);
- params.insert("grant_type", "client_credentials");
- params.insert("scope", "");
+ params.insert("grant_type", &"client_credentials");
+ params.insert("scope", &"");
ApiRequest::new(url, params, client.clone(), Method::POST, None)
}
diff --git a/src/types.rs b/src/types.rs
index 89375bb..56891d2 100644
--- a/src/types.rs
+++ b/src/types.rs
@@ -60,11 +60,13 @@ impl<'a, T> AsRef<str> for IntegerId<'a, T> {
use std::convert::Into;
+/*
impl<'a, T> Into<u32> for &'a IntegerId<'a, T> {
fn into(self) -> u32 {
self.int
}
}
+*/
impl<'a, T> Into<&'a str> for &'a IntegerId<'a, T> {
fn into(self) -> &'a str {
@@ -103,11 +105,13 @@ impl<'a, T> PartialEq<str> for IntegerId<'a, T> {
}
}
+/*
impl<'a, T> PartialEq<u32> for IntegerId<'a, T> {
fn eq(&self, other: &u32) -> bool {
self.int == *other
}
}
+*/
use serde::{Deserialize, Deserializer};
impl<'de, T> Deserialize<'de> for IntegerId<'static, T> {
@@ -143,6 +147,13 @@ impl Id {
}
}
+impl Display for Id {
+
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result
+ {
+ write!(f, "{}", &self.inner)
+ }
+}
impl AsRef<str> for Id {
fn as_ref(&self) -> &str {