pub trait CFAPIRequestable {
// Required methods
fn query_params(&self) -> Vec<(&'static str, String)>;
fn method_name(&self) -> &'static str;
fn get(&self, api_key: &str, api_secret: &str) -> Result<CFResult, Error>;
fn get_raw(&self, api_key: &str, api_secret: &str) -> Result<String, Error>;
}
Expand description
Trait implemented by any type which can be sent as a request to the Codeforces API.
Exposes functions which allow a type to be converted into a URL and fetched from the server.
Required Methods§
Sourcefn query_params(&self) -> Vec<(&'static str, String)>
fn query_params(&self) -> Vec<(&'static str, String)>
Method which returns a Vec of pairs (key, val) which will be mapped onto URL query parameters. Used internally and not much use for most people.
Sourcefn method_name(&self) -> &'static str
fn method_name(&self) -> &'static str
Method which returns a str slice of the method name (eg. “user.info”). Used internally and not much use for most people.
Sourcefn get(&self, api_key: &str, api_secret: &str) -> Result<CFResult, Error>
fn get(&self, api_key: &str, api_secret: &str) -> Result<CFResult, Error>
Fetch response from Codeforces servers.
§Examples
let x = CFUserCommand::Status {
handle: "thud".to_string(),
from: Some(1),
count: Some(3),
};
match x.get(api_key, api_secret) {
Ok(CFResult::CFSubmissionVec(v)) => {
// your code here
},
_ => {
panic!("API request failed");
}
}
Sourcefn get_raw(&self, api_key: &str, api_secret: &str) -> Result<String, Error>
fn get_raw(&self, api_key: &str, api_secret: &str) -> Result<String, Error>
Fetch raw JSON response from Codeforces servers.
§Examples
let x = CFUserCommand::Status {
handle: "thud".to_string(),
from: Some(1),
count: Some(3),
};
match x.get_raw(api_key, api_secret) {
Ok(s) => {
assert!(s.starts_with("{\"status\":\"OK\""));
// your code here
},
_ => {
panic!("raw API request failed");
}
}