summaryrefslogtreecommitdiffstats
path: root/src/registration.rs
diff options
context:
space:
mode:
authorPaul Woolcock <paul@woolcock.us>2018-12-12 16:42:57 -0500
committerPaul Woolcock <paul@woolcock.us>2018-12-12 16:42:57 -0500
commit32e40edd6ced3d4b8d5ede970ff88686eae35160 (patch)
tree44a9ebcc1a8185e055071f45e02d88175482cf97 /src/registration.rs
parentaae013189c1abc9cc42661ad34fc53bdbf1b3fe2 (diff)
Add `Registered::from_parts`
this allows one to store the information for a specific instance so the register call is not always necessary
Diffstat (limited to 'src/registration.rs')
-rw-r--r--src/registration.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/registration.rs b/src/registration.rs
index 817b820..5859734 100644
--- a/src/registration.rs
+++ b/src/registration.rs
@@ -183,6 +183,53 @@ impl<'a, H: HttpSend> Registration<'a, H> {
}
}
+impl Registered<HttpSender> {
+ /// Skip having to retrieve the client id and secret from the server by
+ /// creating a `Registered` struct directly
+ ///
+ /// # Example
+ ///
+ /// ```no_run
+ /// # extern crate elefren;
+ /// # fn main() -> elefren::Result<()> {
+ /// use elefren::{prelude::*, registration::Registered};
+ ///
+ /// let registration = Registered::from_parts(
+ /// "https://example.com",
+ /// "the-client-id",
+ /// "the-client-secret",
+ /// "https://example.com/redirect",
+ /// Scopes::read_all(),
+ /// );
+ /// let url = registration.authorize_url()?;
+ /// // Here you now need to open the url in the browser
+ /// // And handle a the redirect url coming back with the code.
+ /// let code = String::from("RETURNED_FROM_BROWSER");
+ /// let mastodon = registration.complete(&code)?;
+ ///
+ /// println!("{:?}", mastodon.get_home_timeline()?.initial_items);
+ /// # Ok(())
+ /// # }
+ /// ```
+ pub fn from_parts(
+ base: &str,
+ client_id: &str,
+ client_secret: &str,
+ redirect: &str,
+ scopes: Scopes,
+ ) -> Registered<HttpSender> {
+ Registered {
+ base: base.to_string(),
+ client: Client::new(),
+ client_id: client_id.to_string(),
+ client_secret: client_secret.to_string(),
+ redirect: redirect.to_string(),
+ scopes,
+ http_sender: HttpSender,
+ }
+ }
+}
+
impl<H: HttpSend> Registered<H> {
fn send(&self, req: RequestBuilder) -> Result<Response> {
Ok(self.http_sender.send(&self.client, req)?)