[−][src]Struct mediawiki::api::Api
Api
is the main class to interact with a MediaWiki API
Implementations
impl Api
[src]
pub async fn new(api_url: &str) -> Result<Api, Box<dyn Error>>
[src]
Returns a new Api
element, and loads the MediaWiki site info from the api_url
site.
This is done both to get basic information about the site, and to test the API.
Examples
let api = mediawiki::api::Api::new("https://en.wikipedia.org/w/api.php").await.unwrap();
pub async fn new_from_builder(
api_url: &str,
builder: ClientBuilder
) -> Result<Api, Box<dyn Error>>
[src]
api_url: &str,
builder: ClientBuilder
) -> Result<Api, Box<dyn Error>>
Returns a new Api
element, and loads the MediaWiki site info from the api_url
site.
This is done both to get basic information about the site, and to test the API.
Uses a bespoke reqwest::ClientBuilder.
pub fn api_url(&self) -> &str
[src]
Returns the API url
pub fn set_oauth(&mut self, oauth: Option<OAuthParams>)
[src]
Sets the OAuth parameters
pub fn set_oauth2(&mut self, oauth2: &str)
[src]
Set an OAuth 2 access token
pub fn oauth(&self) -> &Option<OAuthParams>
[src]
Returns a reference to the current OAuth parameters
pub fn client(&self) -> &Client
[src]
Returns a reference to the reqwest client
pub fn client_mut(&mut self) -> &mut Client
[src]
Returns a mutable reference to the reqwest client
pub fn user(&self) -> &User
[src]
Returns a reference to the current user object
pub fn user_mut(&mut self) -> &mut User
[src]
Returns a mutable reference to the current user object
pub async fn load_current_user_info(&mut self) -> Result<(), Box<dyn Error>>
[src]
Loads the current user info; returns Ok(()) is successful
pub fn max_retry_attempts(&self) -> u64
[src]
Returns the maximum number of retry attempts
pub fn set_max_retry_attempts(&mut self, max_retry_attempts: u64)
[src]
Sets the maximum number of retry attempts
pub fn get_site_info(&self) -> &Value
[src]
Returns a reference to the serde_json Value containing the site info
pub fn get_site_info_value<'a>(&'a self, k1: &str, k2: &str) -> &'a Value
[src]
Returns a serde_json Value in site info, within the ["query"]
object.
pub fn get_site_info_string<'a>(
&'a self,
k1: &str,
k2: &str
) -> Result<&'a str, String>
[src]
&'a self,
k1: &str,
k2: &str
) -> Result<&'a str, String>
Returns a String from the site info, matching ["query"][k1][k2]
pub fn get_namespace_info(&self, namespace_id: NamespaceID) -> &Value
[src]
Returns the raw data for the namespace, matching ["query"]["namespaces"][namespace_id]
pub fn get_canonical_namespace_name(
&self,
namespace_id: NamespaceID
) -> Option<&str>
[src]
&self,
namespace_id: NamespaceID
) -> Option<&str>
Returns the canonical namespace name for a namespace ID, if defined
pub fn get_local_namespace_name(
&self,
namespace_id: NamespaceID
) -> Option<&str>
[src]
&self,
namespace_id: NamespaceID
) -> Option<&str>
Returns the local namespace name for a namespace ID, if defined
pub fn params_into(&self, params: &[(&str, &str)]) -> HashMap<String, String>
[src]
Turns a Vec of str tuples into a Hashmap of String, to be used in API calls
pub fn no_params(&self) -> HashMap<String, String>
[src]
Returns an empty parameter HashMap
pub async fn get_token(
&mut self,
token_type: &str
) -> Result<String, Box<dyn Error>>
[src]
&mut self,
token_type: &str
) -> Result<String, Box<dyn Error>>
Returns a token of a token_type
, such as login
or csrf
(for editing)
pub async fn get_edit_token(&mut self) -> Result<String, Box<dyn Error>>
[src]
Calls get_token()
to return an edit token
pub async fn get_query_api_json_all(
&self,
params: &HashMap<String, String>
) -> Result<Value, Box<dyn Error>>
[src]
&self,
params: &HashMap<String, String>
) -> Result<Value, Box<dyn Error>>
Same as get_query_api_json
but automatically loads all results via the continue
parameter
pub async fn get_query_api_json_limit(
&self,
params: &HashMap<String, String>,
max: Option<usize>
) -> Result<Value, Box<dyn Error>>
[src]
&self,
params: &HashMap<String, String>,
max: Option<usize>
) -> Result<Value, Box<dyn Error>>
Same as get_query_api_json
but automatically loads more results via the continue
parameter
pub async fn get_query_api_json_limit_iter<'a>(
&'a self,
params: &HashMap<String, String>,
max: Option<usize>
) -> impl Stream<Item = Result<Value, Box<dyn Error>>> + 'a
[src]
&'a self,
params: &HashMap<String, String>,
max: Option<usize>
) -> impl Stream<Item = Result<Value, Box<dyn Error>>> + 'a
Same as get_query_api_json
but automatically loads more results via the continue
parameter.
Returns a stream; each item is a "page" of results.
pub async fn query_api_json(
&self,
params: &HashMap<String, String>,
method: &str
) -> Result<Value, Box<dyn Error>>
[src]
&self,
params: &HashMap<String, String>,
method: &str
) -> Result<Value, Box<dyn Error>>
Runs a query against the MediaWiki API, using method
GET or POST.
Parameters are a hashmap; format=json
is enforced.
pub fn edit_delay(&self) -> &Option<u64>
[src]
Returns the delay time after edits, in milliseconds, if set
pub fn set_edit_delay(&mut self, edit_delay_ms: Option<u64>)
[src]
Sets the delay time after edits in milliseconds (or None
).
This is independent of, and additional to, MAXLAG
pub fn maxlag(&self) -> &Option<u64>
[src]
Returns the maxlag, in seconds, if set
pub fn set_maxlag(&mut self, maxlag_seconds: Option<u64>)
[src]
Sets the maxlag in seconds (or None
)
pub async fn get_query_api_json(
&self,
params: &HashMap<String, String>
) -> Result<Value, Box<dyn Error>>
[src]
&self,
params: &HashMap<String, String>
) -> Result<Value, Box<dyn Error>>
GET wrapper for query_api_json
pub async fn post_query_api_json(
&self,
params: &HashMap<String, String>
) -> Result<Value, Box<dyn Error>>
[src]
&self,
params: &HashMap<String, String>
) -> Result<Value, Box<dyn Error>>
POST wrapper for query_api_json
pub async fn post_query_api_json_mut(
&mut self,
params: &HashMap<String, String>
) -> Result<Value, Box<dyn Error>>
[src]
&mut self,
params: &HashMap<String, String>
) -> Result<Value, Box<dyn Error>>
POST wrapper for query_api_json
.
Requires &mut self
, for sassion cookie storage
pub async fn query_api_raw(
&self,
params: &HashMap<String, String>,
method: &str
) -> Result<String, Box<dyn Error>>
[src]
&self,
params: &HashMap<String, String>,
method: &str
) -> Result<String, Box<dyn Error>>
Runs a query against the MediaWiki API, and returns a text.
Uses query_raw
pub fn get_api_request_builder(
&self,
params: &HashMap<String, String>,
method: &str
) -> Result<RequestBuilder, Box<dyn Error>>
[src]
&self,
params: &HashMap<String, String>,
method: &str
) -> Result<RequestBuilder, Box<dyn Error>>
Generates a RequestBuilder
for the API URL
pub fn user_agent(&self) -> &str
[src]
Returns the user agent name
pub fn set_user_agent<S: Into<String>>(&mut self, agent: S)
[src]
Sets the user agent name
pub fn user_agent_full(&self) -> String
[src]
Returns the user agent string, as it is passed to the API through a HTTP header
pub async fn query_raw(
&self,
api_url: &str,
params: &HashMap<String, String>,
method: &str
) -> Result<String, Box<dyn Error>>
[src]
&self,
api_url: &str,
params: &HashMap<String, String>,
method: &str
) -> Result<String, Box<dyn Error>>
Runs a query against a generic URL, and returns a text.
Does not store cookies, but also does not require &self
to be mutable.
Used for simple queries
pub async fn login<S: Into<String>>(
&mut self,
lgname: S,
lgpassword: S
) -> Result<(), Box<dyn Error>>
[src]
&mut self,
lgname: S,
lgpassword: S
) -> Result<(), Box<dyn Error>>
Performs a login against the MediaWiki API.
If successful, user information is stored in User
, and in the cookie jar
pub fn result_array_to_titles(data: &Value) -> Vec<Title>
[src]
From an API result that has a list of entries with "title" and "ns" (e.g. search), returns a vector of Title
objects.
pub async fn sparql_query(&self, query: &str) -> Result<Value, Box<dyn Error>>
[src]
Performs a SPARQL query against a wikibase installation. Tries to get the SPARQL endpoint URL from the site info
pub async fn sparql_query_endpoint(
&self,
query: &str,
query_api_url: &str
) -> Result<Value, Box<dyn Error>>
[src]
&self,
query: &str,
query_api_url: &str
) -> Result<Value, Box<dyn Error>>
Performs a SPARQL query against a wikibase installation. Uses the given sparql endpoint
pub fn extract_entity_from_uri(
&self,
uri: &str
) -> Result<String, Box<dyn Error>>
[src]
&self,
uri: &str
) -> Result<String, Box<dyn Error>>
Given a uri
(usually, an URL) that points to a Wikibase entity on this MediaWiki installation, returns the item ID
pub fn entities_from_sparql_result(
&self,
sparql_result: &Value,
variable_name: &str
) -> Vec<String>
[src]
&self,
sparql_result: &Value,
variable_name: &str
) -> Vec<String>
Returns a vector of entity IDs (as String) from a SPARQL result, given a variable name
pub async fn load_user_info(
&self,
user: &mut User
) -> Result<(), Box<dyn Error>>
[src]
&self,
user: &mut User
) -> Result<(), Box<dyn Error>>
Loads the user info from the API into the user structure
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Api
[src]
impl Send for Api
[src]
impl Sync for Api
[src]
impl Unpin for Api
[src]
impl !UnwindSafe for Api
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,