Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor and test #9

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bb2cac9
Update README.md
hosseinRezaei188 Apr 14, 2020
15eeecf
Update README.md
hosseinRezaei188 Apr 14, 2020
94ed2c9
Update README.md
hosseinRezaei188 Apr 15, 2020
29b8507
Remove HtmlEncode from message inside Send method to prevent changing…
Mar 27, 2021
1f2bb8c
Merge pull request #3 from amirriazi/master
hosseinRezaei188 Apr 3, 2021
bfc4559
Update README.md
hosseinRezaei188 Apr 4, 2021
44e23c9
Some change in project information
hosseinRezaei188 Apr 4, 2021
17b2e2e
update Newtonsoft pakage
Nov 28, 2022
186300c
Update README.md
hosseinRezaei188 Nov 28, 2022
8a5785b
update readme
Nov 28, 2022
1ef3992
refactor(Solution) : Refactor all codes
alireza995 Nov 30, 2022
9db333f
refactor(Solution) : relocate files
alireza995 Dec 1, 2022
1397eae
refactor(Solution) : create new api
alireza995 Dec 2, 2022
6210982
refactor(Solution) : Remove unnecessary objects
alireza995 Dec 2, 2022
a789c61
refactor(Solution) : Remove unused enum
alireza995 Dec 3, 2022
d70c97e
Merge pull request #1 from alireza995/refactor/all
alireza995 Dec 3, 2022
f307c4e
test(Solution) : relocate codes and create test project
alireza995 Dec 3, 2022
1fb3165
Refactor(Solution) : refactor and add new methods
alireza995 Dec 8, 2022
ab70fc5
test(KavenegarMessageSender) : Test KavenegarMessage Sender
alireza995 Dec 9, 2022
cdc0384
test(KavenegarMessageSender) : test all methods
alireza995 Dec 11, 2022
b0669e7
test(Solution) : Test kavenegarprofile and shared project
alireza995 Dec 13, 2022
2b9678f
Merge pull request #2 from alireza995/test/all
alireza995 Dec 13, 2022
2c972d8
test(IntegrationTest) : create test project
alireza995 Dec 14, 2022
b2f22c4
test(Solution) : test all basic methods of all actions
alireza995 Dec 14, 2022
12fdf57
refactor(Kavenegar) : Add easy constructor
alireza995 Dec 14, 2022
c5bef6c
Merge pull request #3 from alireza995/test/integration
alireza995 Dec 14, 2022
25ab9e9
refactor(IntegrationTest) : refactor controllers
alireza995 Dec 15, 2022
bf815aa
Merge pull request #4 from alireza995/test/integration
alireza995 Dec 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Code/Kavenegar.Core/BaseKavenegarApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Kavenegar.Core.Dto.Result;
using Shared.Infrastructure;

namespace Kavenegar.Core;

public class BaseKavenegarApi
{
private const string ApiAddress = "https://api.kavenegar.com/v1";
private readonly IHttpClientHelper _httpClientHelper;

protected BaseKavenegarApi(
IHttpClientHelper httpClientHelper,
string apiKey)
{
_httpClientHelper = httpClientHelper;
_httpClientHelper.BaseAddress = Path.Combine(ApiAddress, apiKey);
}

protected async Task<T?> RequestSender<T>(
string requestUri,
object? body,
Dictionary<string, object?>? queryParams,
CancellationToken cancellationToken)
{
var httpResponseMessage = await _httpClientHelper.PostAsync(
requestUri,
body,
queryParams,
cancellationToken);

var deserializedObj = await httpResponseMessage.Deserialize<ResultDto<T>>(cancellationToken);

return deserializedObj == null ? default : deserializedObj.Value;
}
}
27 changes: 27 additions & 0 deletions Code/Kavenegar.Core/DependencyManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Microsoft.Extensions.DependencyInjection;
using Shared.Infrastructure;

namespace Kavenegar.Core;

