use reqwest; use serde_json::Value; #[derive(Debug)] pub struct TicketData { class : String, // Type in Jira status : String, priority : String, subject : String, // Summary in Jira issue_trak_num : String, issue_trak_link: String, assignee : String, // Next Action in IssueTrak comment : String, // Note in IssueTrak // Not yet implemented Solution : String } impl TicketData { pub fn from_jira_data(json_value: Value) -> Result>{ // All of the data we need is under the fields key let json_fields = match json_value.get("fields") { Some(f) => {f.clone()}, _ => { return Err("No fields")?} }; /* Handling Jira comments is going to a nightmare. This will be implemented later */ // Believe it or not this is easier than dealing with creating structs for the reposonse // if the fields are blank 'null' will be returned as a string Ok(TicketData { class : json_fields.get("issuetype").unwrap().get("name").unwrap().to_string(), status: json_fields.get("status").unwrap().get("name").unwrap().to_string(), priority: json_fields.get("priority").unwrap().get("name").unwrap().to_string(), subject: json_fields.get("summary").unwrap().to_string(), issue_trak_num: json_fields.get("customfield_10065").unwrap().to_string(), issue_trak_link: json_fields.get("customfield_10060").unwrap().to_string(), assignee: json_fields.get("assignee").unwrap().get("displayName").unwrap().to_string(), comment: "Test".to_string()//json_fields.get("comment").unwrap().get("displayName").unwrap().to_string(), //solution: json_fields.get("solu").unwrap().get("displayName").unwrap().to_string() }) } }