Trait codeforces_api::requests::CFAPIRequestable[][src]

pub trait CFAPIRequestable {
    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>; }

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

fn query_params(&self) -> Vec<(&'static str, String)>[src]

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.

fn method_name(&self) -> &'static str[src]

Method which returns a str slice of the method name (eg. “user.info”). Used internally and not much use for most people.

fn get(&self, api_key: &str, api_secret: &str) -> Result<CFResult, Error>[src]

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");
    }
}

fn get_raw(&self, api_key: &str, api_secret: &str) -> Result<String, Error>[src]

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");
    }
}
Loading content...

Implementors

impl CFAPIRequestable for CFBlogEntryCommand[src]

impl CFAPIRequestable for CFContestCommand[src]

impl CFAPIRequestable for CFProblemsetCommand[src]

impl CFAPIRequestable for CFUserCommand[src]

impl CFAPIRequestable for CFRecentActionsCommand[src]

Loading content...