-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from Faultless/feat-list-voice-messages-method
List voice messages method
- Loading branch information
Showing
6 changed files
with
179 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace MessageBird.Objects | ||
{ | ||
public class VoiceMessageList : BaseList<VoiceMessage> { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
Tests/UnitTests/MessageBirdUnitTests/Responses/ListVoiceMessages.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |