Skip to content

Commit

Permalink
Merge pull request #76 from Faultless/feat-list-voice-messages-method
Browse files Browse the repository at this point in the history
List voice messages method
  • Loading branch information
marcel corso gonzalez committed Feb 11, 2020
2 parents 29f9c36 + 0b7da48 commit c6e2199
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 0 deletions.
44 changes: 44 additions & 0 deletions Examples/VoiceMessage/ListVoiceMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using MessageBird;
using MessageBird.Exceptions;
using MessageBird.Net.ProxyConfigurationInjector;
using MessageBird.Objects;

namespace Examples.VoiceMessage
{
class ListVoiceMessages
{
const string YourAccessKey = "YOUR_ACCESS_KEY"; // your access key here.

static void Main(string[] args)
{
IProxyConfigurationInjector proxyConfigurationInjector = null; // for no web proxies, or web proxies not requiring authentication

Client client = Client.CreateDefault(YourAccessKey, proxyConfigurationInjector);

try
{
MessageBird.Objects.VoiceMessageList voiceMessageList = client.ListVoiceMessages();
Console.WriteLine("{0}", voiceMessageList);
}
catch (ErrorException e)
{
// Either the request fails with error descriptions from the endpoint.
if (e.HasErrors)
{
foreach (Error error in e.Errors)
{
Console.WriteLine("code: {0} description: '{1}' parameter: '{2}'", error.Code, error.Description, error.Parameter);
}
}
// or fails without error information from the endpoint, in which case the reason contains a 'best effort' description.
if (e.HasReason)
{
Console.WriteLine(e.Reason);
}
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
}
16 changes: 16 additions & 0 deletions MessageBird/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,22 @@ public VoiceMessage ViewVoiceMessage(string id)
return result.Object as VoiceMessage;
}

/// <summary>
/// This request retrieves a listing of all voice messages from the account.
/// If successful, this request returns an object with a data property, which is an array that has 0 or more voice message objects.
/// </summary>
/// <param name="limit">Set how many records will return from the server</param>
/// <param name="offset">Identify the starting point to return rows from a result</param>
/// <returns>If successful, this request will return an object with a data, _links and pagination properties.</returns>
public VoiceMessageList ListVoiceMessages(int limit = 20, int offset = 0)
{
var voiceMessageLists = new VoiceMessageLists();
var voiceMessageList = new VoiceMessageLists(new VoiceMessageList { Limit = limit, Offset = offset });

restClient.Retrieve(voiceMessageList);
return voiceMessageList.Object as VoiceMessageList;
}

#endregion

#region Verify API
Expand Down
4 changes: 4 additions & 0 deletions MessageBird/Objects/VoiceMessageList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace MessageBird.Objects
{
public class VoiceMessageList : BaseList<VoiceMessage> { }
}
28 changes: 28 additions & 0 deletions MessageBird/Resources/VoiceMessageList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Text;

namespace MessageBird.Resources
{
public class VoiceMessageLists : BaseLists<Objects.VoiceMessage>
{
public VoiceMessageLists() : base("voicemessages", new Objects.VoiceMessageList()) { }

public VoiceMessageLists(Objects.VoiceMessageList voiceMessageList) : base("voicemessages", voiceMessageList) { }

public override string QueryString
{
get
{
var baseList = (Objects.VoiceMessageList)Object;

var builder = new StringBuilder();

if (!string.IsNullOrEmpty(base.QueryString))
{
builder.AppendFormat("{0}", base.QueryString);
}

return builder.ToString();
}
}
}
}
17 changes: 17 additions & 0 deletions Tests/UnitTests/MessageBirdUnitTests/Resources/VoiceMessageTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;

using MessageBird;
using MessageBird.Objects;
using MessageBird.Resources;
using Newtonsoft.Json;
Expand All @@ -9,6 +10,22 @@ namespace MessageBirdUnitTests.Resources
[TestClass]
public class VoiceMessageTest
{
[TestMethod]
public void ListVoiceMessages()
{
var restClient = MockRestClient
.ThatReturns(filename: "ListVoiceMessages.json")
.FromEndpoint("GET", "voicemessages?limit=20&offset=0")
.Get();
var client = Client.Create(restClient.Object);

var voicemessages = client.ListVoiceMessages();
restClient.Verify();

Assert.AreEqual(2, voicemessages.Items.Count);
Assert.AreEqual(2, voicemessages.Count);
Assert.AreEqual("12345678-9012-3456-7890-123456789012", voicemessages.Items[0].Id);
}
[TestMethod]
public void DeserializeAndSerialize()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"offset": 0,
"limit": 10,
"count": 2,
"totalCount": 2,
"links": {
"first": "https://rest.messagebird.com/voicemessages/?offset=0&limit=30",
"previous": null,
"next": null,
"last": "https://rest.messagebird.com/voicemessages/?offset=0&limit=30"
},
"items": [
{
"id": "12345678-9012-3456-7890-123456789012",
"href": "https://rest.messagebird.com/voicemessages/12345678-9012-3456-7890-123456789012",
"originator": null,
"body": "This is a test message.",
"reference": null,
"language": "en-gb",
"voice": "male",
"repeat": 1,
"ifMachine": "continue",
"machineTimeout": 7000,
"scheduledDatetime": null,
"createdDatetime": "2020-02-04T15:15:30+00:00",
"recipients": {
"totalCount": 1,
"totalSentCount": 1,
"totalDeliveredCount": 1,
"totalDeliveryFailedCount": 0,
"items": [
{
"recipient": 31612345678,
"originator": null,
"status": "answered",
"statusDatetime": "2020-02-04T15:15:57+00:00"
}
]
}
},
{
"id": "12345678-9012-3456-7890-123456789013",
"href": "https://rest.messagebird.com/voicemessages/12345678-9012-3456-7890-123456789013",
"originator": null,
"body": "The voice message to be sent",
"reference": null,
"language": "en-gb",
"voice": "female",
"repeat": 1,
"ifMachine": "delay",
"machineTimeout": 7000,
"scheduledDatetime": null,
"createdDatetime": "2020-02-04T12:26:44+00:00",
"recipients": {
"totalCount": 1,
"totalSentCount": 1,
"totalDeliveredCount": 1,
"totalDeliveryFailedCount": 0,
"items": [
{
"recipient": 31612345678,
"originator": null,
"status": "answered",
"statusDatetime": "2020-02-04T12:27:32+00:00"
}
]
}
}
]
}

0 comments on commit c6e2199

Please sign in to comment.