-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTeam.cs
92 lines (83 loc) · 2.92 KB
/
Team.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections;
using System.Collections.Generic;
namespace Cisco.Spark
{
/// <summary>
/// A Team is a group of <see cref="Person"/>s with a set of <see cref="Room"/>s that are visible to all members of the Team.
/// </summary>
public class Team : SparkObject
{
/// <summary>
/// The SparkType for this SparkObject implementation.
/// </summary>
internal override SparkType SparkType
{
get { return SparkType.Team; }
}
/// <summary>
/// A user-friendly name for the Team.
/// </summary>
public string Name { get; set; }
/// <summary>
/// Creates a new Team object representing an existing Spark Team.
/// </summary>
/// <param name="id">Spark UUID of Team.</param>
public static Team FromId(string id)
{
return (Team)SparkObjectFactory.Make(id, SparkType.Team);
}
public Team() { }
/// <summary>
/// Creates a new Team locally.
/// </summary>
public Team(string name)
{
Name = name;
}
/// <summary>
/// Returns a dictionary representation of the object.
/// </summary>
/// <returns>The serialised object as a Dictionary.</returns>
/// <param name="fields">A specific list of fields to serialise.</param>
protected override Dictionary<string, object> ToDict(List<string> fields)
{
var data = base.ToDict();
if (Name == null)
{
throw new Exception("Team Name must be set");
}
else
{
data["name"] = Name;
return CleanDict(data, fields);
}
}
/// <summary>
/// Populates the object with data retrieved from Spark.
/// </summary>
/// <param name="data">De-serialised data dictionary from Spark.</param>
protected override void LoadDict(Dictionary<string, object> data)
{
base.LoadDict(data);
Name = data["name"] as string;
}
/// <summary>
/// Lists teams to which the authenticated user belongs.
/// </summary>
/// <param name="error">Error from Spark, if any.</param>
/// <param name="results">List of teams.</param>
/// <param name="max">Limit the maximum number of teams.</param>
/// <returns></returns>
public static IEnumerator ListTeams(Action<SparkMessage> error, Action<List<Team>> results, int max = 0)
{
var constraints = new Dictionary<string, string>();
if (max > 0)
{
constraints.Add("max", max.ToString());
}
var listObjects = ListObjects(constraints, SparkType.Team, error, results);
yield return Request.Instance.StartCoroutine(listObjects);
}
}
}