-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add `all`, `latest`, and `random` example.
- Loading branch information
Showing
3 changed files
with
71 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2016 Nikita Pekin and the xkcd_rs contributors | ||
// See the README.md file at the top-level directory of this distribution. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
extern crate hyper; | ||
extern crate xkcd; | ||
|
||
fn main() { | ||
let client = hyper::Client::new(); | ||
|
||
// Retrieve the latest comic ID. | ||
let latest_id = xkcd::comics::latest(&client).unwrap().num; | ||
|
||
// Retrieve all the comics. | ||
let mut all_comics = Vec::new(); | ||
for i in 1..latest_id + 1 { | ||
// Skip 404 because that's the 404 page and not a comic. | ||
if i == 404 { | ||
continue; | ||
} | ||
|
||
all_comics.push(xkcd::comics::get(&client, i).unwrap()); | ||
} | ||
} |
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,19 @@ | ||
// Copyright (c) 2016 Nikita Pekin and the xkcd_rs contributors | ||
// See the README.md file at the top-level directory of this distribution. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
extern crate hyper; | ||
extern crate xkcd; | ||
|
||
fn main() { | ||
let client = hyper::Client::new(); | ||
|
||
// Retrieve the latest comic. | ||
let latest_comic = xkcd::comics::latest(&client); | ||
println!("Latest comic: {:?}", latest_comic); | ||
} |
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,23 @@ | ||
// Copyright (c) 2016 Nikita Pekin and the xkcd_rs contributors | ||
// See the README.md file at the top-level directory of this distribution. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
extern crate hyper; | ||
extern crate xkcd; | ||
|
||
fn main() { | ||
let client = hyper::Client::new(); | ||
|
||
// Retrieve a random comic. | ||
let random_comic = xkcd::random::random(&client); | ||
println!("Random comic: {:?}\n", random_comic); | ||
|
||
// Retrieve a random comic in the range `start <= x < end`. | ||
let random_comic_in_range = xkcd::random::random_in_range(&client, (1..50)); | ||
println!("Random comic in range: {:?}", random_comic_in_range); | ||
} |