Added checking for the correct type
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use serde::Deserialize;
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{Read, Seek, SeekFrom, Write};
|
use std::io::{Read, Seek, SeekFrom, Write};
|
||||||
@@ -30,7 +30,7 @@ struct ScryfallBulk {
|
|||||||
pub data: Vec<ScryfallBulkData>,
|
pub data: Vec<ScryfallBulkData>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, PartialEq, Debug)]
|
#[derive(Deserialize, Serialize, PartialEq, Debug)]
|
||||||
pub enum ScryfallBulkType {
|
pub enum ScryfallBulkType {
|
||||||
#[serde(rename = "oracle_cards")]
|
#[serde(rename = "oracle_cards")]
|
||||||
OracleCards,
|
OracleCards,
|
||||||
@@ -47,7 +47,7 @@ pub enum ScryfallBulkType {
|
|||||||
const SCRYFALL_BULK_API: &str = "https://api.scryfall.com/bulk-data";
|
const SCRYFALL_BULK_API: &str = "https://api.scryfall.com/bulk-data";
|
||||||
|
|
||||||
pub fn download_latest(
|
pub fn download_latest(
|
||||||
_stype: ScryfallBulkType,
|
stype: ScryfallBulkType,
|
||||||
mut dest_file: &NamedTempFile,
|
mut dest_file: &NamedTempFile,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let bulk_body: ScryfallBulk = ureq::get(SCRYFALL_BULK_API)
|
let bulk_body: ScryfallBulk = ureq::get(SCRYFALL_BULK_API)
|
||||||
@@ -59,13 +59,11 @@ pub fn download_latest(
|
|||||||
|
|
||||||
let mut download_uri = String::new();
|
let mut download_uri = String::new();
|
||||||
for scryfall_bulk in bulk_body.data {
|
for scryfall_bulk in bulk_body.data {
|
||||||
// TODO: Actually implement getting different types
|
if serde_json::to_string(&stype).unwrap() == scryfall_bulk.stype {
|
||||||
if scryfall_bulk.stype == "oracle_cards" {
|
|
||||||
download_uri = scryfall_bulk.download_uri;
|
download_uri = scryfall_bulk.download_uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert!(!download_uri.is_empty());
|
assert!(!download_uri.is_empty());
|
||||||
|
|
||||||
let cards_response = ureq::get(download_uri)
|
let cards_response = ureq::get(download_uri)
|
||||||
.header("User-Agent", "Arthur's Card Finger Testing v0.1")
|
.header("User-Agent", "Arthur's Card Finger Testing v0.1")
|
||||||
.header("Accept", "application/json")
|
.header("Accept", "application/json")
|
||||||
|
|||||||
Reference in New Issue
Block a user