Skip to content

Commit

Permalink
API updates (#25)
Browse files Browse the repository at this point in the history
* Support for disconnectSim endpoint

* setupSimExpirationDate accepts either msisdn and iccid

* blockSimaccepts either msisdn and iccid

* unblockSim accepts either msisdn and iccid

* updateSimName accepts either msisdn and iccid

* sendSms accepts either msisdn and iccid

* changeSimPlan accepts either msisdn and iccid

* updateSimTag accepts either msisdn and iccid
  • Loading branch information
mburumaxwell authored Jun 23, 2021
1 parent b7253c5 commit e6d482f
Showing 1 changed file with 88 additions and 48 deletions.
136 changes: 88 additions & 48 deletions src/ThingsMobile/ThingsMobileClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,43 @@ public async Task<ThingsMobileResponse<BaseResponseModel>> ActivateSimCardAsync(
/// <summary>
/// Block a sim card
/// </summary>
/// <param name="msisdn">MSISDN of the sim card</param>
/// <param name="msisdn">MSISDN for the SIM card</param>
/// <param name="iccid">ICCID for the SIM card</param>
/// <param name="cancellationToken">The token for cancelling the task</param>
/// <returns></returns>
public async Task<ThingsMobileResponse<BaseResponseModel>> BlockSimCardAsync(string msisdn, CancellationToken cancellationToken = default)
public async Task<ThingsMobileResponse<BaseResponseModel>> BlockSimCardAsync(string? msisdn = null,
string? iccid = null,
CancellationToken cancellationToken = default)
{
var parameters = new Dictionary<string, string?>
{
["msisdn"] = msisdn,
};
var parameters = new Dictionary<string, string?>();

if (!string.IsNullOrWhiteSpace(msisdn)) parameters["msisdn"] = msisdn;
else if (!string.IsNullOrWhiteSpace(iccid)) parameters["iccid"] = iccid;
else throw new InvalidOperationException($"Either '{nameof(msisdn)}' or '{nameof(iccid)}' is required.");

return await PostAsync<BaseResponseModel>("/services/business-api/blockSim", parameters, cancellationToken);
}

/// <summary>
/// Disconnect a sim card
/// </summary>
/// <param name="msisdn">MSISDN for the SIM card</param>
/// <param name="iccid">ICCID for the SIM card</param>
/// <param name="cancellationToken">The token for cancelling the task</param>
/// <returns></returns>
public async Task<ThingsMobileResponse<BaseResponseModel>> DisconnectSimCardAsync(string? msisdn = null,
string? iccid = null,
CancellationToken cancellationToken = default)
{
var parameters = new Dictionary<string, string?>();

if (!string.IsNullOrWhiteSpace(msisdn)) parameters["msisdn"] = msisdn;
else if (!string.IsNullOrWhiteSpace(iccid)) parameters["iccid"] = iccid;
else throw new InvalidOperationException($"Either '{nameof(msisdn)}' or '{nameof(iccid)}' is required.");

return await PostAsync<BaseResponseModel>("/services/business-api/disconnectSim", parameters, cancellationToken);
}

/// <summary>
/// Modify an existing sim plan
/// </summary>
Expand Down Expand Up @@ -207,23 +231,28 @@ public async Task<ThingsMobileResponse<SimPlanCollection>> GetSimPlansAsync(Canc
/// <summary>
/// Sets an expiry date for a sim card
/// </summary>
/// <param name="blockSimAfterExpiry">Whether to block the sim card after expiry</param>
/// <param name="msisdn">MSISDN for the SIM card</param>
/// <param name="iccid">ICCID for the SIM card</param>
/// <param name="expiryDateString">Date which the sim card expires. Format (yyyy-MM-dd)</param>
/// <param name="blockSimAfterExpiry">Whether to block the sim card after expiry</param>
/// <param name="cancellationToken">The token for cancelling the task</param>
/// <returns></returns>
public async Task<ThingsMobileResponse<BaseResponseModel>> SetSimExpiryDateAsync(string msisdn,
string expiryDateString,
public async Task<ThingsMobileResponse<BaseResponseModel>> SetSimExpiryDateAsync(string expiryDateString,
bool blockSimAfterExpiry,
string? msisdn = null,
string? iccid = null,
CancellationToken cancellationToken = default)
{
var parameters = new Dictionary<string, string?>
{
["msisdn"] = msisdn,
["expirationDate"] = expiryDateString,
["blockSim"] = blockSimAfterExpiry ? "1" : "0"
};

if (!string.IsNullOrWhiteSpace(msisdn)) parameters["msisdn"] = msisdn;
else if (!string.IsNullOrWhiteSpace(iccid)) parameters["iccid"] = iccid;
else throw new InvalidOperationException($"Either '{nameof(msisdn)}' or '{nameof(iccid)}' is required.");

return await PostAsync<BaseResponseModel>("/services/business-api/setupSimExpirationDate", parameters, cancellationToken);
}

Expand Down Expand Up @@ -253,96 +282,107 @@ public async Task<ThingsMobileResponse<BaseResponseModel>> SetSimThresholdsAsync
/// <summary>
/// Unblock a sim card
/// </summary>
/// <param name="msisdn">MSISDN of the sim card</param>
/// <param name="msisdn">MSISDN for the SIM card</param>
/// <param name="iccid">ICCID for the SIM card</param>
/// <param name="cancellationToken">The token for cancelling the task</param>
/// <returns></returns>
public async Task<ThingsMobileResponse<BaseResponseModel>> UnblockSimCardAsync(string msisdn,
public async Task<ThingsMobileResponse<BaseResponseModel>> UnblockSimCardAsync(string? msisdn = null,
string? iccid = null,
CancellationToken cancellationToken = default)
{
var parameters = new Dictionary<string, string?>
{
["msisdn"] = msisdn,
};
var parameters = new Dictionary<string, string?>();

if (!string.IsNullOrWhiteSpace(msisdn)) parameters["msisdn"] = msisdn;
else if (!string.IsNullOrWhiteSpace(iccid)) parameters["iccid"] = iccid;
else throw new InvalidOperationException($"Either '{nameof(msisdn)}' or '{nameof(iccid)}' is required.");

return await PostAsync<BaseResponseModel>("/services/business-api/unblockSim", parameters, cancellationToken);
}

/// <summary>
/// Updates the name of the sim
/// </summary>
/// <param name="msisdn">MSISDN for the sim card</param>
/// <param name="name">Name of the sim card</param>
/// <param name="msisdn">MSISDN for the SIM card</param>
/// <param name="iccid">ICCID for the SIM card</param>
/// <param name="cancellationToken">The token for cancelling the task</param>
/// <returns></returns>
public async Task<ThingsMobileResponse<BaseResponseModel>> UpdateSimNameAsync(string msisdn,
string name,
public async Task<ThingsMobileResponse<BaseResponseModel>> UpdateSimNameAsync(string name,
string? msisdn = null,
string? iccid = null,
CancellationToken cancellationToken = default)
{
var parameters = new Dictionary<string, string?>
{
["msisdn"] = msisdn,
["name"] = name
};
var parameters = new Dictionary<string, string?> { ["name"] = name, };

if (!string.IsNullOrWhiteSpace(msisdn)) parameters["msisdn"] = msisdn;
else if (!string.IsNullOrWhiteSpace(iccid)) parameters["iccid"] = iccid;
else throw new InvalidOperationException($"Either '{nameof(msisdn)}' or '{nameof(iccid)}' is required.");

return await PostAsync<BaseResponseModel>("/services/business-api/updateSimName", parameters, cancellationToken);
}

/// <summary>
/// Send an SMS to an active Things Mobile SIM
/// </summary>
/// <param name="msisdn">MSISDN for the sim card</param>
/// <param name="message">sms message (160 characters maximum)</param>
/// <param name="msisdn">MSISDN for the SIM card</param>
/// <param name="iccid">ICCID for the SIM card</param>
/// <param name="cancellationToken">The token for cancelling the task</param>
/// <returns></returns>
public async Task<ThingsMobileResponse<BaseResponseModel>> SendSmsToSimAsync(string msisdn,
string message,
public async Task<ThingsMobileResponse<BaseResponseModel>> SendSmsToSimAsync(string message,
string? msisdn = null,
string? iccid = null,
CancellationToken cancellationToken = default)
{
var parameters = new Dictionary<string, string?>
{
["msisdn"] = msisdn,
["message"] = message
};
var parameters = new Dictionary<string, string?> { ["message"] = message, };

if (!string.IsNullOrWhiteSpace(msisdn)) parameters["msisdn"] = msisdn;
else if (!string.IsNullOrWhiteSpace(iccid)) parameters["iccid"] = iccid;
else throw new InvalidOperationException($"Either '{nameof(msisdn)}' or '{nameof(iccid)}' is required.");

return await PostAsync<BaseResponseModel>("/services/business-api/sendSms", parameters, cancellationToken);
}

/// <summary>
/// Associates a custom sim plan to specified sim card
/// </summary>
/// <param name="msisdn">MSISDN for the sim card</param>
/// <param name="customPlanId">Unique identifier for the sim plan</param>
/// <param name="msisdn">MSISDN for the sim card</param>
/// <param name="iccid">ICCID for the SIM card</param>
/// <param name="cancellationToken">The token for cancelling the task</param>
/// <returns></returns>
public async Task<ThingsMobileResponse<BaseResponseModel>> ChangeSimPlanAsync(string msisdn,
string customPlanId,
public async Task<ThingsMobileResponse<BaseResponseModel>> ChangeSimPlanAsync(string customPlanId,
string? msisdn = null,
string? iccid = null,
CancellationToken cancellationToken = default)
{
var parameters = new Dictionary<string, string?>
{
["msisdn"] = msisdn,
["customPlanId"] = customPlanId
};
var parameters = new Dictionary<string, string?> { ["customPlanId"] = customPlanId, };

if (!string.IsNullOrWhiteSpace(msisdn)) parameters["msisdn"] = msisdn;
else if (!string.IsNullOrWhiteSpace(iccid)) parameters["iccid"] = iccid;
else throw new InvalidOperationException($"Either '{nameof(msisdn)}' or '{nameof(iccid)}' is required.");

return await PostAsync<BaseResponseModel>("/services/business-api/changeSimPlan", parameters, cancellationToken);
}

/// <summary>
/// Updates the sim tag
/// </summary>
/// <param name="msisdn">MSISDN for the SIM card</param>
/// <param name="tag">Tag for the SIM card</param>
/// <param name="msisdn">MSISDN for the SIM card</param>
/// <param name="iccid">ICCID for the SIM card</param>
/// <param name="cancellationToken">The token for cancelling the task</param>
/// <returns></returns>
public async Task<ThingsMobileResponse<BaseResponseModel>> UpdateSimTagAsync(string msisdn,
string tag,
public async Task<ThingsMobileResponse<BaseResponseModel>> UpdateSimTagAsync(string tag,
string? msisdn = null,
string? iccid = null,
CancellationToken cancellationToken = default)
{
var parameters = new Dictionary<string, string?>
{
["msisdn"] = msisdn,
["tag"] = tag
};
var parameters = new Dictionary<string, string?> { ["tag"] = tag, };

if (!string.IsNullOrWhiteSpace(msisdn)) parameters["msisdn"] = msisdn;
else if (!string.IsNullOrWhiteSpace(iccid)) parameters["iccid"] = iccid;
else throw new InvalidOperationException($"Either '{nameof(msisdn)}' or '{nameof(iccid)}' is required.");

return await PostAsync<BaseResponseModel>("/services/business-api/updateSimTag", parameters, cancellationToken);
}
Expand Down

0 comments on commit e6d482f

Please sign in to comment.