Skip to content

Commit

Permalink
Merge pull request #9 from RichLogan/feature/callback-changes
Browse files Browse the repository at this point in the history
feature/callback-changes
  • Loading branch information
RichLogan authored Nov 1, 2016
2 parents be42e68 + 7598b0f commit 5b989fa
Show file tree
Hide file tree
Showing 15 changed files with 87 additions and 226 deletions.
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ using Cisco.Spark;
public class Spark : MonoBehaviour {
void Start() {
StartCoroutine (Room.ListRooms (error => {
if (error != null) {
Debug.LogError(error.Message);
foreach (var sparkError in error.Errors) {
Debug.LogError(sparkError.Description);
}
Debug.LogError(error.Message);
foreach (var sparkError in error.Errors) {
Debug.LogError(sparkError.Description);
}
}, rooms => {
foreach (var room in rooms) {
Expand All @@ -70,9 +68,7 @@ public class Spark : MonoBehaviour {
void Start() {
StartCoroutine (Message.ListMessages ("Y2lzY29zcGFyazovL3VzL1JPT00vMzFhOTVkYTAtZjgwYi0xMWU1LWIyMjgtNTk1Mjc3YjMwNDli",
error => {
if (error != null) {
Debug.LogError ("Failed: " + error.Message);
}
Debug.LogError ("Failed: " + error.Message);
},
messages => {
foreach (var message in messages) {
Expand Down
8 changes: 0 additions & 8 deletions SparkUnity/Assets/Cisco/Spark/Membership.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ public IEnumerator Commit(Action<SparkMessage> error, Action<Membership> result)
if (membershipData.ContainsKey ("message")) {
// Spark Error
error (new SparkMessage (membershipData));
result (null);
} else {
// Create local Membership object
error(null);
result(new Membership (membershipData));
}
}
Expand All @@ -124,13 +122,11 @@ public IEnumerator Delete(Action<SparkMessage> error, Action<bool> result) {
} else {
// Delete returns 204 on success
if (www.responseCode == 204) {
error (null);
result (true);
} else {
// Delete Failed
var json = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
error (new SparkMessage (json));
result (false);
}
}
}
Expand Down Expand Up @@ -182,7 +178,6 @@ public static IEnumerator ListMemberships(Action<SparkMessage> error, Action<Lis
// Check for Spark side errors
if (json.ContainsKey ("message")) {
error (new SparkMessage (json));
result (null);
} else {
// Convert to Membership objects
var memberships = new List<Membership> ();
Expand All @@ -191,7 +186,6 @@ public static IEnumerator ListMemberships(Action<SparkMessage> error, Action<Lis
memberships.Add (new Membership (membership as Dictionary<string, object>));
}
result (memberships);
error (null);
}
}
}
Expand All @@ -218,10 +212,8 @@ public static IEnumerator GetMembershipDetails(string membershipId, Action<Spark
if (membershipData.ContainsKey ("message")) {
// Error Callback
error (new SparkMessage (membershipData));
result(null);
} else {
// Result callback
error (null);
result(new Membership (membershipData));
}
}
Expand Down
8 changes: 0 additions & 8 deletions SparkUnity/Assets/Cisco/Spark/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,8 @@ public IEnumerator Commit(Action<SparkMessage> error, Action<Message> result) {
var messageData = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
if (messageData.ContainsKey ("message")) {
error (new SparkMessage (messageData));
result (null);
} else {
result(new Message (messageData));
error (null);
}
}
}
Expand All @@ -155,13 +153,11 @@ public IEnumerator Delete(Action<SparkMessage> error, Action<bool> result) {
} else {
// Delete returns 204 on success
if (www.responseCode == 204) {
error (null);
result (true);
} else {
// Delete Failed
var json = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
error (new SparkMessage (json));
result (false);
}
}
}
Expand All @@ -185,10 +181,8 @@ public static IEnumerator GetMessageDetails(string messageId, Action<SparkMessag
var messageDetails = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
if (messageDetails.ContainsKey ("message")) {
error (new SparkMessage (messageDetails));
result (null);
} else {
result (new Message (messageDetails));
error (null);
}
}
}
Expand Down Expand Up @@ -230,15 +224,13 @@ public static IEnumerator ListMessages(string roomId, Action<SparkMessage> error
var json = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
if (json.ContainsKey ("message")) {
error (new SparkMessage (json));
result (null);
} else {
var messages = new List<Message>();
var items = json ["items"] as List<object>;
foreach (Dictionary<string, object> message_json in items) {
messages.Add (new Message (message_json));
}
result (messages);
error (null);
}
}
}
Expand Down
7 changes: 1 addition & 6 deletions SparkUnity/Assets/Cisco/Spark/Person.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ public IEnumerator DownloadAvatar(Action<SparkMessage> error, Action<Texture> ca
var texture = ((DownloadHandlerTexture)www.downloadHandler).texture;
if (texture) {
callback (texture);
error (null);
} else {
// TODO: Check what happens on failed avatar calls
Debug.LogError ("Download avatar failed. Check implementation.");
callback (null);
Debug.LogError (www.downloadHandler.text);
error (null);
}
}
Expand Down Expand Up @@ -101,10 +100,8 @@ public static IEnumerator GetPersonDetails(string personId, Action<SparkMessage>
if (personData.ContainsKey ("message")) {
// Error Callback
error (new SparkMessage (personData));
result(null);
} else {
// Result callback
error (null);
result(new Person (personData));
}
}
Expand Down Expand Up @@ -152,7 +149,6 @@ public static IEnumerator ListPeople(Action<SparkMessage> error, Action<List<Per
var json = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
if (json.ContainsKey ("message")) {
error (new SparkMessage (json));
result (null);
} else {
// Convert to Membership objects
var people = new List<Person> ();
Expand All @@ -161,7 +157,6 @@ public static IEnumerator ListPeople(Action<SparkMessage> error, Action<List<Per
people.Add (new Person (person as Dictionary<string, object>));
}
result (people);
error (null);
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions SparkUnity/Assets/Cisco/Spark/Room.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,8 @@ public IEnumerator Commit(Action<SparkMessage> error, Action<Room> result) {
var roomData = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
if (roomData.ContainsKey ("message")) {
error (new SparkMessage (roomData));
result (null);
} else {
result(new Room (roomData));
error (null);
}
}
}
Expand All @@ -112,13 +110,11 @@ public IEnumerator Delete(Action<SparkMessage> error, Action<bool> result) {
} else {
// Delete returns 204 on success
if (www.responseCode == 204) {
error (null);
result (true);
} else {
// Delete Failed
var json = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
error (new SparkMessage (json));
result (false);
}
}
}
Expand Down Expand Up @@ -162,15 +158,13 @@ public static IEnumerator ListRooms(Action<SparkMessage> error, Action<List<Room
var json = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
if (json.ContainsKey ("message")) {
error (new SparkMessage(json));
result (null);
} else {
var rooms = new List<Room> ();
var items = json ["items"] as List<object>;
foreach (Dictionary<string, object> room_json in items) {
rooms.Add(new Room (room_json));
}
result (rooms);
error (null);
}
}
}
Expand All @@ -193,10 +187,8 @@ public static IEnumerator GetRoomDetails(string roomId, Action<SparkMessage> err
var roomDetails = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
if (roomDetails.ContainsKey ("message")) {
error (new SparkMessage (roomDetails));
result (null);
} else {
result (new Room (roomDetails));
error (null);
}
}
}
Expand Down
8 changes: 0 additions & 8 deletions SparkUnity/Assets/Cisco/Spark/Team.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,8 @@ public IEnumerator Commit(Action<SparkMessage> error, Action<Team> result) {
if (teamData.ContainsKey ("message")) {
// Spark Error
error (new SparkMessage (teamData));
result (null);
} else {
// Create local Team object
error(null);
result(new Team (teamData));
}
}
Expand All @@ -96,13 +94,11 @@ public IEnumerator Delete(Action<SparkMessage> error, Action<bool> result) {
} else {
// Delete returns 204 on success
if (www.responseCode == 204) {
error (null);
result (true);
} else {
// Delete Failed
var json = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
error (new SparkMessage (json));
result (false);
}
}
}
Expand Down Expand Up @@ -142,7 +138,6 @@ public static IEnumerator ListTeams(Action<SparkMessage> error, Action<List<Team
// Check for Spark side errors
if (json.ContainsKey ("message")) {
error (new SparkMessage (json));
result (null);
} else {
// Convert to Team objects
var teams = new List<Team> ();
Expand All @@ -151,7 +146,6 @@ public static IEnumerator ListTeams(Action<SparkMessage> error, Action<List<Team
teams.Add (new Team (team as Dictionary<string, object>));
}
result (teams);
error (null);
}
}
}
Expand All @@ -178,10 +172,8 @@ public static IEnumerator GetTeamDetails(string teamId, Action<SparkMessage> err
if (teamData.ContainsKey ("team")) {
// Error Callback
error (new SparkMessage (teamData));
result(null);
} else {
// Result callback
error (null);
result(new Team (teamData));
}
}
Expand Down
8 changes: 0 additions & 8 deletions SparkUnity/Assets/Cisco/Spark/TeamMembership.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,8 @@ public IEnumerator Commit(Action<SparkMessage> error, Action<TeamMembership> res
if (teamMembershipData.ContainsKey ("message")) {
// Spark Error
error (new SparkMessage (teamMembershipData));
result (null);
} else {
// Create local TeamMembership object
error(null);
result(new TeamMembership (teamMembershipData));
}
}
Expand All @@ -125,13 +123,11 @@ public IEnumerator Delete(Action<SparkMessage> error, Action<bool> result) {
} else {
// Delete returns 204 on success
if (www.responseCode == 204) {
error (null);
result (true);
} else {
// Delete Failed
var json = Json.Deserialize (www.downloadHandler.text) as Dictionary<string, object>;
error (new SparkMessage (json));
result (false);
}
}
}
Expand Down Expand Up @@ -183,7 +179,6 @@ public static IEnumerator ListTeamMemberships(Action<SparkMessage> error, Action
// Check for Spark side errors
if (json.ContainsKey ("message")) {
error (new SparkMessage (json));
result (null);
} else {
// Convert to TeamMembership objects
var teamMemberships = new List<TeamMembership> ();
Expand All @@ -192,7 +187,6 @@ public static IEnumerator ListTeamMemberships(Action<SparkMessage> error, Action
teamMemberships.Add (new TeamMembership (teamMembership as Dictionary<string, object>));
}
result (teamMemberships);
error (null);
}
}
}
Expand All @@ -219,10 +213,8 @@ public static IEnumerator GetTeamMembershipDetails(string teamMembershipId, Acti
if (teamMembershipData.ContainsKey ("message")) {
// Error Callback
error (new SparkMessage (teamMembershipData));
result(null);
} else {
// Result callback
error (null);
result(new TeamMembership (teamMembershipData));
}
}
Expand Down
Loading

0 comments on commit 5b989fa

Please sign in to comment.