Skip to content

Commit 059d9cb

Browse files
authored
Merge pull request #9 from gilmae/master
Added the Message structs for use in SendMessageRequest, SendMessagesReponse
2 parents cd879ec + 897997f commit 059d9cb

File tree

8 files changed

+162
-43
lines changed

8 files changed

+162
-43
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,6 @@ FakesAssemblies/
213213

214214
# Visual Studio 6 workspace options file
215215
*.opt
216+
217+
# Signing Keys
218+
*.snk
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
5+
namespace MessageMedia.Messages.Models
6+
{
7+
public struct Message
8+
{
9+
[JsonProperty("message_id")] public string MessageId { get; set; }
10+
11+
/// <summary>
12+
/// Urls of the media files to send in the Message
13+
///
14+
/// <remarks>Only valid if the Format is MMS</remarks>
15+
/// </summary>
16+
[JsonProperty("media")] public string[] Media { get; set; }
17+
18+
[JsonProperty("status")] public MessageStatus Status { get; set; }
19+
20+
/// <summary>
21+
/// Replies and delivery reports for this message will be pushed to the URL"
22+
/// </summary>
23+
[JsonProperty("callback_url")] public string CallbackUrl { get; set; }
24+
25+
/// <summary>
26+
/// Content of the message
27+
/// <example>Hello world!</example>
28+
/// </summary>
29+
[JsonProperty("content")] public string Content { get; set; }
30+
31+
/// <summary>
32+
/// Destination number of the message
33+
/// <example>+61491570156</example>
34+
/// </summary>
35+
[JsonProperty("destination_number")] public string DestinationNumber { get; set; }
36+
37+
/// <summary>
38+
/// Request a delivery report for this message
39+
/// </summary>
40+
[JsonProperty("delivery_report")] public bool DeliveryReport { get; set; }
41+
42+
/// <summary>
43+
/// Format of message, SMS or TTS (Text To Speech).
44+
/// </summary>
45+
[JsonProperty("format")] public MessageFormat Format { get; set; }
46+
47+
/// <summary>
48+
/// Date time after which the message expires and will not be sent
49+
/// </summary>
50+
[JsonProperty("message_expiry_timestamp")]
51+
public DateTime MessageExpiryTimestamp { get; set; }
52+
53+
/// <summary>
54+
/// Metadata for the message specified as a set of key value pairs.
55+
///
56+
/// <remarks>Each key can be up to 100 characters long and each value can be up to 256 characters long.</remarks>
57+
/// </summary>
58+
[JsonProperty("metadata")] public Dictionary<string, string> Metadata { get; set; }
59+
60+
/// <summary>
61+
/// Scheduled delivery date time of the message
62+
/// </summary>
63+
[JsonProperty("scheduled")] public DateTime Scheduled { get; set; }
64+
65+
/// <summary>
66+
/// Source of the message
67+
///
68+
/// <example>+61491570156</example>
69+
/// <example>Reminders</example>
70+
///
71+
/// <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>
72+
/// </summary>
73+
[JsonProperty("source_number")] public string SourceNumber { get; set; }
74+
75+
/// <summary>
76+
/// Type of source address specified
77+
/// </summary>
78+
[JsonProperty("source_number_type")] public NumberType SourceNumberType { get; set; }
79+
}
80+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace MessageMedia.Messages.Models
2+
{
3+
public enum MessageFormat
4+
{
5+
SMS,
6+
MMS,
7+
TTS
8+
}
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace MessageMedia.Messages.Models
2+
{
3+
public enum MessageStatus
4+
{
5+
enroute,
6+
submitted,
7+
delivered,
8+
expired,
9+
rejected,
10+
undeliverable,
11+
queued,
12+
processed,
13+
cancelled,
14+
scheduled,
15+
failed
16+
}
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace MessageMedia.Messages.Models
2+
{
3+
public enum NumberType
4+
{
5+
INTERNATIONAL,
6+
ALPHANUMERIC,
7+
SHORTCODE
8+
}
9+
}

MessageMedia.SDK.Messages/Models/SendMessagesRequest.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,29 @@
33
*
44
*/
55

6+
using System.Collections.Generic;
7+
using System.Security.Cryptography.X509Certificates;
68
using Newtonsoft.Json;
79

810
namespace MessageMedia.Messages.Models
911
{
10-
public class SendMessagesRequest : BaseModel
12+
public class SendMessagesRequest : BaseModel
1113
{
1214
// These fields hold the values for the public properties.
13-
private object messages;
15+
private IList<Message> messages;
1416

1517
/// <summary>
1618
/// TODO: Write general description for this method
1719
/// </summary>
1820
[JsonProperty("messages")]
19-
public object Messages
20-
{
21-
get
22-
{
23-
return this.messages;
24-
}
25-
set
21+
public IList<Message> Messages
22+
{
23+
get { return this.messages; }
24+
set
2625
{
2726
this.messages = value;
2827
onPropertyChanged("Messages");
2928
}
3029
}
3130
}
32-
}
31+
}

MessageMedia.SDK.Messages/Models/SendMessagesResponse.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ namespace MessageMedia.Messages.Models
1919
public class SendMessagesResponse : BaseModel
2020
{
2121
// These fields hold the values for the public properties.
22-
private object messages;
22+
private IList<Message> messages;
2323

2424
/// <summary>
2525
/// TODO: Write general description for this method
2626
/// </summary>
2727
[JsonProperty("messages")]
28-
public object Messages
28+
public IList<Message> Messages
2929
{
3030
get
3131
{

README.md

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -96,22 +96,20 @@ namespace TestCSharpSDK
9696
MessageMediaMessagesClient client = new MessageMediaMessagesClient(basicAuthUserName, basicAuthPassword, useHmacAuthentication);
9797
IMessagesController messages = client.Messages;
9898

99-
// Perform API call
100-
string bodyValue = @"{
101-
""messages"":[
102-
{
103-
""content"":""Greetings from MessageMedia!"",
104-
""destination_number"":""YOUR_MOBILE_NUMBER""
105-
}
106-
]
107-
}";
108-
109-
var body = Newtonsoft.Json.JsonConvert.DeserializeObject<SendMessagesRequest>(bodyValue);
110-
111-
SendMessagesResponse result = messages.CreateSendMessages(body);
112-
var json = JsonConvert.SerializeObject(result.Messages);
113-
var parse = JObject.Parse(json);
114-
Console.WriteLine(parse);
99+
var request = new SendMessagesRequest() {
100+
Messages = new []{
101+
new Message() {
102+
Content = "Greetings from MessageMedia!",
103+
DestinationNumber = "YOUR_MOBILE_NUMBER"
104+
}
105+
}
106+
}
107+
108+
109+
SendMessagesResponse result = messages.CreateSendMessages(request);
110+
Message message = result.Messages.First();
111+
112+
Console.WriteLine("Status: {0}, Message Id: {1}", message.Status, message.MessageId);
115113
Console.ReadKey();
116114
}
117115
}
@@ -142,21 +140,25 @@ namespace TestCSharpSDK
142140
IMessagesController messages = client.Messages;
143141

144142
// Perform API call
145-
string bodyValue = @"{
146-
""messages"":[
147-
{
148-
""content"":""Greetings from MessageMedia!"",
149-
""destination_number"":""YOUR_MOBILE_NUMBER"",
150-
""format"":""MMS"",
151-
""media"":[""https://upload.wikimedia.org/wikipedia/commons/6/6a/L80385-flash-superhero-logo-1544.png""]
152-
}
153-
]
154-
}";
155-
156-
var body = Newtonsoft.Json.JsonConvert.DeserializeObject<MessageMedia.Messages.Models.SendMessagesRequest>(bodyValue);
157-
158-
MessageMedia.Messages.Models.SendMessagesResponse result = messages.CreateSendMessages(body);
159-
Console.WriteLine(result.Messages);
143+
var request = new SendMessagesRequest()
144+
{
145+
Messages = new[]
146+
{
147+
new Message()
148+
{
149+
Format = MessageFormat.MMS,
150+
Content = "Greets from MessageMedia!",
151+
DestinationNumber = "YOUR_MOBILE_NUMBER",
152+
Media = new[]
153+
{"https://upload.wikimedia.org/wikipedia/commons/6/6a/L80385-flash-superhero-logo-1544.png"}
154+
155+
}
156+
}
157+
};
158+
159+
Message message = result.Messages.First();
160+
161+
Console.WriteLine("Status: {0}, Message Id: {1}", message.Status, message.MessageId);
160162
Console.ReadKey();
161163
}
162164
}

0 commit comments

Comments
 (0)