-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSparkMessage.cs
75 lines (67 loc) · 2.37 KB
/
SparkMessage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System.Collections.Generic;
using UnityEngine.Networking;
namespace Cisco.Spark
{
/// <summary>
/// A message Spark returns in response to an operation.
/// This is usually a wrapping of a SparkError.
/// </summary>
public class SparkMessage
{
/// <summary>
/// The specific message from Spark.
/// </summary>
public string Message { get; private set; }
/// <summary>
/// A collection of one or more <see cref="SparkError"/>s.
/// </summary>
public IEnumerable<SparkError> Errors { get; private set; }
/// <summary>
/// Spark's internal tracking ID for this message.
/// </summary>
public string TrackingId { get; private set; }
/// <summary>
/// The associated web request.
/// </summary>
public UnityWebRequest WebRequest { get; private set; }
/// <summary>
/// Creates a SparkMessage from a JSON Spark response.
/// </summary>
/// <param name="data">Dictionary of data about the SparkMessage.</param>
/// <param name="request">The associated UnityWebRequest.</param>
public SparkMessage(Dictionary<string, object> data, UnityWebRequest request)
{
WebRequest = request;
Message = (string)data["message"];
Errors = new List<SparkError>();
object errors;
if (data.TryGetValue("errors", out errors))
{
var listOfErrors = errors as List<object>;
var errorList = new List<SparkError>();
foreach (var error in listOfErrors)
{
errorList.Add(new SparkError(error as Dictionary<string, object>));
}
Errors = errorList;
}
TrackingId = (string)data["trackingId"];
}
/// <summary>
/// Creates a SparkMessage object from a UnityWebRequest.
/// </summary>
/// <param name="request">The associated UnityWebRequest.</param>
public SparkMessage(UnityWebRequest request)
{
WebRequest = request;
}
/// <summary>
/// Text only error.
/// </summary>
/// <param name="message">Error text.</param>
public SparkMessage(string message)
{
Message = message;
}
}
}