pub async fn dataset_create_new(
        &self,
        new_dataset: DatasetNew,
    ) -> anyhow::Result<DatasetNewResponse> {
        new_dataset.validate_resources()?;
        let metadata = new_dataset.metadata;

        let (owner_slug, dataset_slug) = self
            .get_user_and_identifier_slug(&metadata.id)
            .map(|(s1, s2)| (s1.to_string(), s2.to_string()))?;

        // validate
        if dataset_slug == "INSERT_SLUG_HERE" {
            return Err(KaggleError::meta(
                "Default slug detected, please change values before uploading",
            )
            .into());
        }
        if metadata.title == "INSERT_SLUG_HERE" {
            return Err(KaggleError::meta(
                "Default title detected, please change values before uploading",
            )
            .into());
        }
        if metadata.licenses.len() != 1 {
            return Err(KaggleError::meta("Please specify exactly one license").into());
        }
        if dataset_slug.len() < 6 || dataset_slug.len() > 50 {
            return Err(
                KaggleError::meta("The dataset slug must be between 6 and 50 characters").into(),
            );
        }
        if metadata.title.len() < 6 || metadata.title.len() > 50 {
            return Err(
                KaggleError::meta("The dataset title must be between 6 and 50 characters").into(),
            );
        }

        let mut request = DatasetNewRequest::builder(metadata.title);
        if let Some(subtitle) = &metadata.subtitle {
            if subtitle.len() < 20 || subtitle.len() > 80 {
                return Err(KaggleError::meta(
                    "Subtitle length must be between 20 and 80 characters",
                )
                .into());
            }
            request = request.subtitle(subtitle);
        }

        let files = if let Some(folder) = new_dataset.dataset_folder {
            self.upload_files(folder, &metadata.resources, new_dataset.archive_mode)
                .await?
        } else {
            vec![]
        };

        let mut request = request
            .slug(dataset_slug)
            .owner_slug(owner_slug)
            .license_name(metadata.licenses[0].to_string())
            .with_private(new_dataset.is_private)
            .convert_to_csv(new_dataset.convert_to_csv)
            .category_ids(metadata.keywords)
            .files(files);
        if let Some(desc) = metadata.description {
            request = request.description(desc);
        }

        Ok(self.datasets_create_new(&request.build()).await?)
    }
/// Create a new dataset meaning the same as creating a version but with
/// extra metadata like license and user/owner.
///
/// This will upload any referenced resources in the metadata resources.
/// This will fail on kaggle if the metadata contains no resources to
/// upload.
///
/// Example
///
/// Create a new kaggle dataset based on the `./dataset-metadata.json`
///
/// ```json
/// {
///   "title": "My Awesome dataset",
///   "id": "mattsse/my-awesome-dataset",
///   "licenses": [
///     {
///       "name": "CC0-1.0"
///     }
///   ],
///   "resources": [
///     {
///       "path": "LICENSE",
///       "description": "This is the license"
///     }
///   ]
/// }
/// ```
///
/// ```no_run
/// use kaggle::models::DatasetNew;
/// use kaggle::KaggleApiClient;
///
/// #[tokio::main]
/// async fn main() -> Result<(), Box<dyn std::error::Error>> {
///     let kaggle = KaggleApiClient::builder().build()?;
///     let resp = kaggle
///         .dataset_create_new(DatasetNew::with_metadata_file(".").await?)
///         .await?;
///     Ok(())
/// }
/// ```
Create a new dataset meaning the same as creating a version but with
extra metadata like license and user/owner.

This will upload any referenced resources in the metadata resources.
This will fail on kaggle if the metadata contains no resources to
upload.

Example

Create a new kaggle dataset based on the `./dataset-metadata.json`




