feat: added more types and fixed broken ones
This commit is contained in:
parent
5df6d0f7d9
commit
43e5fc6005
1 changed files with 112 additions and 15 deletions
127
src/lib.rs
127
src/lib.rs
|
|
@ -276,6 +276,7 @@ pub struct Databases<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Databases<'_> {
|
impl Databases<'_> {
|
||||||
|
// FIXME: This call can have Databases mixed in with the Page's, needs an intermediary
|
||||||
pub async fn query<'a>(
|
pub async fn query<'a>(
|
||||||
&self,
|
&self,
|
||||||
options: DatabaseQueryOptions<'a>,
|
options: DatabaseQueryOptions<'a>,
|
||||||
|
|
@ -824,6 +825,7 @@ pub enum DatabaseProperty {
|
||||||
Status {
|
Status {
|
||||||
id: String,
|
id: String,
|
||||||
name: String,
|
name: String,
|
||||||
|
// TODO: add "groups"
|
||||||
options: DatabaseSelectOptions,
|
options: DatabaseSelectOptions,
|
||||||
},
|
},
|
||||||
Title {
|
Title {
|
||||||
|
|
@ -919,7 +921,7 @@ where
|
||||||
|
|
||||||
serde_json::from_value::<DatabaseProperty>(value.to_owned()).unwrap_or_else(|error| {
|
serde_json::from_value::<DatabaseProperty>(value.to_owned()).unwrap_or_else(|error| {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"Could not parse value because of error, defaulting to DatabaseProperty::Unsupported:\n= ERROR:\n{error:?}\n= JSON:\n{:?}\n---",
|
"Could not parse DatabaseProperty value because of error, defaulting to DatabaseProperty::Unsupported:\n= ERROR:\n{error:?}\n= JSON:\n{:?}\n---",
|
||||||
serde_json::to_string_pretty(&value).expect("to pretty print the database property error")
|
serde_json::to_string_pretty(&value).expect("to pretty print the database property error")
|
||||||
);
|
);
|
||||||
DatabaseProperty::Unsupported(value.to_owned())
|
DatabaseProperty::Unsupported(value.to_owned())
|
||||||
|
|
@ -935,6 +937,7 @@ pub struct Number {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum NumberFormat {
|
pub enum NumberFormat {
|
||||||
ArgentinePeso,
|
ArgentinePeso,
|
||||||
Baht,
|
Baht,
|
||||||
|
|
@ -992,6 +995,22 @@ pub struct Relation {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
|
#[serde(tag = "type")]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
// TODO: Implement all enums here
|
||||||
|
pub enum Rollup {
|
||||||
|
Array {
|
||||||
|
function: RollupFunction,
|
||||||
|
array: Vec<RollupProperty>,
|
||||||
|
},
|
||||||
|
Date,
|
||||||
|
Incomplete,
|
||||||
|
Number,
|
||||||
|
Unsupported,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum RollupFunction {
|
pub enum RollupFunction {
|
||||||
Average,
|
Average,
|
||||||
Checked,
|
Checked,
|
||||||
|
|
@ -1020,12 +1039,73 @@ pub enum RollupFunction {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
pub enum RollupValue {
|
#[serde(tag = "type")]
|
||||||
Array,
|
#[serde(rename_all = "snake_case")]
|
||||||
Date,
|
pub enum RollupProperty {
|
||||||
Incomplete,
|
Checkbox {
|
||||||
Number,
|
checkbox: bool,
|
||||||
Unsupported,
|
},
|
||||||
|
CreatedBy {},
|
||||||
|
CreatedTime {
|
||||||
|
created_time: DateValue,
|
||||||
|
},
|
||||||
|
Date {
|
||||||
|
date: Option<Date>,
|
||||||
|
},
|
||||||
|
Email {
|
||||||
|
email: Option<String>,
|
||||||
|
},
|
||||||
|
Files {
|
||||||
|
files: Vec<File>,
|
||||||
|
},
|
||||||
|
Formula {
|
||||||
|
name: Option<String>,
|
||||||
|
formula: Formula,
|
||||||
|
},
|
||||||
|
LastEditedBy {
|
||||||
|
last_edited_by: User,
|
||||||
|
},
|
||||||
|
LastEditedTime {
|
||||||
|
last_edited_time: DateValue,
|
||||||
|
},
|
||||||
|
Select {
|
||||||
|
select: SelectOption,
|
||||||
|
},
|
||||||
|
MultiSelect {
|
||||||
|
multi_select: Vec<SelectOption>,
|
||||||
|
},
|
||||||
|
Number {
|
||||||
|
number: Option<f32>,
|
||||||
|
},
|
||||||
|
People {},
|
||||||
|
PhoneNumber {},
|
||||||
|
Relation {
|
||||||
|
relation: Vec<Relation>,
|
||||||
|
},
|
||||||
|
Rollup {
|
||||||
|
rollup: Rollup,
|
||||||
|
},
|
||||||
|
RichText {
|
||||||
|
rich_text: Vec<RichText>,
|
||||||
|
},
|
||||||
|
Status {
|
||||||
|
status: Option<SelectOption>,
|
||||||
|
},
|
||||||
|
Title {
|
||||||
|
title: Vec<RichText>,
|
||||||
|
},
|
||||||
|
Url {
|
||||||
|
url: Option<String>,
|
||||||
|
},
|
||||||
|
Verification {
|
||||||
|
state: VerificationState,
|
||||||
|
verified_by: Option<User>,
|
||||||
|
date: Option<Date>,
|
||||||
|
},
|
||||||
|
UniqueId {},
|
||||||
|
Button {},
|
||||||
|
|
||||||
|
Unsupported(Value),
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Paginate all possible responses
|
// TODO: Paginate all possible responses
|
||||||
|
|
@ -1034,6 +1114,7 @@ pub struct QueryResponse<T> {
|
||||||
pub has_more: Option<bool>,
|
pub has_more: Option<bool>,
|
||||||
pub next_cursor: Option<String>,
|
pub next_cursor: Option<String>,
|
||||||
pub results: Vec<T>,
|
pub results: Vec<T>,
|
||||||
|
pub page_or_database: Value,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
|
|
@ -1087,6 +1168,7 @@ pub enum Property {
|
||||||
},
|
},
|
||||||
CreatedBy {
|
CreatedBy {
|
||||||
id: String,
|
id: String,
|
||||||
|
created_by: User,
|
||||||
},
|
},
|
||||||
CreatedTime {
|
CreatedTime {
|
||||||
id: String,
|
id: String,
|
||||||
|
|
@ -1131,9 +1213,11 @@ pub enum Property {
|
||||||
},
|
},
|
||||||
People {
|
People {
|
||||||
id: String,
|
id: String,
|
||||||
|
people: Vec<User>,
|
||||||
},
|
},
|
||||||
PhoneNumber {
|
PhoneNumber {
|
||||||
id: String,
|
id: String,
|
||||||
|
phone_number: Option<String>,
|
||||||
},
|
},
|
||||||
Relation {
|
Relation {
|
||||||
id: String,
|
id: String,
|
||||||
|
|
@ -1142,9 +1226,7 @@ pub enum Property {
|
||||||
},
|
},
|
||||||
Rollup {
|
Rollup {
|
||||||
id: String,
|
id: String,
|
||||||
function: RollupFunction,
|
rollup: Rollup,
|
||||||
// TODO: This will not parse properly and needs custom deserializer code
|
|
||||||
value: RollupValue,
|
|
||||||
},
|
},
|
||||||
RichText {
|
RichText {
|
||||||
id: String,
|
id: String,
|
||||||
|
|
@ -1152,7 +1234,7 @@ pub enum Property {
|
||||||
},
|
},
|
||||||
Status {
|
Status {
|
||||||
id: String,
|
id: String,
|
||||||
status: SelectOption,
|
status: Option<SelectOption>,
|
||||||
},
|
},
|
||||||
Title {
|
Title {
|
||||||
id: String,
|
id: String,
|
||||||
|
|
@ -1164,12 +1246,11 @@ pub enum Property {
|
||||||
},
|
},
|
||||||
Verification {
|
Verification {
|
||||||
id: String,
|
id: String,
|
||||||
state: VerificationState,
|
verification: Verification,
|
||||||
verified_by: Option<User>,
|
|
||||||
date: Option<Date>,
|
|
||||||
},
|
},
|
||||||
UniqueId {
|
UniqueId {
|
||||||
id: String,
|
id: String,
|
||||||
|
unique_id: UniqueId,
|
||||||
},
|
},
|
||||||
Button {
|
Button {
|
||||||
id: String,
|
id: String,
|
||||||
|
|
@ -1280,7 +1361,7 @@ where
|
||||||
key.to_owned(),
|
key.to_owned(),
|
||||||
serde_json::from_value::<Property>(value.to_owned()).unwrap_or_else(|error| {
|
serde_json::from_value::<Property>(value.to_owned()).unwrap_or_else(|error| {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"Could not parse value because of error, defaulting to Property::Unsupported:\n= ERROR:\n{error:#?}\n= JSON:\n{}\n---",
|
"Could not parse Property value because of error, defaulting to Property::Unsupported:\n= ERROR:\n{error:#?}\n= JSON:\n{}\n---",
|
||||||
serde_json::to_string_pretty(&value).expect("to pretty print Property errors")
|
serde_json::to_string_pretty(&value).expect("to pretty print Property errors")
|
||||||
);
|
);
|
||||||
Property::Unsupported(value.to_owned())
|
Property::Unsupported(value.to_owned())
|
||||||
|
|
@ -1289,10 +1370,26 @@ where
|
||||||
})
|
})
|
||||||
.collect::<HashMap<String, Property>>())
|
.collect::<HashMap<String, Property>>())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum VerificationState {
|
pub enum VerificationState {
|
||||||
Verified,
|
Verified,
|
||||||
Unverified,
|
Unverified,
|
||||||
|
Expired,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
|
pub struct Verification {
|
||||||
|
state: VerificationState,
|
||||||
|
verified_by: Option<User>,
|
||||||
|
date: Option<Date>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
|
pub struct UniqueId {
|
||||||
|
number: i32,
|
||||||
|
prefix: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue