Skip to content

Commit

Permalink
Merge pull request #9 from gilmae/master
Browse files Browse the repository at this point in the history
Added the Message structs for use in SendMessageRequest, SendMessagesReponse
  • Loading branch information
IbrahimTareq authored Sep 10, 2018
2 parents cd879ec + 897997f commit 059d9cb
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,6 @@ FakesAssemblies/

# Visual Studio 6 workspace options file
*.opt

# Signing Keys
*.snk
80 changes: 80 additions & 0 deletions MessageMedia.SDK.Messages/Models/Message.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace MessageMedia.Messages.Models
{
public struct Message
{
[JsonProperty("message_id")] public string MessageId { get; set; }

/// <summary>
/// Urls of the media files to send in the Message
///
/// <remarks>Only valid if the Format is MMS</remarks>
/// </summary>
[JsonProperty("media")] public string[] Media { get; set; }

[JsonProperty("status")] public MessageStatus Status { get; set; }

/// <summary>
/// Replies and delivery reports for this message will be pushed to the URL"
/// </summary>
[JsonProperty("callback_url")] public string CallbackUrl { get; set; }

/// <summary>
/// Content of the message
/// <example>Hello world!</example>
/// </summary>
[JsonProperty("content")] public string Content { get; set; }

/// <summary>
/// Destination number of the message
/// <example>+61491570156</example>
/// </summary>
[JsonProperty("destination_number")] public string DestinationNumber { get; set; }

/// <summary>
/// Request a delivery report for this message
/// </summary>
[JsonProperty("delivery_report")] public bool DeliveryReport { get; set; }

/// <summary>
/// Format of message, SMS or TTS (Text To Speech).
/// </summary>
[JsonProperty("format")] public MessageFormat Format { get; set; }

/// <summary>
/// Date time after which the message expires and will not be sent
/// </summary>
[JsonProperty("message_expiry_timestamp")]
public DateTime MessageExpiryTimestamp { get; set; }

/// <summary>
/// Metadata for the message specified as a set of key value pairs.
///
/// <remarks>Each key can be up to 100 characters long and each value can be up to 256 characters long.</remarks>
/// </summary>
[JsonProperty("metadata")] public Dictionary<string, string> Metadata { get; set; }

/// <summary>
/// Scheduled delivery date time of the message
/// </summary>
[JsonProperty("scheduled")] public DateTime Scheduled { get; set; }

/// <summary>
/// Source of the message
///
/// <example>+61491570156</example>
/// <example>Reminders</example>
///
/// <remarks>By default this feature is not available and will be ignored in the request. Please contact [email protected] for more information. Specifying a source number is optional and a by default a source number will be assigned to the message.</remarks>
/// </summary>
[JsonProperty("source_number")] public string SourceNumber { get; set; }

/// <summary>
/// Type of source address specified
/// </summary>
[JsonProperty("source_number_type")] public NumberType SourceNumberType { get; set; }
}
}
9 changes: 9 additions & 0 deletions MessageMedia.SDK.Messages/Models/MessageFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MessageMedia.Messages.Models
{
public enum MessageFormat
{
SMS,
MMS,
TTS
}
}
17 changes: 17 additions & 0 deletions MessageMedia.SDK.Messages/Models/MessageStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace MessageMedia.Messages.Models
{
public enum MessageStatus
{
enroute,
submitted,
delivered,
expired,
rejected,
undeliverable,
queued,
processed,
cancelled,
scheduled,
failed
}
}
9 changes: 9 additions & 0 deletions MessageMedia.SDK.Messages/Models/NumberType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace MessageMedia.Messages.Models
{
public enum NumberType
{
INTERNATIONAL,
ALPHANUMERIC,
SHORTCODE
}
}
19 changes: 9 additions & 10 deletions MessageMedia.SDK.Messages/Models/SendMessagesRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,29 @@
*
*/

using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using Newtonsoft.Json;

namespace MessageMedia.Messages.Models
{
public class SendMessagesRequest : BaseModel
public class SendMessagesRequest : BaseModel
{
// These fields hold the values for the public properties.
private object messages;
private IList<Message> messages;

/// <summary>
/// TODO: Write general description for this method
/// </summary>
[JsonProperty("messages")]
public object Messages
{
get
{
return this.messages;
}
set
public IList<Message> Messages
{
get { return this.messages; }
set
{
this.messages = value;
onPropertyChanged("Messages");
}
}
}
}
}
4 changes: 2 additions & 2 deletions MessageMedia.SDK.Messages/Models/SendMessagesResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ namespace MessageMedia.Messages.Models
public class SendMessagesResponse : BaseModel
{
// These fields hold the values for the public properties.
private object messages;
private IList<Message> messages;

/// <summary>
/// TODO: Write general description for this method
/// </summary>
[JsonProperty("messages")]
public object Messages
public IList<Message> Messages
{
get
{
Expand Down
64 changes: 33 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,20 @@ namespace TestCSharpSDK
MessageMediaMessagesClient client = new MessageMediaMessagesClient(basicAuthUserName, basicAuthPassword, useHmacAuthentication);
IMessagesController messages = client.Messages;

// Perform API call
string bodyValue = @"{
""messages"":[
{
""content"":""Greetings from MessageMedia!"",
""destination_number"":""YOUR_MOBILE_NUMBER""
}
]
}";

var body = Newtonsoft.Json.JsonConvert.DeserializeObject<SendMessagesRequest>(bodyValue);

SendMessagesResponse result = messages.CreateSendMessages(body);
var json = JsonConvert.SerializeObject(result.Messages);
var parse = JObject.Parse(json);
Console.WriteLine(parse);
var request = new SendMessagesRequest() {
Messages = new []{
new Message() {
Content = "Greetings from MessageMedia!",
DestinationNumber = "YOUR_MOBILE_NUMBER"
}
}
}


SendMessagesResponse result = messages.CreateSendMessages(request);
Message message = result.Messages.First();

Console.WriteLine("Status: {0}, Message Id: {1}", message.Status, message.MessageId);
Console.ReadKey();
}
}
Expand Down Expand Up @@ -142,21 +140,25 @@ namespace TestCSharpSDK
IMessagesController messages = client.Messages;

// Perform API call
string bodyValue = @"{
""messages"":[
{
""content"":""Greetings from MessageMedia!"",
""destination_number"":""YOUR_MOBILE_NUMBER"",
""format"":""MMS"",
""media"":[""https://upload.wikimedia.org/wikipedia/commons/6/6a/L80385-flash-superhero-logo-1544.png""]
}
]
}";

var body = Newtonsoft.Json.JsonConvert.DeserializeObject<MessageMedia.Messages.Models.SendMessagesRequest>(bodyValue);

MessageMedia.Messages.Models.SendMessagesResponse result = messages.CreateSendMessages(body);
Console.WriteLine(result.Messages);
var request = new SendMessagesRequest()
{
Messages = new[]
{
new Message()
{
Format = MessageFormat.MMS,
Content = "Greets from MessageMedia!",
DestinationNumber = "YOUR_MOBILE_NUMBER",
Media = new[]
{"https://upload.wikimedia.org/wikipedia/commons/6/6a/L80385-flash-superhero-logo-1544.png"}

}
}
};

Message message = result.Messages.First();

Console.WriteLine("Status: {0}, Message Id: {1}", message.Status, message.MessageId);
Console.ReadKey();
}
}
Expand Down

0 comments on commit 059d9cb

Please sign in to comment.