Add support for pagination

This commit is contained in:
Adrian Malacoda 2017-12-04 00:10:48 -06:00
parent d3d199b42a
commit 0ba2fb3b2c
2 changed files with 12 additions and 3 deletions

View File

@ -17,8 +17,8 @@ impl Scryfall {
Scryfall {}
}
pub fn search(&self, query: &str) -> Result<CardList, Error> {
let mut response = reqwest::get(&format!("https://api.scryfall.com/cards/search?q={}", query))?;
pub fn search(&self, query: &str, page: i32) -> Result<CardList, Error> {
let mut response = reqwest::get(&format!("https://api.scryfall.com/cards/search?q={}&page={}", query, page))?;
let mut content = String::new();
response.read_to_string(&mut content);

View File

@ -5,5 +5,14 @@ use std::env;
fn main() {
let query = env::args().nth(1).expect("please supply an query");
let sf = Scryfall::new();
println!("{:?}", sf.search(&query).expect("Search failed"));
let mut page = 1;
loop {
let result = sf.search(&query, page).expect("Search failed");
println!("Page {}: {:?}", page, result);
if !result.has_more {
break;
}
}
}