Browse code

Save registration

Julio Biason authored on 10/05/2019 08:50:27
Showing 4 changed files

... ...
@@ -5,3 +5,5 @@
5 5
 
6 6
 /target
7 7
 **/*.rs.bk
8
+
9
+mastodon.toml
... ...
@@ -269,6 +269,7 @@ dependencies = [
269 269
  "serde_urlencoded 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
270 270
  "skeptic 0.13.4 (registry+https://github.com/rust-lang/crates.io-index)",
271 271
  "tap-reader 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
272
+ "toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
272 273
  "try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
273 274
  "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
274 275
 ]
... ...
@@ -1356,6 +1357,14 @@ dependencies = [
1356 1357
  "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
1357 1358
 ]
1358 1359
 
1360
+[[package]]
1361
+name = "toml"
1362
+version = "0.5.0"
1363
+source = "registry+https://github.com/rust-lang/crates.io-index"
1364
+dependencies = [
1365
+ "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)",
1366
+]
1367
+
1359 1368
 [[package]]
1360 1369
 name = "try-lock"
1361 1370
 version = "0.2.2"
... ...
@@ -1662,6 +1671,7 @@ dependencies = [
1662 1671
 "checksum tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72558af20be886ea124595ea0f806dd5703b8958e4705429dd58b3d8231f72f2"
1663 1672
 "checksum tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2910970404ba6fa78c5539126a9ae2045d62e3713041e447f695f41405a120c6"
1664 1673
 "checksum tokio-trace-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "350c9edade9830dc185ae48ba45667a445ab59f6167ef6d0254ec9d2430d9dd3"
1674
+"checksum toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "87c5890a989fa47ecdc7bcb4c63a77a82c18f306714104b1decfd722db17b39e"
1665 1675
 "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
1666 1676
 "checksum try_from 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "283d3b89e1368717881a9d51dad843cc435380d8109c9e47d38780a324698d8b"
1667 1677
 "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
... ...
@@ -5,4 +5,4 @@ authors = ["Julio Biason <julio.biason@pm.me>"]
5 5
 edition = "2018"
6 6
 
7 7
 [dependencies]
8
-elefren = "0.19"
8
+elefren = { version = "0.19", features = ["toml"] }
... ...
@@ -1,12 +1,19 @@
1 1
 use elefren::prelude::*;
2 2
 use elefren::helpers::cli;
3
+use elefren::helpers::toml;
3 4
 
4 5
 fn main() {
5
-    let registration = Registration::new("https://functional.cafe")
6
-        .client_name("downfav")
7
-        .build()
8
-        .unwrap();
9
-    let client = cli::authenticate(registration).unwrap();
6
+    let client = if let Ok(data) = toml::from_file("mastodon.toml") {
7
+        Mastodon::from(data)
8
+    } else {
9
+        let registration = Registration::new("https://functional.cafe")
10
+            .client_name("downfav")
11
+            .build()
12
+            .unwrap();
13
+        let mastodon = cli::authenticate(registration).unwrap();
14
+        toml::to_file(&*mastodon, "mastodon.toml").unwrap();
15
+        mastodon
16
+    };
10 17
 
11 18
     client
12 19
         .favourites().unwrap()
... ...
@@ -14,4 +21,12 @@ fn main() {
14 21
         .take(2)
15 22
         .for_each(move |record| println!("{:#?}", record))
16 23
         ;
24
+
25
+    // status
26
+    // status.account.acct (username)
27
+    // status.id (id)
28
+    // status.content
29
+    // status.media_attachments
30
+    //  -> attachment.remote_url / attachment.url
31
+    //     attachment.
17 32
 }