Add support for pagination
This commit is contained in:
parent
d3d199b42a
commit
0ba2fb3b2c
@ -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);
|
||||
|
||||
|
11
src/main.rs
11
src/main.rs
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user