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 144 145
//! [![ci-badge][]][ci] [![license-badge][]][license] [![docs-badge][]][docs] //! //! # urbandictionary.rs //! //! Unofficial Rust crate for the Urbandictionary API. //! //! [Documentation][docs] //! //! ### Installation //! //! Add the following dependency to your Cargo.toml: //! //! ```toml //! urbandictionary = "0.3" //! ``` //! //! And include it in your project: //! //! ```rust,no_run //! extern crate urbandictionary; //! ``` //! //! ### Examples //! //! Using `hyper` with the `hyper-tls` HTTPS connector, retrieve a list of //! definitions for a word and print the example of the second definition if it //! exists: //! //! ```rust,no_run //! # #[cfg(feature = "hyper-support")] //! extern crate futures; //! # #[cfg(feature = "hyper-support")] //! extern crate hyper; //! # #[cfg(feature = "hyper-support")] //! extern crate hyper_tls; //! # #[cfg(feature = "hyper-support")] //! extern crate tokio_core; //! extern crate urbandictionary; //! //! # use std::error::Error; //! # //! # #[cfg(feature = "hyper-support")] //! # fn try_main() -> Result<(), Box<Error>> { //! # //! use futures::Future; //! use hyper::client::{Client, HttpConnector}; //! use hyper_tls::HttpsConnector; //! use tokio_core::reactor::Core; //! use urbandictionary::HyperUrbanDictionaryRequester; //! //! let mut core = Core::new()?; //! let client = Client::configure() //! .connector(HttpsConnector::new(4, &core.handle())?) //! .build(&core.handle()); //! //! let done = client.definitions("cat").and_then(|response| { //! if let Some(definition) = response.definitions.get(1) { //! println!("Examples: {}", definition.example); //! } //! //! Ok(()) //! }).map_err(|_| ()); //! //! core.run(done).expect("Error running core"); //! # Ok(()) //! # } //! # //! # fn main() { //! # #[cfg(feature = "hyper-support")] //! # try_main().unwrap(); //! # } //! ``` //! //! Using reqwest, print the definition of the word `"cat"`: //! //! ```rust,no_run //! # #[cfg(feature = "reqwest-support")] //! # //! extern crate reqwest; //! extern crate urbandictionary; //! //! # use std::error::Error; //! # //! # #[cfg(feature = "reqwest-support")] //! # fn try_main() -> Result<(), Box<Error>> { //! # //! //! use reqwest::Client; //! use urbandictionary::ReqwestUrbanDictionaryRequester; //! //! let client = Client::new(); //! let response = client.define("cat")?; //! //! if let Some(definition) = response { //! println!("The definition of cat is: {}", definition.definition); //! } else { //! println!("No definition found"); //! } //! # Ok(()) //! # } //! # //! # fn main() { //! # #[cfg(feature = "reqwest-support")] //! # try_main().unwrap(); //! # } //! ``` //! //! ### License //! //! License info in [LICENSE.md]. Long story short, ISC. //! //! [ci]: https://travis-ci.org/zeyla/urbandictionary.rs //! [ci-badge]: https://travis-ci.org/zeyla/urbandictionary.rs.svg?branch=master //! [docs]: https://docs.rs/crate/urbandictionary //! [docs-badge]: https://img.shields.io/badge/docs-online-2020ff.svg //! [LICENSE.md]: https://github.com/zeyla/urbandictionary.rs/blob/master/LICENSE.md //! [license]: https://opensource.org/licenses/ISC //! [license-badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=flat-square #![deny(missing_docs)] #[macro_use] extern crate serde_derive; extern crate serde; extern crate serde_json; #[cfg(feature = "futures")] extern crate futures; #[cfg(feature = "hyper")] extern crate hyper; #[cfg(feature = "hyper-tls")] extern crate hyper_tls; #[cfg(feature = "reqwest")] extern crate reqwest; pub mod bridge; pub mod model; mod error; pub use error::{Error, Result}; #[cfg(feature = "hyper-support")] pub use bridge::hyper::UrbanDictionaryRequester as HyperUrbanDictionaryRequester; #[cfg(feature = "reqwest-support")] pub use bridge::reqwest::UrbanDictionaryRequester as ReqwestUrbanDictionaryRequester;