Skip to content

Commit

Permalink
docs fixes and additions
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzou committed Apr 1, 2024
1 parent 16f3278 commit 9a2a4d3
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 61 deletions.
31 changes: 2 additions & 29 deletions .generator/src/generator/templates/common_mod.j2
Original file line number Diff line number Diff line change
Expand Up @@ -75,38 +75,11 @@ impl <T> From<std::io::Error> for Error<T> {
}
}

pub fn urlencode<T: AsRef<str>>(s: T) -> String {
pub(crate) fn urlencode<T: AsRef<str>>(s: T) -> String {
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
}

pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
if let serde_json::Value::Object(object) = value {
let mut params = vec![];

for (key, value) in object {
match value {
serde_json::Value::Object(_) => params.append(&mut parse_deep_object(
&format!("{}[{}]", prefix, key),
value,
)),
serde_json::Value::Array(array) => {
for (i, value) in array.iter().enumerate() {
params.append(&mut parse_deep_object(
&format!("{}[{}][{}]", prefix, key, i),
value,
));
}
},
serde_json::Value::String(s) => params.push((format!("{}[{}]", prefix, key), s.clone())),
_ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
}
}
return params;
}
unimplemented!("Only objects are supported with style=deepObject")
}

pub struct DDFormatter;
pub(crate) struct DDFormatter;

impl serde_json::ser::Formatter for DDFormatter {
fn write_f64<W>(&mut self, writer: &mut W, value: f64) -> std::io::Result<()>
Expand Down
1 change: 1 addition & 0 deletions .generator/src/generator/templates/lib.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% include "partial_header.j2" %}
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![doc = include_str!("../README.md")]

pub mod datadog;
pub mod datadogV1;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ datadog-api-client = "0"

Please follow the [installation](#installation) instructions and try the following snippet to validate your Datadog API key:

```Rust
```rust
use datadog_api_client::datadog::configuration::Configuration;
use datadog_api_client::datadogV1::api::api_authentication::AuthenticationAPI;

Expand Down
33 changes: 2 additions & 31 deletions src/datadog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,40 +77,11 @@ impl<T> From<std::io::Error> for Error<T> {
}
}

pub fn urlencode<T: AsRef<str>>(s: T) -> String {
pub(crate) fn urlencode<T: AsRef<str>>(s: T) -> String {
::url::form_urlencoded::byte_serialize(s.as_ref().as_bytes()).collect()
}

pub fn parse_deep_object(prefix: &str, value: &serde_json::Value) -> Vec<(String, String)> {
if let serde_json::Value::Object(object) = value {
let mut params = vec![];

for (key, value) in object {
match value {
serde_json::Value::Object(_) => params.append(&mut parse_deep_object(
&format!("{}[{}]", prefix, key),
value,
)),
serde_json::Value::Array(array) => {
for (i, value) in array.iter().enumerate() {
params.append(&mut parse_deep_object(
&format!("{}[{}][{}]", prefix, key, i),
value,
));
}
}
serde_json::Value::String(s) => {
params.push((format!("{}[{}]", prefix, key), s.clone()))
}
_ => params.push((format!("{}[{}]", prefix, key), value.to_string())),
}
}
return params;
}
unimplemented!("Only objects are supported with style=deepObject")
}

pub struct DDFormatter;
pub(crate) struct DDFormatter;

impl serde_json::ser::Formatter for DDFormatter {
fn write_f64<W>(&mut self, writer: &mut W, value: f64) -> std::io::Result<()>
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Copyright 2019-Present Datadog, Inc.
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![doc = include_str!("../README.md")]

pub mod datadog;
pub mod datadogV1;
Expand Down

0 comments on commit 9a2a4d3

Please sign in to comment.