Trait weeb_api::bridge::reqwest::WeebApiRequester [] [src]

pub trait WeebApiRequester {
    fn get_images(&self) -> Result<ApiResponse>;
fn get_image_info<S>(&self, auth: S, id: &str) -> Result<Image>
    where
        S: Into<String>
;
fn get_image_random<S>(&self, auth: S, params: ImageParams) -> Result<Image>
    where
        S: Into<String>
;
fn get_image_tags<S>(&self, auth: S, hidden: bool) -> Result<Vec<String>>
    where
        S: Into<String>
;
fn get_image_types<S>(&self, auth: S, hidden: bool) -> Result<Vec<String>>
    where
        S: Into<String>
;
fn upload_image<S>(
        &self,
        auth: S,
        params: UploadParams
    ) -> Result<ImageUploadResponse>
    where
        S: Into<String>
; }

Trait which defines the methods necessary to interact with the service.

Examples

To bring in the implemenation for the reqwest Client, simply use the trait:

use weeb_api::WeebApiReqwestRequester;

At this point, the methods will be on your Reqwest Client.

Required Methods

Retrieves information about the API.

Examples

Get basic info about the API:

extern crate reqwest;
extern crate weeb_api;
use reqwest::Client;
use std::env;
use weeb_api::WeebApiReqwestRequester;

let token = env::var("WEEB_TOKEN")?;

let client = Client::new();

let response = client.get_images()?;

println!("Info: {:?}", response);

Errors

Returns Error::Json if there was an error parsing the response body.

Returns Error::ReqwestBad if the request was otherwise bad for some reason, containing the response.

Returns Error::ReqwestInvalid if the response was a non-OK (status code 200) response, containing the response.

Get info on an image.

Examples

Get info about the image with the id "ryh6x04Rb":

extern crate reqwest;
extern crate weeb_api;
use reqwest::Client;
use std::env;
use weeb_api::WeebApiReqwestRequester;

let token = env::var("WEEB_TOKEN")?;

let client = Client::new();

let id = "ryh6x04Rb";
let response = client.get_image_info(token, id)?;

println!("Info: {:?}", response);

Errors

Returns Error::Json if there was an error parsing the response body.

Returns Error::ReqwestBad if the request was otherwise bad for some reason, containing the response.

Returns Error::ReqwestInvalid if the response was a non-OK (status code 200) response, containing the response.

Returns Error::ReqwestUnauthorized if the authorization token was invalid.

Retrieves a random image given the matching parameters.

Note: You must specify at least one of [kind] or [tags] in the image params.

Examples

Retrieve a random image with the "sleepy" kind:

extern crate reqwest;
extern crate weeb_api;
use reqwest::Client;
use std::env;
use weeb_api::{ImageParams, WeebApiReqwestRequester};

let token = env::var("WEEB_TOKEN")?;

let client = Client::new();

let params = ImageParams::kind("sleepy");
let response = client.get_image_random(token, params)?;

println!("URL: {}", response.url);

Retrieve a random image with the "girl" tag:

extern crate reqwest;
extern crate weeb_api;
use reqwest::Client;
use std::env;
use weeb_api::{ImageParams, WeebApiReqwestRequester};

let token = env::var("WEEB_TOKEN")?;

let client = Client::new();

let params = ImageParams::tags(vec!["girl"]);
let response = client.get_image_random(token, params)?;

println!("URL: {}", response.url);

Errors

Returns Error::Json if there was an error parsing the response body.

Returns Error::NoParamsSpecified if the input did not specify one of the required image parameters, containing the image parameters.

Returns Error::ReqwestBad if the request was otherwise bad for some reason, containing the response.

Returns Error::ReqwestInvalid if the response was a non-OK (status code 200) response, containing the response.

Returns Error::ReqwestParse if there was an error parsing the image parameters into a valid URL.

Returns Error::ReqwestUnauthorized if the authorization token was invalid.

Retrieves all the current image tags.

Examples

Retrieve all image tags including hidden ones:

extern crate reqwest;
extern crate weeb_api;
use reqwest::Client;
use std::env;
use weeb_api::WeebApiReqwestRequester;

let token = env::var("WEEB_TOKEN")?;

let client = Client::new();

let response = client.get_image_tags(token, true)?;

println!("Tags: {:?}", response);

Errors

Returns Error::Json if there was an error parsing the response body.

Returns Error::ReqwestBad if the request was otherwise bad for some reason, containing the response.

Returns Error::ReqwestInvalid if the response was a non-OK (status code 200) response, containing the response.

Returns Error::ReqwestUnauthorized if the authorization token was invalid.

Retrieves all the current image types.

Examples

Retrieve all image tags including hidden ones:

extern crate reqwest;
extern crate weeb_api;
use reqwest::Client;
use std::env;
use weeb_api::WeebApiReqwestRequester;

let token = env::var("WEEB_TOKEN")?;

let client = Client::new();

let response = client.get_image_types(token, true)?;

println!("Types: {:?}", response);

Errors

Returns Error::Json if there was an error parsing the response body.

Returns Error::ReqwestBad if the request was otherwise bad for some reason, containing the response.

Returns Error::ReqwestInvalid if the response was a non-OK (status code 200) response, containing the response.

Returns Error::ReqwestUnauthorized if the authorization token was invalid.

Uploads an image to the Api.

Examples

Upload an image after reading it from the disk:

extern crate reqwest;
extern crate weeb_api;
use reqwest::Client;
use std::env;
use std::fs::File;
use std::io::Read;
use weeb_api::{UploadParams, WeebApiReqwestRequester};

let token = env::var("WEEB_TOKEN")?;

let client = Client::new();

let mut buffer = vec![];
let mut file = File::open("./file.png")?;
file.read_to_end(&mut buffer)?;
let params = UploadParams::simple("hug".to_string(), buffer);

let response = client.upload_image(token, params)?;

println!("Status: {}", response.message);

Errors

Returns Error::Json if there was an error parsing the response body.

Returns [Error::NoUploadSpecified] if the input did not specify one of the required image upload parameters.

Returns Error::ReqwestBad if the request was otherwise bad for some reason, containing the response.

Returns Error::ReqwestInvalid if the response was a non-OK (status code 200) response, containing the response.

Returns Error::ReqwestParse if there was an error parsing the image parameters into a valid URL.

Returns Error::ReqwestUnauthorized if the authorization token was invalid.

Implementations on Foreign Types

impl WeebApiRequester for ReqwestClient
[src]

[src]

[src]

[src]

[src]

[src]

[src]

Implementors