-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* The versions of the `Microsoft.Extensions.Http` and `System.Text.Json` packages in the `Sinch.csproj` file have been updated. * feat: add FaxRegion and resolve url based on it * refactor: create fax request take either content url, stream or filePath * refactor: list query create query param * feat: add fax autolist * chore: add string output to debug for json responses * feat: upload fax as multipart/form data * feat:process other kind of api error * feat: impl get fax * feat: implement download fax, add example * feat: implement delete * feat: implement list * feat: add fax mock service * chore(http): add test for multipart content * feat: for last page add calculate if first page starting at 1 * chore: add comment for unused StreamExtensions.cs * feat: add multiple or single send fax * feat: return contentresult with stream and filename for content download --------- Co-authored-by: spacedsweden <christian@sinch.com>
- Loading branch information
1 parent
bb7fe2b
commit ca8c550
Showing
34 changed files
with
2,207 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using Sinch; | ||
|
||
namespace Examples.Fax | ||
{ | ||
public class DownloadFax | ||
{ | ||
public static async Task Example() | ||
{ | ||
var sinchClient = new SinchClient("PROJECT_ID", "KEY_ID", "KEY_SECRET"); | ||
const string faxId = "FAX_ID"; | ||
|
||
await using var contentResult = await sinchClient.Fax.Faxes.DownloadContent("faxId"); | ||
const string directory = @"C:\Downloads\"; | ||
if (!Path.Exists(directory)) | ||
{ | ||
Directory.CreateDirectory(directory); | ||
} | ||
|
||
await using var fileStream = | ||
new FileStream(Path.Combine(directory, contentResult.FileName ?? $"{faxId}.pdf"), FileMode.Create, | ||
FileAccess.Write); | ||
await contentResult.Stream.CopyToAsync(fileStream); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
|
||
namespace Sinch.Core | ||
{ | ||
public sealed class ContentResult : IDisposable, IAsyncDisposable | ||
{ | ||
/// <summary> | ||
/// The Stream containing data of the file | ||
/// </summary> | ||
public Stream Stream { get; init; } = null!; | ||
|
||
/// <summary> | ||
/// Name of the file, if available. | ||
/// </summary> | ||
public string? FileName { get; init; } | ||
|
||
public void Dispose() | ||
{ | ||
Stream.Dispose(); | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
await Stream.DisposeAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System; | ||
using System.IO; | ||
|
||
namespace Sinch.Core | ||
{ | ||
internal static class StreamExtensions | ||
{ | ||
// NOTE: not used, may be used in send fax json request | ||
public static string ConvertToBase64(this Stream stream) | ||
{ | ||
if (stream is MemoryStream memoryStream) | ||
{ | ||
return Convert.ToBase64String(memoryStream.ToArray()); | ||
} | ||
|
||
var bytes = new Byte[(int)stream.Length]; | ||
|
||
stream.Seek(0, SeekOrigin.Begin); | ||
stream.Read(bytes, 0, (int)stream.Length); | ||
|
||
return Convert.ToBase64String(bytes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.