public static class DependencyManager
{
public static IServiceCollection AddKavenegar(
this IServiceCollection serviceCollection,
string apiKey)
{
serviceCollection.AddScoped<HttpClient>();
serviceCollection.AddScoped<IHttpClientHelper, HttpClientHelper>();

serviceCollection.AddScoped<IKavenegarProfileApi, KavenegarProfileApi>(
serviceProvider => new KavenegarProfileApi(
serviceProvider.GetRequiredService<IHttpClientHelper>(),
apiKey));

serviceCollection.AddScoped<IKavenegarMessageSender, KavenegarMessageSender>(
serviceProvider => new KavenegarMessageSender(
serviceProvider.GetRequiredService<IHttpClientHelper>(),
apiKey));

return serviceCollection;
}
}
16 changes: 16 additions & 0 deletions Code/Kavenegar.Core/Dto/Message/MessageInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Kavenegar.Core.Enums;

namespace Kavenegar.Core.Dto.Message;

public class MessageInfo
{
public MessageInfo(
string message)
{
Message = message;
}

public string? Sender { get; set; }
public string Message { get; set; }
public MessageType Type { get; set; } = MessageType.Flash;
}
16 changes: 16 additions & 0 deletions Code/Kavenegar.Core/Dto/Message/SendMessageInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace Kavenegar.Core.Dto.Message;

public class SendMessageInfo
{
public SendMessageInfo(
MessageInfo messageInfo,
string receptor)
{
MessageInfo = messageInfo;
Receptor = receptor;
}

public MessageInfo MessageInfo { get; set; }
public string Receptor { get; set; }
public string? LocalMessageId { get; set; } = null!;
}
14 changes: 14 additions & 0 deletions Code/Kavenegar.Core/Dto/Message/SendMultiMessageRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Kavenegar.Core.Dto.Message;

public class SendMultiMessageRequest
{
public SendMultiMessageRequest(
IEnumerable<SendMessageInfo> sendMessageInfos)
{
SendMessageInfos = sendMessageInfos;
}

public IEnumerable<SendMessageInfo> SendMessageInfos { get; set; }
public DateTime Date { get; set; }
public bool Hide { get; set; }
}
23 changes: 23 additions & 0 deletions Code/Kavenegar.Core/Dto/Message/SendSingleMessageRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Kavenegar.Core.Dto.Message;

public class SendSingleMessageRequest
{
public SendSingleMessageRequest(
MessageInfo messageInfo,
Dictionary<string, string?> receptorLocalMessageIds)
{
MessageInfo = messageInfo;
ReceptorLocalMessageIds = receptorLocalMessageIds;
}

public MessageInfo MessageInfo { get; set; }

/// <summary>
/// Key is receptor
/// Value is local message id
/// </summary>
public Dictionary<string, string?> ReceptorLocalMessageIds { get; set; }

public DateTime? Date { get; set; }
public bool Hide { get; set; }
}
25 changes: 25 additions & 0 deletions Code/Kavenegar.Core/Dto/Message/VerifyLookupRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Kavenegar.Core.Enums;

namespace Kavenegar.Core.Dto.Message;

public class VerifyLookupRequest
{
public VerifyLookupRequest(
string receptor,
string template,
string token1)
{
Receptor = receptor;
Template = template;
Token1 = token1;
}

public string Receptor { get; set; }
public string Template { get; set; }
public string Token1 { get; set; }
public string? Token2 { get; set; }
public string? Token3 { get; set; }
public string? Token4 { get; set; }
public string? Token5 { get; set; }
public VerifyLookupType? VerifyLookupType { get; set; } = null!;
}
11 changes: 11 additions & 0 deletions Code/Kavenegar.Core/Dto/Result/AccountConfigDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Kavenegar.Core.Dto.Result;

public class AccountConfigDto
{
public string ApiLogs { get; set; } = null!;
public string DailyReport { get; set; } = null!;
public string DebugMode { get; set; } = null!;
public string DefaultSender { get; set; } = null!;
public string MinCreditAlarm { get; set; } = null!;
public string ResendFailed { get; set; } = null!;
}
11 changes: 11 additions & 0 deletions Code/Kavenegar.Core/Dto/Result/AccountInfoDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Shared.Infrastructure;

namespace Kavenegar.Core.Dto.Result;

public class AccountInfoDto
{
public long RemainCredit { get; set; }
public long ExpireDate { get; set; }
public DateTime GregorianExpireDate => ExpireDate.ToDateTime();
public string Type { get; set; } = null!;
}
13 changes: 13 additions & 0 deletions Code/Kavenegar.Core/Dto/Result/CountInboxDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Shared.Infrastructure;

namespace Kavenegar.Core.Dto.Result;

