Skip to content

Commit

Permalink
updated readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ANKUR DWIVEDI authored and ANKUR DWIVEDI committed Sep 2, 2024
1 parent 5589804 commit 9259521
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 2 deletions.
29 changes: 29 additions & 0 deletions Imagekit.UnitTests/Upload/UploadTestCasesAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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);
}


}
}
Expand Down
31 changes: 31 additions & 0 deletions Imagekit.UnitTests/Upload/UploadTestCasesNonAsync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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);
}

}
}
Expand Down
12 changes: 12 additions & 0 deletions Imagekit/Helper/MultipartFormDataModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using global::Imagekit.Models;
using global::Imagekit.Util;
using Newtonsoft.Json;
using System.Collections.Generic;

public static class MultipartFormDataModel
{
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions Imagekit/Imagekit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<Description>Library to Integrate Imagekit.io Service.</Description>
<PackageId>Imagekit</PackageId>
<PackOnBuild>true</PackOnBuild>
<ReleaseVersion>5.0.0</ReleaseVersion>
<ReleaseVersion>5.0.1</ReleaseVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<SynchReleaseVersion>false</SynchReleaseVersion>
<Version>5.0.0</Version>
<Version>5.0.1</Version>
<RepositoryUrl>[email protected]:imagekit-developer/imagekit-dotnet.git</RepositoryUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageReleaseNotes>-Fixes</PackageReleaseNotes>
Expand Down
2 changes: 2 additions & 0 deletions Imagekit/Models/FileCreateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ public class FileCreateRequest
public UploadTransformation transformation { get; set; }

public string checks { get; set; }

public bool? isPublished { get; set; }
}
2 changes: 2 additions & 0 deletions Imagekit/Models/FileUpdateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public class FileUpdateRequest
public string customCoordinates { get; set; }

public Hashtable customMetadata { get; set; }

public PublishStatus publish { get; set; }
}
}
11 changes: 11 additions & 0 deletions Imagekit/Models/PublishStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Imagekit.Models
{
using System.Collections.Generic;

public class PublishStatus
{
public bool isPublished { get; set; }
public bool? includeFileVersions { get; set; }
}

Check warning on line 10 in Imagekit/Models/PublishStatus.cs

View workflow job for this annotation

GitHub Actions / Build and test

}

Check warning on line 11 in Imagekit/Models/PublishStatus.cs

View workflow job for this annotation

GitHub Actions / Build and test

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit 9259521

Please sign in to comment.