Create a new dataset meaning the same as creating a version but with extra metadata like license and user / owner . This will upload any referenced resources in the metadata resources . This will fail on kaggle if the metadata contains no resources to upload . Example Create a new kaggle dataset based on the ` . / dataset - metadata . json `
pub async fn dataset_create_new(
        &self,
        new_dataset: DatasetNew,
    ) -> anyhow::Result<DatasetNewResponse> {
        new_dataset.validate_resources()?;
        let metadata = new_dataset.metadata;
        let (owner_slug, dataset_slug) = self
            .get_user_and_identifier_slug(&metadata.id)
            .map(|(s1, s2)| (s1.to_string(), s2.to_string()))?;
        // validate
        if dataset_slug == "INSERT_SLUG_HERE" {
            return Err(KaggleError::meta(
                "Default slug detected, please change values before uploading",
            )
            .into());
        }
        if metadata.title == "INSERT_SLUG_HERE" {
            return Err(KaggleError::meta(
                "Default title detected, please change values before uploading",
            )
            .into());
        }
        if metadata.licenses.len() != 1 {
            return Err(KaggleError::meta("Please specify exactly one license").into());
        }
        if dataset_slug.len() < 6 || dataset_slug.len() > 50 {
            return Err(
                KaggleError::meta("The dataset slug must be between 6 and 50 characters").into(),
            );
        }
        if metadata.title.len() < 6 || metadata.title.len() > 50 {
            return Err(
                KaggleError::meta("The dataset title must be between 6 and 50 characters").into(),
            );
        }
        let mut request = DatasetNewRequest::builder(metadata.title);
        if let Some(subtitle) = &metadata.subtitle {
            if subtitle.len() < 20 || subtitle.len() > 80 {
                return Err(KaggleError::meta(
                    "Subtitle length must be between 20 and 80 characters",
                )
                .into());
            }
            request = request.subtitle(subtitle);
        }
        let files = if let Some(folder) = new_dataset.dataset_folder {
            self.upload_files(folder, &metadata.resources, new_dataset.archive_mode)
                .await?
        } else {
            vec![]
        };
        let mut request = request
            .slug(dataset_slug)
            .owner_slug(owner_slug)
            .license_name(metadata.licenses[0].to_string())
            .with_private(new_dataset.is_private)
            .convert_to_csv(new_dataset.convert_to_csv)
            .category_ids(metadata.keywords)
            .files(files);
        if let Some(desc) = metadata.description {
            request = request.description(desc);
        }
        Ok(self.datasets_create_new(&request.build()).await?)
    }
pub async fn dataset_create_new ( & self , new_dataset : DatasetNew , ) -> anyhow :: Result < DatasetNewResponse > { new_dataset . validate_resources ( ) ? ; let metadata = new_dataset . metadata ; let ( owner_slug , dataset_slug ) = self . get_user_and_identifier_slug ( & metadata . id ) . map ( | ( s1 , s2 ) | ( s1 . to_string ( ) , s2 . to_string ( ) ) ) ? ; // validate if dataset_slug == " " { return Err ( KaggleError :: meta ( " " , ) . into ( ) ) ; } if metadata . title == " " { return Err ( KaggleError :: meta ( " " , ) . into ( ) ) ; } if metadata . licenses . len ( ) != 1 { return Err ( KaggleError :: meta ( " " ) . into ( ) ) ; } if dataset_slug . len ( ) < 6 || dataset_slug . len ( ) > 50 { return Err ( KaggleError :: meta ( " " ) . into ( ) , ) ; } if metadata . title . len ( ) < 6 || metadata . title . len ( ) > 50 { return Err ( KaggleError :: meta ( " " ) . into ( ) , ) ; } let mut request = DatasetNewRequest :: builder ( metadata . title ) ; if let Some ( subtitle ) = & metadata . subtitle { if subtitle . len ( ) < 20 || subtitle . len ( ) > 80 { return Err ( KaggleError :: meta ( " " , ) . into ( ) ) ; } request = request . subtitle ( subtitle ) ; } let files = if let Some ( folder ) = new_dataset . dataset_folder { self . upload_files ( folder , & metadata . resources , new_dataset . archive_mode ) . await ? } else { vec ! [ ] } ; let mut request = request . slug ( dataset_slug ) . owner_slug ( owner_slug ) . license_name ( metadata . licenses [ 0 ] . to_string ( ) ) . with_private ( new_dataset . is_private ) . convert_to_csv ( new_dataset . convert_to_csv ) . category_ids ( metadata . keywords ) . files ( files ) ; if let Some ( desc ) = metadata . description { request = request . description ( desc ) ; } Ok ( self . datasets_create_new ( & request . build ( ) ) . await ? ) }
Create a new dataset meaning the same as creating a version but with
extra metadata like license and user/owner.
Create a new dataset meaning the same as creating a version but with extra metadata like license and user / owner .
&self
new_dataset
DatasetNew
&self
new_dataset
DatasetNew
[tokio::main]
async fn main() -> Result<(), Box> {
let kaggle = KaggleApiClient::builder().build()?;
let resp = kaggle
.dataset_create_new(DatasetNew::with_metadata_file(".").await?)
.await?;
Ok(())
}
```
async fn main () - > Result< () Box > { let kaggle = KaggleApiClient :: builder () . build () ? ; let resp = kaggle . dataset_create_new ( DatasetNew :: with_metadata_file ( " . " ) . await? ) . await? ; Ok (( )) } ` ` `