From 92595210bf75bf7c1557f98292a68ad4e4061512 Mon Sep 17 00:00:00 2001 From: ANKUR DWIVEDI Date: Mon, 2 Sep 2024 13:39:55 +0530 Subject: [PATCH] updated readme.md --- .../Upload/UploadTestCasesAsync.cs | 29 +++++++++++++++++ .../Upload/UploadTestCasesNonAsync.cs | 31 +++++++++++++++++++ Imagekit/Helper/MultipartFormDataModel.cs | 12 +++++++ Imagekit/Imagekit.csproj | 4 +-- Imagekit/Models/FileCreateRequest.cs | 2 ++ Imagekit/Models/FileUpdateRequest.cs | 2 ++ Imagekit/Models/PublishStatus.cs | 11 +++++++ README.md | 17 ++++++++++ 8 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 Imagekit/Models/PublishStatus.cs diff --git a/Imagekit.UnitTests/Upload/UploadTestCasesAsync.cs b/Imagekit.UnitTests/Upload/UploadTestCasesAsync.cs index 3108ac7..0475f1a 100644 --- a/Imagekit.UnitTests/Upload/UploadTestCasesAsync.cs +++ b/Imagekit.UnitTests/Upload/UploadTestCasesAsync.cs @@ -206,6 +206,7 @@ public void UploadFile_Default() ob.overwriteCustomMetadata = true; ob.transformation = uploadTransformation; ob.checks = "'request.folder' : '/dummy-folder'"; + ob.isPublished = true; Hashtable model = new Hashtable { { "price", 2000 } @@ -394,6 +395,34 @@ public void UpdateFile_Default() Assert.Equal(responseObj1, response.Raw); } + [Fact] + public void UpdateFile_Publish_Status() + { + FileUpdateRequest ob = new FileUpdateRequest + { + fileId = "file-Id", + + }; + PublishStatus publishStatus = new PublishStatus + { + isPublished = false + }; + ob.publish = publishStatus; + var responseObj = TestHelpers.ImagekitResponseFaker.Generate(); + var httpResponse = new HttpResponseMessage + { + StatusCode = HttpStatusCode.OK, + Content = new StringContent(JsonConvert.SerializeObject(responseObj)) + }; + var httpClient = TestHelpers.GetTestHttpClient(httpResponse); + + var restClient = new RestClient(GOOD_PUBLICKEY, GOOD_URLENDPOINT, httpClient); + + var response = (Result)restClient.UpdateFileDetailAsync(ob).Result; + var responseObj1 = JsonConvert.SerializeObject(responseObj); + Assert.Equal(responseObj1, response.Raw); + } + } } diff --git a/Imagekit.UnitTests/Upload/UploadTestCasesNonAsync.cs b/Imagekit.UnitTests/Upload/UploadTestCasesNonAsync.cs index 5ec58f7..4ed8340 100644 --- a/Imagekit.UnitTests/Upload/UploadTestCasesNonAsync.cs +++ b/Imagekit.UnitTests/Upload/UploadTestCasesNonAsync.cs @@ -193,6 +193,8 @@ public void UploadFile_DefaultNonAsync() ob.overwriteAITags = false; ob.overwriteTags = false; ob.overwriteCustomMetadata = true; + ob.checks = "'request.folder' : '/dummy-folder'"; + ob.isPublished = true; Hashtable model = new Hashtable { { "price", 2000 } @@ -381,6 +383,35 @@ public void UpdateFile_Default() var responseObj1 = JsonConvert.SerializeObject(responseObj); Assert.Equal(responseObj1, response.Raw); } + + [Fact] + public void UpdateFile_Publish_Status() + { + FileUpdateRequest ob = new FileUpdateRequest + { + fileId = "file-Id", + + }; + PublishStatus publishStatus = new PublishStatus + { + isPublished = false + }; + ob.publish = publishStatus; + + var responseObj = TestHelpers.ImagekitResponseFaker.Generate(); + var httpResponse = new HttpResponseMessage + { + StatusCode = HttpStatusCode.OK, + Content = new StringContent(JsonConvert.SerializeObject(responseObj)) + }; + var httpClient = TestHelpers.GetTestHttpClient(httpResponse); + + var restClient = new RestClient(GOOD_PUBLICKEY, GOOD_URLENDPOINT, httpClient); + + var response = (Result)restClient.UpdateFileDetail(ob); + var responseObj1 = JsonConvert.SerializeObject(responseObj); + Assert.Equal(responseObj1, response.Raw); + } } } diff --git a/Imagekit/Helper/MultipartFormDataModel.cs b/Imagekit/Helper/MultipartFormDataModel.cs index 5c78fd9..cb670a7 100644 --- a/Imagekit/Helper/MultipartFormDataModel.cs +++ b/Imagekit/Helper/MultipartFormDataModel.cs @@ -8,6 +8,7 @@ using global::Imagekit.Models; using global::Imagekit.Util; using Newtonsoft.Json; + using System.Collections.Generic; public static class MultipartFormDataModel { @@ -116,6 +117,11 @@ public static MultipartFormDataContent Build(FileCreateRequest fileCreateRequest formdata.Add(new StringContent(fileCreateRequest.checks), "checks"); } + if (fileCreateRequest.isPublished.HasValue) + { + formdata.Add(new StringContent(fileCreateRequest.isPublished.Value.ToString().ToLower()), "isPublished"); + } + return formdata; } @@ -162,6 +168,12 @@ public static MultipartFormDataContent BuildUpdateFile(FileUpdateRequest fileCre formdata.Add(new StringContent(jSONresult), "customMetadata"); } + if (fileCreateRequest.publish != null) + { + string jSONresult = JsonConvert.SerializeObject(fileCreateRequest.publish); + formdata.Add(new StringContent(jSONresult), "publish"); + } + return formdata; } } diff --git a/Imagekit/Imagekit.csproj b/Imagekit/Imagekit.csproj index 013cc8b..dcd06ff 100644 --- a/Imagekit/Imagekit.csproj +++ b/Imagekit/Imagekit.csproj @@ -17,10 +17,10 @@ Library to Integrate Imagekit.io Service. Imagekit true - 5.0.0 + 5.0.1 true false - 5.0.0 + 5.0.1 git@github.com:imagekit-developer/imagekit-dotnet.git true -Fixes diff --git a/Imagekit/Models/FileCreateRequest.cs b/Imagekit/Models/FileCreateRequest.cs index 3c45e90..9787a6b 100644 --- a/Imagekit/Models/FileCreateRequest.cs +++ b/Imagekit/Models/FileCreateRequest.cs @@ -42,4 +42,6 @@ public class FileCreateRequest public UploadTransformation transformation { get; set; } public string checks { get; set; } + + public bool? isPublished { get; set; } } \ No newline at end of file diff --git a/Imagekit/Models/FileUpdateRequest.cs b/Imagekit/Models/FileUpdateRequest.cs index e5b5999..9d1bd55 100644 --- a/Imagekit/Models/FileUpdateRequest.cs +++ b/Imagekit/Models/FileUpdateRequest.cs @@ -18,5 +18,7 @@ public class FileUpdateRequest public string customCoordinates { get; set; } public Hashtable customMetadata { get; set; } + + public PublishStatus publish { get; set; } } } diff --git a/Imagekit/Models/PublishStatus.cs b/Imagekit/Models/PublishStatus.cs new file mode 100644 index 0000000..be11998 --- /dev/null +++ b/Imagekit/Models/PublishStatus.cs @@ -0,0 +1,11 @@ +namespace Imagekit.Models +{ + using System.Collections.Generic; + + public class PublishStatus + { + public bool isPublished { get; set; } + public bool? includeFileVersions { get; set; } + } + +} diff --git a/README.md b/README.md index 31195ce..b7bcdc8 100644 --- a/README.md +++ b/README.md @@ -450,6 +450,23 @@ updateob.webhookUrl = "https://webhook.site/c78d617f_33bc_40d9_9e61_608999721e2e Result updateresp = imagekit.UpdateFileDetail(updateob); ``` +**Update publish status** + +If `publish` is included in the update options, no other parameters are allowed. + +```cs +FileUpdateRequest updateob = new FileUpdateRequest +{ + fileId = "fileId", +}; +PublishStatus publishStatus = new PublishStatus +{ + isPublished = false +}; +updateob.publish = publishStatus; +Result updateresp = imagekit.UpdateFileDetail(updateob); +``` + **4\. Delete File** Accept the file ID and delete a file as per the [API documentation here](https://docs.imageKit.io/api-reference/media-api/delete-file).