public class CountInboxDto
{
public long StartDate { get; set; }
public DateTime StartDateGregorian => StartDate.ToDateTime();
public long EndDate { get; set; }
public DateTime EndDateGregorian => EndDate.ToDateTime();

public long SumCount { get; set; }
}
7 changes: 7 additions & 0 deletions Code/Kavenegar.Core/Dto/Result/CountOutboxDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Kavenegar.Core.Dto.Result;

public class CountOutboxDto : CountInboxDto
{
public long SumPart { get; set; }
public long Cost { get; set; }
}
11 changes: 11 additions & 0 deletions Code/Kavenegar.Core/Dto/Result/LocalStatusDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Kavenegar.Core.Enums;

namespace Kavenegar.Core.Dto.Result;

public class LocalStatusDto
{
public long MessageId { get; set; }
public long LocalId { get; set; }
public MessageStatus Status { get; set; }
public string StatusText { get; set; } = null!;
}
13 changes: 13 additions & 0 deletions Code/Kavenegar.Core/Dto/Result/ReceivedMessageDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Shared.Infrastructure;

namespace Kavenegar.Core.Dto.Result;

public class ReceivedMessageDto
{
public long Date { get; set; }
public DateTime GregorianDate => Date.ToDateTime();
public long MessageId { get; set; }
public string Sender { get; set; } = null!;
public string Message { get; set; } = null!;
public string Receptor { get; set; } = null!;
}
12 changes: 12 additions & 0 deletions Code/Kavenegar.Core/Dto/Result/ResultDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace Kavenegar.Core.Dto.Result;

internal class ResultDto<T>
{
[JsonPropertyName("return")]
public ResultStatus Result { get; set; } = null!;

[JsonPropertyName("entries")]
public T Value { get; set; } = default!;
}
12 changes: 12 additions & 0 deletions Code/Kavenegar.Core/Dto/Result/ResultStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace Kavenegar.Core.Dto.Result;

internal class ResultStatus
{
[JsonPropertyName("status")]
public int Status { get; set; }

[JsonPropertyName("message")]
public string Message { get; set; } = null!;
}
32 changes: 32 additions & 0 deletions Code/Kavenegar.Core/Dto/Result/SendResultDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System.Text.Json.Serialization;
using Kavenegar.Core.Enums;
using Shared.Infrastructure;

namespace Kavenegar.Core.Dto.Result;

public class SendResultDto
{
public long MessageId { get; set; }
public string Message { get; set; } = null!;

[JsonPropertyName("Status")]
public int StatusNumber { get; set; }

public MessageStatus MessageStatus => StatusCaster(StatusNumber);
public string StatusText { get; set; } = null!;
public string Sender { get; set; } = null!;
public string Receptor { get; set; } = null!;

[JsonPropertyName("Date")]
public long UnixDate { get; set; }

public DateTime DateTime => UnixDate.ToDateTime();
public int Cost { get; set; }

private MessageStatus StatusCaster(
int status)
{
if (Enum.IsDefined(typeof(MessageStatus), StatusNumber)) return (MessageStatus)status;
return status == 5 ? MessageStatus.SentToCenter : MessageStatus.Unknown;
}
}
10 changes: 10 additions & 0 deletions Code/Kavenegar.Core/Dto/Result/StatusMessageDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Kavenegar.Core.Enums;

namespace Kavenegar.Core.Dto.Result;

public class StatusMessageDto
{
public long Messageid { get; set; }
public MessageStatus Status { get; set; }
public string StatusText { get; set; } = null!;
}
15 changes: 15 additions & 0 deletions Code/Kavenegar.Core/Enums/MessageStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Kavenegar.Core.Enums;

public enum MessageStatus
{
Unknown = 0,
Queued = 1,
Scheduled = 2,
SentToCenter = 4,
Delivered = 10,
Undelivered = 11,
Canceled = 13,
Filtered = 14,
Received = 50,
Incorrect = 100
}
9 changes: 9 additions & 0 deletions Code/Kavenegar.Core/Enums/MessageType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Kavenegar.Core.Enums;

public enum MessageType
{
Flash = 0,
MobileMemory = 1,
SimMemory = 2,
AppMemory = 3
}
7 changes: 7 additions & 0 deletions Code/Kavenegar.Core/Enums/VerifyLookupType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Kavenegar.Core.Enums;

public enum VerifyLookupType
{
Sms = 0,
Call = 1
}
Loading