1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
//! # weeb-api.rs
//!
//! An unofficial Rust library acting as a wrapper around the Weeb.sh API, offering
//! implementations for both asynchronous hyper(v0.11) and synchronous
//! reqwest(0.8.0).
//!
//! **note:** This library requires the use of a Weeb.sh token.
//!
//! ### Compile features
//!
//! - **hyper-support**: Compiles with `hyper` support
//! - **reqwest-support**: Compiles with `reqwest` support (*default)
//!
//! ### Installation
//!
//! Add the following to your `Cargo.toml` file.
//!
//! ```toml
//! [dependencies]
//! weeb_api = "0.1"
//! ```
//!
//! To enable both `hyper` and `reqwest` support:
//!
//! ```toml
//! [dependencies.weeb_api]
//! version = "0.1"
//! features = ["hyper-support", "reqwest support"]
//! ```
//!
//! To enable `hyper` but not `reqwest` support:
//!
//! ```toml
//! [dependencies.weeb_api]
//! version = "0.1"
//! default-features = false
//! features = ["hyper-support"]
//! ```
//!
//! ### Examples
//!
//! Using reqwest, search for a random image using the token and type provided by
//! user input:
//!
//! ```rust,no_run
//! extern crate weeb_api;
//! # #[cfg(feature = "reqwest")]
//! extern crate reqwest;
//!
//! # #[cfg(feature = "request")]
//! fn main() {
//!     use weeb_api::{ImageParams, WeebApiReqwestRequester};
//!     use reqwest::Client;
//!     use std::io::{self, Write};
//!
//!     // Create the reqwest Client.
//!     let client = Client::new();
//!
//!     // Read the token from the users input.
//!     let token = ask("Input your API token:");
//!     let token_trimmed = token.trim();
//!
//!     if token_trimmed.is_empty() {
//!         println!("No token give. Shutting down.");
//!
//!         return;
//!     }
//!
//!     // Get a type to get a random image for from the users input.
//!     let input = ask("Input a type to get a random image URL for:");
//!     let input_trimmed = input.trim();
//!
//!     if input_trimmed.is_empty() {
//!         println!("No type given. Shutting down.");
//!
//!         return;
//!     }
//!
//!     let response = client.get_image_random(token_trimmed, params)
//!     let params = ImageParams::kind(input_trimmed);
//!             .expect("Error getting random image");
//!
//!     println!("Response URL: {}", response.url);
//! }
//! # #[cfg(not(feature = "reqwest"))]
//! # fn main() { }
//!
//! fn ask(question: &str) -> String {
//!     print!("{}\n>", question);
//!     let _ = io::stdout().flush();
//!
//!     let mut input = String::new();
//!     io::stdin().read_line(&mut input).expect("Error processing input");
//!
//!     input
//! }
//! ```
//!
//! For more examples, refer to the [examples] folder.
//!
//! ### License
//!
//! ISC. View the full license [here][license file].
//!
//! [examples]: https://github.com/shinonome-cafe/weeb-api.rs/blob/master/examples
//! [license file]: https://github.com/shinonome-cafe/weeb-api.rs/blob/master/LICENSE.md
#![deny(missing_docs)]

#[cfg(feature = "hyper")]
extern crate hyper;
#[cfg(feature = "hyper")]
extern crate hyper_tls;
#[cfg(feature = "reqwest")]
extern crate reqwest;
#[cfg(feature = "serde")]
extern crate serde;
#[cfg(feature = "serde_derive")]
#[macro_use]
extern crate serde_derive;
#[cfg(feature = "serde_json")]
extern crate serde_json;

pub mod bridge;
pub mod constants;
pub mod utils;

#[cfg(feature = "serde-items")]
pub mod model;

mod error;
mod image_params;
#[cfg(feature = "reqwest")]
mod upload_params;

pub use error::{Error, Result};
pub use image_params::ImageParams;
#[cfg(feature = "reqwest")]
pub use upload_params::UploadParams;

#[cfg(feature = "reqwest")]
pub use bridge::reqwest::WeebApiRequester as WeebApiReqwestRequester;
#[cfg(feature = "hyper")]
pub use bridge::hyper::WeebApiRequester as WeebApiHyperRequester;