aboutsummaryrefslogtreecommitdiff
path: root/src/tw/user.rs
diff options
context:
space:
mode:
authorAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-02 01:27:08 -0700
committerAndy Wortman <ixineeringeverywhere@gmail.com>2017-10-02 01:27:18 -0700
commitea4e93f01d9e4ef17effae1e9a807bb1977865fe (patch)
tree08cfbcc32b9fbea5f13fd3447026090f51402274 /src/tw/user.rs
parentafd61ae0822690f30d37859c806a8d8d843b8c1a (diff)
move everything to src/
Diffstat (limited to 'src/tw/user.rs')
-rw-r--r--src/tw/user.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/tw/user.rs b/src/tw/user.rs
new file mode 100644
index 0000000..1da82f0
--- /dev/null
+++ b/src/tw/user.rs
@@ -0,0 +1,46 @@
+extern crate serde_json;
+
+#[derive(Debug, Serialize, Deserialize)]
+pub struct User {
+ pub id: String,
+ pub name: String,
+ pub handle: String
+}
+
+impl Default for User {
+ fn default() -> User {
+ User {
+ id: "".to_owned(),
+ name: "_default_".to_owned(),
+ handle: "_default_".to_owned()
+ }
+ }
+}
+
+impl User {
+ pub fn from_json(json: serde_json::Value) -> Option<User> {
+ if let serde_json::Value::Object(json_map) = json {
+ if json_map.contains_key("id_str") &&
+ json_map.contains_key("name") &&
+ json_map.contains_key("screen_name") {
+ if let (
+ Some(id_str),
+ Some(name),
+ Some(screen_name)
+ ) = (
+ json_map["id_str"].as_str(),
+ json_map["name"].as_str(),
+ json_map["screen_name"].as_str()
+ ) {
+ return Some(User {
+ id: id_str.to_owned(),
+ name: name.to_owned(),
+ handle: screen_name.to_owned()
+ })
+ }
+ }
+ }
+ None
+ }
+}
+