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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! # osu.rs
//!
//! Unofficial Rust crate for the osu! API.
//!
//! [Documentation][docs]
//!
//! ### Installation
//!
//! Add the following dependency to your Cargo.toml:
//!
//! ```toml
//! osu = "0.2"
//! ```
//!
//! And include it in your project:
//!
//! ```rust
//! extern crate osu;
//! ```
//!
//! ### Examples
//!
//! Using `hyper` with the `hyper-tls` HTTPS connector, retrieve the start time of a
//! match by ID:
//!
//! ```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;
//! extern crate osu;
//! # #[cfg(feature = "hyper-support")]
//! extern crate tokio_core;
//!
//! # #[cfg(feature = "hyper-support")]
//! use futures::Future;
//! # #[cfg(feature = "hyper-support")]
//! use hyper::client::{Client, HttpConnector};
//! # #[cfg(feature = "hyper-support")]
//! use hyper_tls::HttpsConnector;
//! use osu::bridge::hyper::OsuHyperRequester;
//! use std::error::Error;
//! use std::env;
//! # #[cfg(feature = "hyper-support")]
//! use tokio_core::reactor::Core;
//!
//! # #[cfg(feature = "hyper-support")]
//! fn try_main() -> Result<(), Box<Error>> {
//!     let mut core = Core::new()?;
//!     let client = Client::configure()
//!         .connector(HttpsConnector::new(4, &core.handle())?)
//!         .build(&core.handle());
//!     let key = env::var("OSU_KEY")?;
//!
//!     let done = client.get_match(&key, 71641).map(|found| {
//!         println!("Match start time: {}", found.start_time);
//!
//!         ()
//!     }).map_err(|_| ());
//!
//!     core.run(done).expect("Error running core");
//!
//!     Ok(())
//! }
//!
//! fn main() {
//!     # #[cfg(feature = "hyper-support")]
//!     try_main().unwrap();
//! }
//! ```
//!
//! Using reqwest, retrieve a match's start time by ID:
//!
//! ```rust,no_run
//! extern crate osu;
//! # #[cfg(feature = "reqwest-support")]
//! extern crate reqwest;
//!
//! # #[cfg(feature = "reqwest-support")]
//! use osu::bridge::reqwest::OsuReqwestRequester;
//! # #[cfg(feature = "reqwest-support")]
//! use reqwest::Client;
//! use std::error::Error;
//!
//! # #[cfg(feature = "reqwest-support")]
//! fn try_main() -> Result<(), Box<Error>> {
//!     let key = env::var("OSU_KEY")?;
//!     let client = Client::new();
//!     let found = client.get_match(&key, 71641)?;
//!
//!     println!("Match start time: {}", found.start_time);
//!
//!     Ok(())
//! }
//!
//! fn main() {
//!     # #[cfg(feature = "reqwest-support")]
//!     try_main().unwrap();
//! }
//! ```

// #![deny(missing_docs)]

#[macro_use] extern crate bitflags;
#[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 = "reqwest")]
extern crate reqwest;

/// The base URL for all requests to osu!'s API.
///
/// Although this is not necessary for use with the library, but is exposed for
/// any extra purposes that might be needed.
pub const API_URL: &'static str = "https://osu.ppy.sh/api";

pub mod bridge;
pub mod builder;
pub mod error;

mod model;

pub use error::{Error, Result};
pub use model::*;

/// Information for retrieving a user.
///
/// User retrieval can either be done with an ID or with a username.
pub enum GetBeatmapUser {
    /// The user's ID.
    UserId(u64),
    /// The user's username.
    Username(String),
}

impl<'a> From<&'a str> for GetBeatmapUser {
    fn from(username: &'a str) -> GetBeatmapUser {
        GetBeatmapUser::Username(username.to_owned())
    }
}

impl From<String> for GetBeatmapUser {
    fn from(username: String) -> GetBeatmapUser {
        GetBeatmapUser::Username(username)
    }
}

impl From<u64> for GetBeatmapUser {
    fn from(user_id: u64) -> GetBeatmapUser {
        GetBeatmapUser::UserId(user_id)
    }
}