Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #133 from dwijnand/rate_limit
Introduce GET /rate_limit & test the example in CI
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
extern crate env_logger; | ||
extern crate futures; | ||
extern crate hubcaps; | ||
extern crate tokio_core; | ||
|
||
use tokio_core::reactor::Core; | ||
|
||
use hubcaps::{Github, Result}; | ||
|
||
fn main() -> Result<()> { | ||
drop(env_logger::init()); | ||
let mut core = Core::new()?; | ||
let github = Github::new( | ||
concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")), | ||
None, | ||
&core.handle(), | ||
); | ||
let status = core.run(github.rate_limit().get())?; | ||
println!("{:#?}", status); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//! Rate Limit interface | ||
|
||
use hyper::client::Connect; | ||
|
||
use {Future, Github}; | ||
|
||
pub struct RateLimit<C: Clone + Connect> { | ||
github: Github<C>, | ||
} | ||
|
||
impl<C: Clone + Connect> RateLimit<C> { | ||
#[doc(hidden)] | ||
pub fn new(github: Github<C>) -> Self { | ||
Self { github } | ||
} | ||
|
||
/// https://developer.github.com/v3/rate_limit/#get-your-current-rate-limit-status | ||
pub fn get(&self) -> Future<RateLimitStatus> { | ||
self.github.get("/rate_limit") | ||
} | ||
} | ||
|
||
// representations | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct RateLimitStatus { | ||
pub resources: RateLimitResourcesStatus | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct RateLimitResourcesStatus { | ||
pub core: RateLimitResourceStatus, | ||
pub search: RateLimitResourceStatus, | ||
pub graphql: RateLimitResourceStatus, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct RateLimitResourceStatus { | ||
pub limit: u32, | ||
pub remaining: u32, | ||
pub reset: u32 // ideally something like std::time::Duration | ||
} |