~statianzo/classdojo

fc85e48604ab525c8ea084d093648e0ce9a8c526 — Jason Staten 3 years ago e203795
deserialization
3 files changed, 56 insertions(+), 2 deletions(-)

M Cargo.lock
M Cargo.toml
M src/main.rs
M Cargo.lock => Cargo.lock +2 -0
@@ 98,6 98,8 @@ name = "classdojo"
version = "0.1.0"
dependencies = [
 "reqwest 0.9.20 (registry+https://github.com/rust-lang/crates.io-index)",
 "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
 "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]

M Cargo.toml => Cargo.toml +2 -0
@@ 5,3 5,5 @@ name = "classdojo"
version = "0.1.0"
[dependencies]
reqwest = "0.9.20"
serde = "1.0.99"
serde_json = "1.0.40"

M src/main.rs => src/main.rs +52 -2
@@ 1,3 1,53 @@
fn main() {
    println!("Hello, world!");
use reqwest::Client;
use serde::Deserialize;
use std::error::Error;

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct FeedAttachment {
    #[serde(rename = "_id")]
    id: String,
    content_type: String,
    #[serde(rename = "type")]
    attachment_type: String,
    path: String,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct FeedContents {
    body: String,
    attachments: Vec<FeedAttachment>,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
struct FeedItem {
    header_text: String,
    header_subtext: String,
    contents: FeedContents,
}

#[derive(Debug, Deserialize)]
struct Feed {
    #[serde(rename = "_items")]
    items: Vec<FeedItem>,
}

fn authenticate() {}

fn main() -> Result<(), Box<dyn Error>> {
    let client = Client::builder().cookie_store(true).build()?;
    let feed: Feed = client
        .get("http://localhost:2015/feed.json")
        .send()?
        .json()?;
    println!("{:?}", feed);
    let feed2: Feed = client
        .get("http://localhost:2015/feed.json")
        .send()?
        .json()?;
    println!("{:?}", feed2);

    Ok(())
}