Skip to content

Commit

Permalink
Merged changes from repo
Browse files Browse the repository at this point in the history
  • Loading branch information
timheuer committed Dec 30, 2016
2 parents 43d7f14 + ae95467 commit 849766f
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 94 deletions.
39 changes: 0 additions & 39 deletions Alexa.NET/Request/RequestBundle.cs

This file was deleted.

8 changes: 5 additions & 3 deletions Alexa.NET/Request/SkillRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using Alexa.NET.Request.Type;
using Newtonsoft.Json;

namespace Alexa.NET.Request
{
Expand All @@ -11,11 +12,12 @@ public class SkillRequest
public Session Session { get; set; }

[JsonProperty("request")]
public RequestBundle Request { get; set; }
[JsonConverter(typeof(RequestConverter))]
public Type.Request Request { get; set; }

public System.Type GetRequestType()
{
return Request?.GetRequestType();
return Request?.GetType();
}
}
}
26 changes: 26 additions & 0 deletions Alexa.NET/Request/Type/AudioPlayerRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Alexa.NET.Request.Type
{
public class AudioPlayerRequest: Request
{
[JsonProperty("token")]
public string Token { get; set; }

[JsonProperty("locale")]
public string Locale { get; set; }

[JsonProperty("offsetInMilliseconds")]
public string OffsetInMilliseconds { get; set; }

[JsonProperty("error")]
public Error Error { get; set; }

[JsonProperty("currentPlaybackState")]
public PlaybackState CurrentPlaybackState { get; set; }
}
}
17 changes: 17 additions & 0 deletions Alexa.NET/Request/Type/Error.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Alexa.NET.Request.Type
{
public class Error
{
[JsonProperty("type")]
public string Type { get; set; }

[JsonProperty("message")]
public string Message { get; set; }
}
}
7 changes: 0 additions & 7 deletions Alexa.NET/Request/Type/IIntentRequest.cs

This file was deleted.

7 changes: 7 additions & 0 deletions Alexa.NET/Request/Type/IntentRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Alexa.NET.Request.Type
{
public class IntentRequest : Request
{
public Intent Intent { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Alexa.NET.Request.Type
{
public interface ILaunchRequest : IRequest
public class LaunchRequest : Request
{
}
}
20 changes: 20 additions & 0 deletions Alexa.NET/Request/Type/PlaybackState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Alexa.NET.Request.Type
{
public class PlaybackState
{
[JsonProperty("token")]
public string Token { get; set; }

[JsonProperty("offsetInMilliseconds")]
public string OffsetInMilliseconds { get; set; }

[JsonProperty("playerActivity")]
public string PlayerActivity { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

namespace Alexa.NET.Request.Type
{
public interface IRequest
public abstract class Request
{
[JsonProperty("type")]
string Type { get; set; }
public string Type { get; set; }

[JsonProperty("requestId")]
string RequestId { get; set; }
public string RequestId { get; set; }

[JsonProperty("timestamp")]
DateTime Timestamp { get; set; }
public DateTime Timestamp { get; set; }
}
}
38 changes: 0 additions & 38 deletions Alexa.NET/Request/Type/RequestBundle.cs

This file was deleted.

56 changes: 56 additions & 0 deletions Alexa.NET/Request/Type/RequestConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;

namespace Alexa.NET.Request.Type
{
public class RequestConverter : JsonConverter
{
public override bool CanWrite => false;

public override bool CanConvert(System.Type objectType)
{
return objectType == typeof(Request);
}

public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();
}

public override object ReadJson(JsonReader reader, System.Type objectType, object existingValue, JsonSerializer serializer)
{
// Load JObject from stream
var jObject = JObject.Load(reader);

// Create target request object based on "type" property
var target = Create(jObject["type"].Value<string>());

// Populate the object properties
serializer.Populate(jObject.CreateReader(), target);

return target;
}

public Request Create(string requestType)
{
//AudioPlayer requests are very similar, map to single type
if (requestType.StartsWith("AudioPlayer"))
requestType = "AudioPlayer";

switch (requestType)
{
case "IntentRequest":
return new IntentRequest();
case "LaunchRequest":
return new LaunchRequest();
case "SessionEndedRequest":
return new SessionEndedRequest();
case "AudioPlayer":
return new AudioPlayerRequest();
default:
throw new ArgumentOutOfRangeException(nameof(Type), $"Unknown request type: {requestType}.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Alexa.NET.Request.Type
{
public interface ISessionEndedRequest : IRequest
public class SessionEndedRequest : Request
{
[JsonProperty("reason")]
string Reason { get; set; }
public string Reason { get; set; }
}
}
11 changes: 11 additions & 0 deletions Alexa.NET/Response/Directive/AudioItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Newtonsoft.Json;

namespace Alexa.NET.Response.Directive
{
public class AudioItem
{
[JsonRequired]
[JsonProperty("stream")]
public AudioItemStream Stream { get; set; }
}
}
22 changes: 22 additions & 0 deletions Alexa.NET/Response/Directive/AudioItemStream.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Newtonsoft.Json;

namespace Alexa.NET.Response.Directive
{
public class AudioItemStream
{
[JsonRequired]
[JsonProperty("url")]
public string Url { get; set; }

[JsonRequired]
[JsonProperty("token")]
public string Token { get; set; }

[JsonProperty("expectedPreviousToken")]
public string ExpectedPreviousToken { get; set; }

[JsonRequired]
[JsonProperty("offsetInMilliseconds")]
public int OffsetInMilliseconds { get; set; }
}
}
20 changes: 20 additions & 0 deletions Alexa.NET/Response/Directive/AudioPlayerPlayDirective.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;

namespace Alexa.NET.Response.Directive
{
public class AudioPlayerPlayDirective : IDirective
{
[JsonProperty("playBehavior")]
[JsonRequired]
[JsonConverter(typeof(StringEnumConverter))]
public PlayBehavior PlayBehavior { get; set; }

[JsonProperty("audioItem")]
[JsonRequired]
public AudioItem AudioItem { get; set; }

[JsonProperty("type")]
public string Type => "AudioPlayer.Play";
}
}
18 changes: 18 additions & 0 deletions Alexa.NET/Response/Directive/PlayBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Threading.Tasks;

namespace Alexa.NET.Response.Directive
{
public enum PlayBehavior
{
[EnumMember(Value = "REPLACE_ALL")]
ReplaceAll,
[EnumMember(Value = "ENQUEUE")]
Enqueue,
[EnumMember(Value = "REPLACE_ENQUEUED")]
ReplaceEnqueued
}
}
14 changes: 14 additions & 0 deletions Alexa.NET/Response/IDirective.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Alexa.NET.Response
{
public interface IDirective
{
[JsonRequired]
string Type { get; }
}
}
4 changes: 4 additions & 0 deletions Alexa.NET/Response/Response.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json;
using System.Collections.Generic;

namespace Alexa.NET.Response
{
Expand All @@ -16,5 +17,8 @@ public class ResponseBody
[JsonProperty("shouldEndSession")]
[JsonRequired]
public bool ShouldEndSession { get; set; }

[JsonProperty("directives", NullValueHandling = NullValueHandling.Ignore)]
public IList<IDirective> Directives { get; set; } = new List<IDirective>();
}
}
Loading

0 comments on commit 849766f

Please sign in to comment.