+fn get_current_record_ip(api_key: &str, name: &str, fqdn: &str) -> Result<Ipv4Addr> {
+ let json_value = request_livedns_gandi(
+ api_key,
+ &format!("domains/{}/records/{}/A", fqdn, name),
+ Method::Get,
+ )?;
+
+ match &json_value["rrset_values"][0] {
+ Value::String(ip_str) => Ok(ip_str.parse()?),
+ _ => Result::Err(Box::new(Error {
+ message: format!(
+ "Unable to extract the IP from the JSON answer: {}",
+ json_value
+ ),
+ })),
+ }
+}
+
+fn update_record_ip(api_key: &str, name: &str, fqdn: &str, ip: Ipv4Addr, ttl: i32) -> Result<()> {
+ let json_body = json!(
+ {
+ "rrset_values": [ format!("{}", ip) ],
+ "rrset_ttl": ttl
+ }
+ );
+
+ let json_value = request_livedns_gandi(
+ api_key,
+ &format!("domains/{}/records/{}/A", fqdn, name),
+ Method::Put(json_body.to_string()),
+ )?;
+
+ println!("Update response: {}", json_value);
+
+ Ok(())
+}
+
+enum Method {
+ Put(String),
+ Get,
+}
+
+fn request_livedns_gandi(api_key: &str, url_fragment: &str, method: Method) -> Result<Value> {