From 0496dbc8fdd829e7b37c62a91c98076c740308d0 Mon Sep 17 00:00:00 2001 From: Curtis McEnroe Date: Mon, 21 Dec 2015 22:40:18 -0500 Subject: [PATCH] Add Client struct --- src/client.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + 2 files changed, 49 insertions(+) create mode 100644 src/client.rs diff --git a/src/client.rs b/src/client.rs new file mode 100644 index 0000000..a532913 --- /dev/null +++ b/src/client.rs @@ -0,0 +1,48 @@ +//! Client. + +use std::marker::PhantomData; + +use hyper; + +use provider::Provider; + +/// OAuth 2.0 client. +pub struct Client { + http_client: hyper::Client, + client_id: String, + client_secret: String, + redirect_uri: Option, + provider: PhantomData

, +} + +impl Client

{ + /// Creates a client. + /// + /// # Examples + /// + /// ``` + /// use inth_oauth2::client::Client; + /// use inth_oauth2::provider::Google; + /// + /// let client = Client::::new( + /// Default::default(), + /// "CLIENT_ID", + /// "CLIENT_SECRET", + /// Some("urn:ietf:wg:oauth:2.0:oob") + /// ); + /// ``` + pub fn new( + http_client: hyper::Client, + client_id: S, + client_secret: S, + redirect_uri: Option + ) -> Self where S: Into { + Client { + http_client: http_client, + client_id: client_id.into(), + client_secret: client_secret.into(), + redirect_uri: redirect_uri.map(Into::into), + provider: PhantomData, + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 2d7e474..d487658 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,3 +5,4 @@ extern crate url; pub mod token; pub mod provider; +pub mod client;