Skip to content
This repository has been archived by the owner on Jun 13, 2022. It is now read-only.

Commit

Permalink
add paging support fixes #12
Browse files Browse the repository at this point in the history
  • Loading branch information
ciphax committed Feb 19, 2019
1 parent 5b9a547 commit 02dcd33
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions src/inwx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,31 +89,59 @@ impl Inwx {
}

fn split_domain(&mut self, domain: &str) -> Result<(String, String), InwxError> {
let request = RpcRequest::new("nameserver.list", &[]);
let page_size = 20;
let mut page = 1;

let response = self.send_request(request)?;
let dnf_error = || InwxError::ApiError {
method: "nameserver.list".to_owned(),
msg: "Domain not found".to_owned(),
reason: "".to_owned()
};

if let Ok(Value::Nodeset(ref nodes)) = evaluate_xpath(&response.get_document(), "/methodResponse/params/param/value/struct/member[name/text()=\"resData\"]/value/struct/member[name/text()=\"domains\"]/value/array/data/value/struct/member[name/text()=\"domain\"]/value/string/text()") {
for node in nodes {
if let Some(ref text) = node.text() {
let domain_root = text.text();
loop {
let request = RpcRequest::new("nameserver.list", &[
RpcRequestParameter {
name: "pagelimit",
value: RpcRequestParameterValue::Int(page_size)
},
RpcRequestParameter {
name: "page",
value: RpcRequestParameterValue::Int(page)
}
]);

if domain.ends_with(&format!(".{}", domain_root)) {
let mut name = &domain[0..domain.len() - domain_root.len() - 1];
let response = self.send_request(request)?;

return Ok((domain_root.to_owned(), name.to_owned()));
} else if domain == domain_root {
return Ok((domain_root.to_owned(), "".to_owned()));
let total: i32 = evaluate_xpath(
&response.get_document(),
"/methodResponse/params/param/value/struct/member[name/text()=\"resData\"]/value/struct/member[name/text()=\"count\"]/value/int"
)
.ok()
.and_then(|value| value.string().parse().ok())
.ok_or_else(dnf_error)?;

if let Ok(Value::Nodeset(ref nodes)) = evaluate_xpath(&response.get_document(), "/methodResponse/params/param/value/struct/member[name/text()=\"resData\"]/value/struct/member[name/text()=\"domains\"]/value/array/data/value/struct/member[name/text()=\"domain\"]/value/string/text()") {
for node in nodes {
if let Some(ref text) = node.text() {
let domain_root = text.text();

if domain.ends_with(&format!(".{}", domain_root)) {
let mut name = &domain[0..domain.len() - domain_root.len() - 1];

return Ok((domain_root.to_owned(), name.to_owned()));
} else if domain == domain_root {
return Ok((domain_root.to_owned(), "".to_owned()));
}
}
}
}
}

Err(InwxError::ApiError {
method: "nameserver.list".to_owned(),
msg: "Domain not found".to_owned(),
reason: "".to_owned()
})
if total > page * page_size {
page += 1;
} else {
return Err(dnf_error());
}
}
}

pub fn create_txt_record(&mut self, domain: &str, content: &str) -> Result<(), InwxError> {
Expand Down

0 comments on commit 02dcd33

Please sign in to comment.