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>
impl<'a> RequestBuilder<'a>
Sourcepub fn new(method: Method, base_uri: &'a str) -> Self
pub fn new(method: Method, base_uri: &'a str) -> Self
Creates a new RequestBuilder with the given HTTP method and base URL.
Sourcepub fn with_query_params(self, params: &ParamList) -> Self
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.
Sourcepub fn with_body_params(self, params: &ParamList) -> Self
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.
Sourcepub fn with_body_json(self, body: impl Serialize) -> Self
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.
Sourcepub fn with_body(self, body: impl Into<Body>, content: &'static str) -> Self
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.
Sourcepub fn oauth_callback(self, callback: impl Into<String>) -> Self
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.
Sourcepub fn oauth_verifier(self, verifier: impl Into<String>) -> Self
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.
Sourcepub fn request_keys(
self,
consumer_key: &KeyPair,
token: Option<&KeyPair>,
) -> Request<Body>
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).
Sourcepub fn request_token(self, token: &Token) -> Request<Body>
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.
Sourcepub fn request_consumer_bearer(self, consumer_key: &KeyPair) -> Request<Body>
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.