[−][src]Struct mediawiki::api::Api
Api
is the main class to interact with a MediaWiki API
Methods
impl Api
[src]
pub 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.
pub 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) -> &String
[src]
Returns the API url
pub fn set_oauth(&mut self, oauth: Option<OAuthParams>)
[src]
Sets the OAuth parameters
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 fn load_user_info(&mut self) -> Result<(), Box<dyn Error>>
[src]
Loads the current user info; returns Ok(()) is successful
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(&self, k1: &str, k2: &str) -> Value
[src]
Returns a serde_json Value in site info, within the ["query"]
object.
The value is a cloned copy.
pub fn get_site_info_string(&self, k1: &str, k2: &str) -> Result<String, String>
[src]
Returns a String from the site info, matching ["query"][k1][k2]
pub fn get_canonical_namespace_name(
&self,
namespace_id: NamespaceID
) -> Option<String>
[src]
&self,
namespace_id: NamespaceID
) -> Option<String>
Returns the canonical namespace name for a namespace ID, if defined
pub fn get_local_namespace_name(
&self,
namespace_id: NamespaceID
) -> Option<String>
[src]
&self,
namespace_id: NamespaceID
) -> Option<String>
Returns the local namespace name for a namespace ID, if defined
pub fn params_into(&self, params: &Vec<(&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 fn get_token(&mut self, token_type: &str) -> Result<String, Box<dyn Error>>
[src]
Returns a token of a token_type
, such as login
or csrf
(for editing)
pub fn get_edit_token(&mut self) -> Result<String, Box<dyn Error>>
[src]
Calls get_token()
to return an edit token
pub 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 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 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 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 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 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 fn set_cookies_from_response(&mut self, resp: &Response)
[src]
Adds or replaces cookies in the cookie jar from a http Response
pub fn cookies_to_string(&self) -> String
[src]
Generates a single string to pass as COOKIE parameter in a http Request
pub 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) -> &String
[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 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 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 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 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
Trait Implementations
Auto Trait Implementations
impl Send for Api
impl Unpin for Api
impl Sync for Api
impl !UnwindSafe for Api
impl !RefUnwindSafe for Api
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for 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.
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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Erased for T
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
U: TryFrom<T>,