From e6d482f13e181648655c26840f4847cef114284f Mon Sep 17 00:00:00 2001 From: Maxwell Weru Date: Wed, 23 Jun 2021 12:32:02 +0300 Subject: [PATCH] API updates (#25) * 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 --- src/ThingsMobile/ThingsMobileClient.cs | 136 ++++++++++++++++--------- 1 file changed, 88 insertions(+), 48 deletions(-) diff --git a/src/ThingsMobile/ThingsMobileClient.cs b/src/ThingsMobile/ThingsMobileClient.cs index 5c3d233..fdbd83d 100644 --- a/src/ThingsMobile/ThingsMobileClient.cs +++ b/src/ThingsMobile/ThingsMobileClient.cs @@ -71,19 +71,43 @@ public async Task> ActivateSimCardAsync( /// /// Block a sim card /// - /// MSISDN of the sim card + /// MSISDN for the SIM card + /// ICCID for the SIM card /// The token for cancelling the task /// - public async Task> BlockSimCardAsync(string msisdn, CancellationToken cancellationToken = default) + public async Task> BlockSimCardAsync(string? msisdn = null, + string? iccid = null, + CancellationToken cancellationToken = default) { - var parameters = new Dictionary - { - ["msisdn"] = msisdn, - }; + var parameters = new Dictionary(); + + 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("/services/business-api/blockSim", parameters, cancellationToken); } + /// + /// Disconnect a sim card + /// + /// MSISDN for the SIM card + /// ICCID for the SIM card + /// The token for cancelling the task + /// + public async Task> DisconnectSimCardAsync(string? msisdn = null, + string? iccid = null, + CancellationToken cancellationToken = default) + { + var parameters = new Dictionary(); + + 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("/services/business-api/disconnectSim", parameters, cancellationToken); + } + /// /// Modify an existing sim plan /// @@ -207,23 +231,28 @@ public async Task> GetSimPlansAsync(Canc /// /// Sets an expiry date for a sim card /// + /// Whether to block the sim card after expiry /// MSISDN for the SIM card + /// ICCID for the SIM card /// Date which the sim card expires. Format (yyyy-MM-dd) - /// Whether to block the sim card after expiry /// The token for cancelling the task /// - public async Task> SetSimExpiryDateAsync(string msisdn, - string expiryDateString, + public async Task> SetSimExpiryDateAsync(string expiryDateString, bool blockSimAfterExpiry, + string? msisdn = null, + string? iccid = null, CancellationToken cancellationToken = default) { var parameters = new Dictionary { - ["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("/services/business-api/setupSimExpirationDate", parameters, cancellationToken); } @@ -253,16 +282,19 @@ public async Task> SetSimThresholdsAsync /// /// Unblock a sim card /// - /// MSISDN of the sim card + /// MSISDN for the SIM card + /// ICCID for the SIM card /// The token for cancelling the task /// - public async Task> UnblockSimCardAsync(string msisdn, + public async Task> UnblockSimCardAsync(string? msisdn = null, + string? iccid = null, CancellationToken cancellationToken = default) { - var parameters = new Dictionary - { - ["msisdn"] = msisdn, - }; + var parameters = new Dictionary(); + + 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("/services/business-api/unblockSim", parameters, cancellationToken); } @@ -270,19 +302,21 @@ public async Task> UnblockSimCardAsync(s /// /// Updates the name of the sim /// - /// MSISDN for the sim card /// Name of the sim card + /// MSISDN for the SIM card + /// ICCID for the SIM card /// The token for cancelling the task /// - public async Task> UpdateSimNameAsync(string msisdn, - string name, + public async Task> UpdateSimNameAsync(string name, + string? msisdn = null, + string? iccid = null, CancellationToken cancellationToken = default) { - var parameters = new Dictionary - { - ["msisdn"] = msisdn, - ["name"] = name - }; + var parameters = new Dictionary { ["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("/services/business-api/updateSimName", parameters, cancellationToken); } @@ -290,19 +324,21 @@ public async Task> UpdateSimNameAsync(st /// /// Send an SMS to an active Things Mobile SIM /// - /// MSISDN for the sim card /// sms message (160 characters maximum) + /// MSISDN for the SIM card + /// ICCID for the SIM card /// The token for cancelling the task /// - public async Task> SendSmsToSimAsync(string msisdn, - string message, + public async Task> SendSmsToSimAsync(string message, + string? msisdn = null, + string? iccid = null, CancellationToken cancellationToken = default) { - var parameters = new Dictionary - { - ["msisdn"] = msisdn, - ["message"] = message - }; + var parameters = new Dictionary { ["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("/services/business-api/sendSms", parameters, cancellationToken); } @@ -310,19 +346,21 @@ public async Task> SendSmsToSimAsync(str /// /// Associates a custom sim plan to specified sim card /// - /// MSISDN for the sim card /// Unique identifier for the sim plan + /// MSISDN for the sim card + /// ICCID for the SIM card /// The token for cancelling the task /// - public async Task> ChangeSimPlanAsync(string msisdn, - string customPlanId, + public async Task> ChangeSimPlanAsync(string customPlanId, + string? msisdn = null, + string? iccid = null, CancellationToken cancellationToken = default) { - var parameters = new Dictionary - { - ["msisdn"] = msisdn, - ["customPlanId"] = customPlanId - }; + var parameters = new Dictionary { ["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("/services/business-api/changeSimPlan", parameters, cancellationToken); } @@ -330,19 +368,21 @@ public async Task> ChangeSimPlanAsync(st /// /// Updates the sim tag /// - /// MSISDN for the SIM card /// Tag for the SIM card + /// MSISDN for the SIM card + /// ICCID for the SIM card /// The token for cancelling the task /// - public async Task> UpdateSimTagAsync(string msisdn, - string tag, + public async Task> UpdateSimTagAsync(string tag, + string? msisdn = null, + string? iccid = null, CancellationToken cancellationToken = default) { - var parameters = new Dictionary - { - ["msisdn"] = msisdn, - ["tag"] = tag - }; + var parameters = new Dictionary { ["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("/services/business-api/updateSimTag", parameters, cancellationToken); }