RequestBuilder

Struct RequestBuilder 

Source
pub struct RequestBuilder<'a> { /* private fields */ }
Expand description

Builder struct to assemble and sign an API request.

For more information about how to use this type and about building requests manually, see the module docs.

Implementations§

Source§

impl<'a> RequestBuilder<'a>

Source

pub fn new(method: Method, base_uri: &'a str) -> Self

Creates a new RequestBuilder with the given HTTP method and base URL.

Source

pub fn with_query_params(self, params: &ParamList) -> Self

Adds the given parameters as a query string. Parameters given this way will be included in the OAuth signature.

Note that functions that take a ParamList accumulate parameters as part of the OAuth signature. If you call both with_query_params and with_body_params, both sets of parameters will be used as part of the OAuth signature.

On the other hand, the query string is not cumulative. If you call with_query_params multiple times, only the last set of parameters will actually be considered part of the query string.

Source

pub fn with_body_params(self, params: &ParamList) -> Self

Adds the given params as a request body, formatted as application/x-www-form-urlencoded. Parameters given this way will be included in the OAuth signature.

Note that functions that take a ParamList accumulate parameters as part of the OAuth signature. If you call both with_query_params and with_body_params, both sets of parameters will be used as part of the OAuth signature.

Note that the functions that specify a request body each overwrite the body. For example, if you specify with_body_params and also with_body_json, only the one you call last will be sent with the request.

Source

pub fn with_body_json(self, body: impl Serialize) -> Self

Includes the given data as the request body, formatted as JSON. Data given this way will not be included in the OAuth signature.

Note that the functions that specify a request body each overwrite the body. For example, if you specify with_body_params and also with_body_json, only the one you call last will be sent with the request.

Source

pub fn with_body(self, body: impl Into<Body>, content: &'static str) -> Self

Includes the given data as the request body, with the given content type. Data given this way will not be included in the OAuth signature.

Note that the functions that specify a request body each overwrite the body. For example, if you specify with_body_params and also with_body, only the one you call last will be sent with the request.

Source

pub fn oauth_callback(self, callback: impl Into<String>) -> Self

Includes the given OAuth Callback into the OAuth parameters.

Note that oauth_callback and oauth_verifier are mutually exclusive. If you specify both on the same request, only the last one will be sent.

Source

pub fn oauth_verifier(self, verifier: impl Into<String>) -> Self

Includes the given OAuth Verifier into the OAuth parameters.

Note that oauth_callback and oauth_verifier are mutually exclusive. If you specify both on the same request, only the last one will be sent.

Source

pub fn request_keys( self, consumer_key: &KeyPair, token: Option<&KeyPair>, ) -> Request<Body>

Formats this RequestBuilder into a complete Request, signing it with the given keys.

While the token parameter is an Option here, it should only be None when generating a request token; all other calls must have two sets of keys (or be authenticated in a different way, i.e. a Bearer token).

Source

pub fn request_token(self, token: &Token) -> Request<Body>

Formats this RequestBuilder into a complete Request, signing it with the given token.

If the given Token is an Access token, the request will be signed using OAuth 1.0a, using the given URI, HTTP method, and parameters to create a signature.

If the given Token is a Bearer token, the request will be authenticated using OAuth 2.0, specifying the given Bearer token as authorization.

Source

pub fn request_consumer_bearer(self, consumer_key: &KeyPair) -> Request<Body>

Formats this RequestBuilder into a complete Request, with an Authorization header formatted using HTTP Basic authentication using the given consumer key, as expected by the POST oauth2/token endpoint.

This Authorization should only be used when requesting a Bearer token; other requests need to be signed with multiple keys (as with request_keys or giving an Access token to request_token) or with a proper Bearer token given to request_token.

This authorization can also be used to access Enterprise API endpoints that require Basic authentication, using a KeyPair with the email address and password that would ordinarily be used to access the Enterprise API Console.

Auto Trait Implementations§

§

impl<'a> !Freeze for RequestBuilder<'a>

§

impl<'a> !RefUnwindSafe for RequestBuilder<'a>

§

impl<'a> Send for RequestBuilder<'a>

§

impl<'a> Sync for RequestBuilder<'a>

§

impl<'a> Unpin for RequestBuilder<'a>

§

impl<'a> !UnwindSafe for RequestBuilder<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more