Skip to content

Commit

Permalink
Support for template usage in SMS
Browse files Browse the repository at this point in the history
#"template" parameter is missing #33
  • Loading branch information
jlabno committed Apr 12, 2023
1 parent c11adf1 commit 3ea55e4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 51 deletions.
109 changes: 59 additions & 50 deletions smsapi/Api/Action/SMS/Send.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@ namespace SMSApi.Api.Action
{
public class SMSSend : Send
{
private string DataCoding;
private string DateExpire;
private bool Details = true;
private string Encoding = "UTF-8";
private bool Fast;
private bool Flash;
private int MaxParts;
private bool Normalize;
private bool NoUnicode;
private string[] Params;
private string Sender;
private bool Single;
private string Text;
private const string Encoding = "UTF-8";

private string dataCoding;
private string dateExpire;
private bool fast;
private bool flash;
private int maxParts;
private bool normalize;
private bool noUnicode;
private string[] @params;
private string sender;
private bool single;
private string text;
private string? template;

protected override RequestMethod Method => RequestMethod.POST;

Expand All @@ -29,19 +30,19 @@ public SMSSend SetCheckIDx(bool check = true)

public SMSSend SetDataCoding(string dataCoding)
{
DataCoding = dataCoding;
this.dataCoding = dataCoding;
return this;
}

public SMSSend SetDateExpire(string data)
{
DateExpire = data;
dateExpire = data;
return this;
}

public SMSSend SetDateExpire(DateTime data)
{
DateExpire = data.ToString("yyyy-MM-ddTHH:mm:ssK");
dateExpire = data.ToString("yyyy-MM-ddTHH:mm:ssK");
return this;
}

Expand All @@ -67,13 +68,13 @@ public SMSSend SetEncoding(string encoding)

public SMSSend SetFast(bool fast = true)
{
Fast = fast;
this.fast = fast;
return this;
}

public SMSSend SetFlash(bool flash = true)
{
Flash = flash;
this.flash = flash;
return this;
}

Expand All @@ -97,13 +98,13 @@ public SMSSend SetIDx(string[] idx)

public SMSSend SetNormalize(bool flag = true)
{
Normalize = flag;
normalize = flag;
return this;
}

public SMSSend SetNoUnicode(bool noUnicode = true)
{
NoUnicode = noUnicode;
this.noUnicode = noUnicode;
return this;
}

Expand All @@ -119,12 +120,12 @@ public SMSSend SetParam(int i, string text)
throw new IndexOutOfRangeException();
}

if (Params == null)
if (@params == null)
{
Params = new string[4];
@params = new string[4];
}

Params[i] = text;
@params[i] = text;

return this;
}
Expand All @@ -137,13 +138,13 @@ public SMSSend SetPartner(string partner)

public SMSSend SetSender(string sender)
{
Sender = sender;
this.sender = sender;
return this;
}

public SMSSend SetSingle(bool single = true)
{
Single = single;
this.single = single;
return this;
}

Expand All @@ -155,7 +156,7 @@ public SMSSend SetTest(bool test = true)

public SMSSend SetText(string text)
{
Text = text;
this.text = text;
return this;
}

Expand All @@ -170,6 +171,13 @@ public SMSSend SetTo(string[] to)
To = to;
return this;
}

public SMSSend SetTemplate(string templateName)
{
template = templateName;

return this;
}

protected override string Uri()
{
Expand All @@ -183,7 +191,7 @@ protected override void Validate()
throw new ArgumentException("Cannot use 'to' and 'group' at the same time!");
}

if (Text == null)
if (text == null)
{
throw new ArgumentException("Cannot send message without text!");
}
Expand All @@ -193,9 +201,9 @@ protected override NameValueCollection Values()
{
var collection = new NameValueCollection();

if (Sender != null)
if (sender != null)
{
collection.Add("from", Sender);
collection.Add("from", sender);
}

if (To != null)
Expand All @@ -208,31 +216,32 @@ protected override NameValueCollection Values()
collection.Add("group", Group);
}

collection.Add("message", Text);
collection.Add("message", text);

collection.Add("single", Single ? "1" : "0");
collection.Add("nounicode", NoUnicode ? "1" : "0");
collection.Add("flash", Flash ? "1" : "0");
collection.Add("fast", Fast ? "1" : "0");
collection.Add("single", single ? "1" : "0");
collection.Add("nounicode", noUnicode ? "1" : "0");
collection.Add("flash", flash ? "1" : "0");
collection.Add("fast", fast ? "1" : "0");
collection.Add("details", "1");

if (DataCoding != null)
if (dataCoding != null)
{
collection.Add("datacoding", DataCoding);
collection.Add("datacoding", dataCoding);
}

if (MaxParts > 0)
if (maxParts > 0)
{
collection.Add("max_parts", MaxParts.ToString());
collection.Add("max_parts", maxParts.ToString());
}

if (DateSent != null)
{
collection.Add("date", DateSent);
}

if (DateExpire != null)
if (dateExpire != null)
{
collection.Add("expiration_date", DateExpire);
collection.Add("expiration_date", dateExpire);
}

if (Partner != null)
Expand All @@ -242,7 +251,7 @@ protected override NameValueCollection Values()

collection.Add("encoding", Encoding);

if (Normalize)
if (normalize)
{
collection.Add("normalize", "1");
}
Expand All @@ -258,22 +267,22 @@ protected override NameValueCollection Values()
collection.Add("idx", string.Join("|", Idx));
}

if (Details)
if (@params != null)
{
collection.Add("details", "1");
}

if (Params != null)
{
for (int i = 0; i < Params.Length; i++)
for (int i = 0; i < @params.Length; i++)
{
if (Params[i] != null)
if (@params[i] != null)
{
collection.Add("param" + (i + 1), Params[i]);
collection.Add("param" + (i + 1), @params[i]);
}
}
}

if (template != null)
{
collection.Add("template", template);
}

return collection;
}
}
Expand Down
2 changes: 1 addition & 1 deletion smsapi/smsapi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>SMSAPI.pl</PackageId>
<PackageVersion>2.0.0</PackageVersion>
<PackageVersion>2.1.0</PackageVersion>
<PackagerequireLicenseAcceptance>false</PackagerequireLicenseAcceptance>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://www.smsapi.com</PackageProjectUrl>
Expand Down

0 comments on commit 3ea55e4

Please sign in to comment.