Skip to content

Commit

Permalink
Add http::prelude.
Browse files Browse the repository at this point in the history
Move all tests to use the prelude as a form of dogfooding.

This closes #8.
  • Loading branch information
Aehmlo committed Dec 24, 2018
1 parent d15e78d commit 5e26f77
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 86 deletions.
24 changes: 12 additions & 12 deletions src/http/client/effects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl<'a, T: Select> BreathePayload<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand Down Expand Up @@ -82,7 +82,7 @@ impl<'a, T: Select> Breathe<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand All @@ -101,7 +101,7 @@ impl<'a, T: Select> Breathe<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand All @@ -120,7 +120,7 @@ impl<'a, T: Select> Breathe<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand All @@ -139,7 +139,7 @@ impl<'a, T: Select> Breathe<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand All @@ -158,7 +158,7 @@ impl<'a, T: Select> Breathe<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand All @@ -177,7 +177,7 @@ impl<'a, T: Select> Breathe<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand Down Expand Up @@ -271,7 +271,7 @@ impl<'a, T: Select> Pulse<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand All @@ -290,7 +290,7 @@ impl<'a, T: Select> Pulse<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand All @@ -309,7 +309,7 @@ impl<'a, T: Select> Pulse<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand All @@ -328,7 +328,7 @@ impl<'a, T: Select> Pulse<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand All @@ -347,7 +347,7 @@ impl<'a, T: Select> Pulse<'a, T> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand Down
43 changes: 33 additions & 10 deletions src/http/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ pub use self::effects::*;
pub use self::scenes::*;
pub use self::states::*;

/// Contains useful utilities for working with the LIFX HTTP API.
///
/// Use the prelude to maintain the convenience of glob importing without overly polluting the namespace.
///
/// ## Usage
/// ```
/// use lifxi::http::prelude::*;
/// ```
pub mod prelude {
pub use crate::http::Client;
pub use crate::http::Color;
pub use crate::http::ColorParseError;
pub use crate::http::ColorValidationError;
pub use crate::http::Combine;
pub use crate::http::Randomize;
pub use crate::http::Retry;
pub use crate::http::Selector;
pub use crate::http::SelectorParseError;
pub use crate::http::Send;
pub use crate::http::State;
pub use crate::http::StateChange;
}

/// Trait enabling conversion of non-terminal request builders to requests.
pub trait AsRequest<S: Serialize> {
/// The HTTP verb to be used.
Expand All @@ -42,7 +65,7 @@ pub type ClientResult = Result<reqwest::Response, Error>;
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let result = client
Expand All @@ -64,7 +87,7 @@ impl Client {
///
/// ## Examples
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// let secret = "foo";
/// let client = Client::new(secret);
/// let secret = "foo".to_string();
Expand Down Expand Up @@ -98,7 +121,7 @@ impl Client {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let secret = "foo";
/// let client = Client::new(secret);
Expand Down Expand Up @@ -358,7 +381,7 @@ where
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let lights = client
Expand All @@ -380,7 +403,7 @@ where
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let lights = client
Expand All @@ -401,7 +424,7 @@ where
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let lights = client
Expand All @@ -424,7 +447,7 @@ where
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let lights = client
Expand All @@ -446,7 +469,7 @@ where
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let lights = client
Expand All @@ -471,7 +494,7 @@ where
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// fn client() -> Client {
/// // TODO: Add lazy-static dependency and use it to make a shared client.
/// unimplemented!()
Expand Down Expand Up @@ -505,7 +528,7 @@ where
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let result = client
Expand Down
14 changes: 7 additions & 7 deletions src/http/client/scenes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<'a> Scenes<'a> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let scenes = client
Expand All @@ -40,7 +40,7 @@ impl<'a> Scenes<'a> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let result = client
Expand Down Expand Up @@ -77,7 +77,7 @@ pub struct ActivatePayload {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let result = client
Expand Down Expand Up @@ -110,7 +110,7 @@ impl<'a> Activate<'a> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let result = client
Expand All @@ -130,7 +130,7 @@ impl<'a> Activate<'a> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let result = client
Expand All @@ -150,7 +150,7 @@ impl<'a> Activate<'a> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let result = client
Expand All @@ -168,7 +168,7 @@ impl<'a> Activate<'a> {
///
/// ## Example
/// ```
/// use lifxi::http::*;
/// use lifxi::http::prelude::*;
/// # fn run() {
/// let client = Client::new("foo");
/// let result = client
Expand Down
Loading

0 comments on commit 5e26f77

Please sign in to comment.