From fc85e48604ab525c8ea084d093648e0ce9a8c526 Mon Sep 17 00:00:00 2001 From: Jason Staten Date: Sat, 24 Aug 2019 21:09:49 -0600 Subject: [PATCH] deserialization --- Cargo.lock | 2 ++ Cargo.toml | 2 ++ src/main.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 752e24e..b43a3aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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]] diff --git a/Cargo.toml b/Cargo.toml index 7b18094..75ede71 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,5 @@ name = "classdojo" version = "0.1.0" [dependencies] reqwest = "0.9.20" +serde = "1.0.99" +serde_json = "1.0.40" diff --git a/src/main.rs b/src/main.rs index e7a11a9..7cfa0ca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, +} + +#[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, +} + +fn authenticate() {} + +fn main() -> Result<(), Box> { + 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(()) }