From aaa6732c78292d653c5503e33f192a04fcf6c79a Mon Sep 17 00:00:00 2001 From: Rich Logan Date: Tue, 1 Nov 2016 10:04:35 +0000 Subject: [PATCH 1/3] Update callbacks For some reason I was returning `error(null)` when there wasn't an error and `result(null)` when there was, in addition to the correct callback. This meant they were firing when they didn't need to. --- SparkUnity/Assets/Cisco/Spark/Membership.cs | 8 -------- SparkUnity/Assets/Cisco/Spark/Message.cs | 8 -------- SparkUnity/Assets/Cisco/Spark/Person.cs | 7 +------ SparkUnity/Assets/Cisco/Spark/Room.cs | 8 -------- SparkUnity/Assets/Cisco/Spark/Team.cs | 8 -------- SparkUnity/Assets/Cisco/Spark/TeamMembership.cs | 8 -------- SparkUnity/Assets/Cisco/Spark/Webhook.cs | 8 -------- 7 files changed, 1 insertion(+), 54 deletions(-) diff --git a/SparkUnity/Assets/Cisco/Spark/Membership.cs b/SparkUnity/Assets/Cisco/Spark/Membership.cs index 0620949..068263a 100644 --- a/SparkUnity/Assets/Cisco/Spark/Membership.cs +++ b/SparkUnity/Assets/Cisco/Spark/Membership.cs @@ -98,10 +98,8 @@ public IEnumerator Commit(Action error, Action result) if (membershipData.ContainsKey ("message")) { // Spark Error error (new SparkMessage (membershipData)); - result (null); } else { // Create local Membership object - error(null); result(new Membership (membershipData)); } } @@ -124,13 +122,11 @@ public IEnumerator Delete(Action error, Action 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; error (new SparkMessage (json)); - result (false); } } } @@ -182,7 +178,6 @@ public static IEnumerator ListMemberships(Action error, Action (); @@ -191,7 +186,6 @@ public static IEnumerator ListMemberships(Action error, Action)); } result (memberships); - error (null); } } } @@ -218,10 +212,8 @@ public static IEnumerator GetMembershipDetails(string membershipId, Action error, Action result) { var messageData = Json.Deserialize (www.downloadHandler.text) as Dictionary; if (messageData.ContainsKey ("message")) { error (new SparkMessage (messageData)); - result (null); } else { result(new Message (messageData)); - error (null); } } } @@ -155,13 +153,11 @@ public IEnumerator Delete(Action error, Action 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; error (new SparkMessage (json)); - result (false); } } } @@ -185,10 +181,8 @@ public static IEnumerator GetMessageDetails(string messageId, Action; if (messageDetails.ContainsKey ("message")) { error (new SparkMessage (messageDetails)); - result (null); } else { result (new Message (messageDetails)); - error (null); } } } @@ -230,7 +224,6 @@ public static IEnumerator ListMessages(string roomId, Action error var json = Json.Deserialize (www.downloadHandler.text) as Dictionary; if (json.ContainsKey ("message")) { error (new SparkMessage (json)); - result (null); } else { var messages = new List(); var items = json ["items"] as List; @@ -238,7 +231,6 @@ public static IEnumerator ListMessages(string roomId, Action error messages.Add (new Message (message_json)); } result (messages); - error (null); } } } diff --git a/SparkUnity/Assets/Cisco/Spark/Person.cs b/SparkUnity/Assets/Cisco/Spark/Person.cs index ec08dc9..2c48835 100644 --- a/SparkUnity/Assets/Cisco/Spark/Person.cs +++ b/SparkUnity/Assets/Cisco/Spark/Person.cs @@ -60,11 +60,10 @@ public IEnumerator DownloadAvatar(Action error, Action 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); } } @@ -101,10 +100,8 @@ public static IEnumerator GetPersonDetails(string personId, Action if (personData.ContainsKey ("message")) { // Error Callback error (new SparkMessage (personData)); - result(null); } else { // Result callback - error (null); result(new Person (personData)); } } @@ -152,7 +149,6 @@ public static IEnumerator ListPeople(Action error, Action; if (json.ContainsKey ("message")) { error (new SparkMessage (json)); - result (null); } else { // Convert to Membership objects var people = new List (); @@ -161,7 +157,6 @@ public static IEnumerator ListPeople(Action error, Action)); } result (people); - error (null); } } } diff --git a/SparkUnity/Assets/Cisco/Spark/Room.cs b/SparkUnity/Assets/Cisco/Spark/Room.cs index 9aa1c54..09f0719 100644 --- a/SparkUnity/Assets/Cisco/Spark/Room.cs +++ b/SparkUnity/Assets/Cisco/Spark/Room.cs @@ -88,10 +88,8 @@ public IEnumerator Commit(Action error, Action result) { var roomData = Json.Deserialize (www.downloadHandler.text) as Dictionary; if (roomData.ContainsKey ("message")) { error (new SparkMessage (roomData)); - result (null); } else { result(new Room (roomData)); - error (null); } } } @@ -112,13 +110,11 @@ public IEnumerator Delete(Action error, Action 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; error (new SparkMessage (json)); - result (false); } } } @@ -162,7 +158,6 @@ public static IEnumerator ListRooms(Action error, Action; if (json.ContainsKey ("message")) { error (new SparkMessage(json)); - result (null); } else { var rooms = new List (); var items = json ["items"] as List; @@ -170,7 +165,6 @@ public static IEnumerator ListRooms(Action error, Action err var roomDetails = Json.Deserialize (www.downloadHandler.text) as Dictionary; if (roomDetails.ContainsKey ("message")) { error (new SparkMessage (roomDetails)); - result (null); } else { result (new Room (roomDetails)); - error (null); } } } diff --git a/SparkUnity/Assets/Cisco/Spark/Team.cs b/SparkUnity/Assets/Cisco/Spark/Team.cs index 6a17225..01d643d 100644 --- a/SparkUnity/Assets/Cisco/Spark/Team.cs +++ b/SparkUnity/Assets/Cisco/Spark/Team.cs @@ -70,10 +70,8 @@ public IEnumerator Commit(Action error, Action result) { if (teamData.ContainsKey ("message")) { // Spark Error error (new SparkMessage (teamData)); - result (null); } else { // Create local Team object - error(null); result(new Team (teamData)); } } @@ -96,13 +94,11 @@ public IEnumerator Delete(Action error, Action 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; error (new SparkMessage (json)); - result (false); } } } @@ -142,7 +138,6 @@ public static IEnumerator ListTeams(Action error, Action (); @@ -151,7 +146,6 @@ public static IEnumerator ListTeams(Action error, Action)); } result (teams); - error (null); } } } @@ -178,10 +172,8 @@ public static IEnumerator GetTeamDetails(string teamId, Action err if (teamData.ContainsKey ("team")) { // Error Callback error (new SparkMessage (teamData)); - result(null); } else { // Result callback - error (null); result(new Team (teamData)); } } diff --git a/SparkUnity/Assets/Cisco/Spark/TeamMembership.cs b/SparkUnity/Assets/Cisco/Spark/TeamMembership.cs index fec7bce..0d35012 100644 --- a/SparkUnity/Assets/Cisco/Spark/TeamMembership.cs +++ b/SparkUnity/Assets/Cisco/Spark/TeamMembership.cs @@ -99,10 +99,8 @@ public IEnumerator Commit(Action error, Action res if (teamMembershipData.ContainsKey ("message")) { // Spark Error error (new SparkMessage (teamMembershipData)); - result (null); } else { // Create local TeamMembership object - error(null); result(new TeamMembership (teamMembershipData)); } } @@ -125,13 +123,11 @@ public IEnumerator Delete(Action error, Action 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; error (new SparkMessage (json)); - result (false); } } } @@ -183,7 +179,6 @@ public static IEnumerator ListTeamMemberships(Action 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 (); @@ -192,7 +187,6 @@ public static IEnumerator ListTeamMemberships(Action error, Action teamMemberships.Add (new TeamMembership (teamMembership as Dictionary)); } result (teamMemberships); - error (null); } } } @@ -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)); } } diff --git a/SparkUnity/Assets/Cisco/Spark/Webhook.cs b/SparkUnity/Assets/Cisco/Spark/Webhook.cs index c17549d..a2efb63 100644 --- a/SparkUnity/Assets/Cisco/Spark/Webhook.cs +++ b/SparkUnity/Assets/Cisco/Spark/Webhook.cs @@ -120,10 +120,8 @@ public IEnumerator Commit(Action error, Action result) { if (webhookData.ContainsKey ("message")) { // Spark Error error (new SparkMessage (webhookData)); - result (null); } else { // Create local Membership object - error(null); result(new Webhook (webhookData)); } } @@ -144,13 +142,11 @@ public IEnumerator Delete(Action error, Action 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; error (new SparkMessage (json)); - result (false); } } } @@ -190,7 +186,6 @@ public static IEnumerator ListWebhooks(Action error, Action (); @@ -199,7 +194,6 @@ public static IEnumerator ListWebhooks(Action error, Action)); } result (webhooks); - error (null); } } } @@ -226,10 +220,8 @@ public static IEnumerator GetWebhookDetails(string webhookId, Action Date: Tue, 1 Nov 2016 10:15:59 +0000 Subject: [PATCH 2/3] Add tests for 5b014a0ccf0aa0cd0e599fdbd5de9f01ba471c79 --- .../Cisco/Spark/Tests/TestMembership.cs | 48 +++++++------------ .../Assets/Cisco/Spark/Tests/TestMessage.cs | 30 ++++-------- .../Assets/Cisco/Spark/Tests/TestPerson.cs | 24 ++++------ .../Assets/Cisco/Spark/Tests/TestRoom.cs | 36 +++++--------- .../Assets/Cisco/Spark/Tests/TestTeam.cs | 30 ++++-------- .../Cisco/Spark/Tests/TestTeamMembership.cs | 48 +++++++------------ .../Assets/Cisco/Spark/Tests/TestWebhook.cs | 30 ++++-------- 7 files changed, 82 insertions(+), 164 deletions(-) diff --git a/SparkUnity/Assets/Cisco/Spark/Tests/TestMembership.cs b/SparkUnity/Assets/Cisco/Spark/Tests/TestMembership.cs index 70b593d..984a5fe 100644 --- a/SparkUnity/Assets/Cisco/Spark/Tests/TestMembership.cs +++ b/SparkUnity/Assets/Cisco/Spark/Tests/TestMembership.cs @@ -11,10 +11,8 @@ void Start () // Create a new room for testing var testRoom = new Room ("Test Room (CiscoSpark-UnitySDK", null); StartCoroutine (testRoom.Commit (error => { - if (error != null) { - Debug.LogError("Could not create target Room: " + error.Message); - errorCount++; - } + Debug.LogError("Could not create target Room: " + error.Message); + errorCount++; }, room => { Debug.Log("Created target Room!"); testRoom = room; @@ -30,10 +28,8 @@ void Start () // Commit the membership to Spark StartCoroutine (membership.Commit (commitError => { - if (commitError != null) { - Debug.LogError ("Couldn't commit membership: " + commitError.Message); - errorCount++; - } + Debug.LogError ("Couldn't commit membership: " + commitError.Message); + errorCount++; }, commitResponse => { Debug.Log("Created membership on Spark!"); membership = commitResponse; @@ -45,20 +41,16 @@ void Start () // Try and commit empty membership StartCoroutine (new Membership ().Commit (emptyCommitError => { // This should error - if (emptyCommitError != null) { - if (!emptyCommitError.Message.Equals ("roomId cannot be null")) { - Debug.LogError ("Empty RoomId test failed"); - } + if (!emptyCommitError.Message.Equals ("roomId cannot be null")) { + Debug.LogError ("Empty RoomId test failed: " + emptyCommitError.Message); } else { Debug.Log("Empty RoomId test passed!"); } // Get Membership Details StartCoroutine (Membership.GetMembershipDetails (membership.Id, membershipDetailsError => { - if (membershipDetailsError != null) { - Debug.LogError ("GetMembership Details failed: " + membershipDetailsError.Message); - errorCount++; - } + Debug.LogError ("GetMembership Details failed: " + membershipDetailsError.Message); + errorCount++; }, membershipDetails => { membership = membershipDetails; if (membershipDetails.Id != membership.Id) { @@ -70,20 +62,16 @@ void Start () // List Memberships StartCoroutine (Membership.ListMemberships (listMembershipsError => { - if (listMembershipsError != null) { - Debug.LogError("Couldn't list memberships: " + listMembershipsError.Message); - errorCount++; - } + Debug.LogError("Couldn't list memberships: " + listMembershipsError.Message); + errorCount++; }, memberships => { Debug.Log("List Memberships passed!"); // Convert to moderator membership.IsModerator = true; StartCoroutine (membership.Commit(moderatedError => { - if (moderatedError != null) { - Debug.LogError("Couldn't set moderator flag: " + moderatedError.Message); - errorCount++; - } + Debug.LogError("Couldn't set moderator flag: " + moderatedError.Message); + errorCount++; }, moderatedMembership => { membership = moderatedMembership; if (!membership.IsModerator) { @@ -95,15 +83,11 @@ void Start () // Clean up membership StartCoroutine (membership.Delete (deleteError => { - if (deleteError != null) { - Debug.Log("Couldn't delete membership: " + deleteError.Message); - errorCount++; - } + Debug.Log("Couldn't delete membership: " + deleteError.Message); + errorCount++; }, deleted => StartCoroutine (testRoom.Delete (deleteRoomError => { - if (deleteRoomError != null) { - Debug.LogError ("Couldn't delete target Room: " + deleteRoomError.Message); - errorCount++; - } + Debug.LogError ("Couldn't delete target Room: " + deleteRoomError.Message); + errorCount++; }, deleteRoom => { if (errorCount > 0) { Debug.LogError (errorCount + " tests failed"); diff --git a/SparkUnity/Assets/Cisco/Spark/Tests/TestMessage.cs b/SparkUnity/Assets/Cisco/Spark/Tests/TestMessage.cs index d6006ea..fd36d82 100644 --- a/SparkUnity/Assets/Cisco/Spark/Tests/TestMessage.cs +++ b/SparkUnity/Assets/Cisco/Spark/Tests/TestMessage.cs @@ -15,10 +15,8 @@ void Start () { var testRoom = new Room ("Test Room (CiscoSpark-UnitySDK", null); StartCoroutine (testRoom.Commit (error => { // Failed to create test room - if (error != null) { - errorCount++; - Debug.LogError("Couldn't create target Room"); - } + errorCount++; + Debug.LogError("Couldn't create target Room"); }, room => { // Test Room successful testRoom = room; @@ -34,19 +32,15 @@ void Start () { // Commit Message StartCoroutine (newMessage.Commit (error => { - if (error != null) { - errorCount++; - Debug.LogError("Couldn't commit Message: " + error.Message); - } + errorCount++; + Debug.LogError("Couldn't commit Message: " + error.Message); }, message => { newMessage = message; // List Messages From Room StartCoroutine (Message.ListMessages (testRoom.Id, error => { - if (error != null) { - errorCount++; - Debug.LogError("Couldn't list Messages: " + error.Message); - } + errorCount++; + Debug.LogError("Couldn't list Messages: " + error.Message); }, messages => { // Check Message was successful if (messages [messages.Count - 1].Text != "Test message") { @@ -58,19 +52,15 @@ void Start () { // Delete the message StartCoroutine (newMessage.Delete (error => { - if (error != null) { - errorCount++; - Debug.LogError("Couldn't delete message: " + error.Message); - } + errorCount++; + Debug.LogError("Couldn't delete message: " + error.Message); }, result => StartCoroutine (Message.GetMessageDetails (newMessage.Id, error => { // This should error as the message has been deleted Debug.Log ("Successfully failed to get deleted message details"); // Clean up test Room StartCoroutine (testRoom.Delete (deleteError => { - if (deleteError != null) { - errorCount++; - Debug.LogError ("Couldn't delete Test Room: " + deleteError.Message); - } + errorCount++; + Debug.LogError ("Couldn't delete Test Room: " + deleteError.Message); }, delete => { // Finish and Report Debug.Log ("Finished Running Message Tests"); diff --git a/SparkUnity/Assets/Cisco/Spark/Tests/TestPerson.cs b/SparkUnity/Assets/Cisco/Spark/Tests/TestPerson.cs index 0fe2401..17467b4 100644 --- a/SparkUnity/Assets/Cisco/Spark/Tests/TestPerson.cs +++ b/SparkUnity/Assets/Cisco/Spark/Tests/TestPerson.cs @@ -7,10 +7,8 @@ void Start() { // Error Count var errorCount = 0; StartCoroutine (Person.ListPeople (listPeopleError => { - if (listPeopleError != null) { - errorCount++; - Debug.LogError("List people failed: " + listPeopleError.Message); - } + errorCount++; + Debug.LogError("List people failed: " + listPeopleError.Message); }, people => { if (people.Count != 1) { errorCount++; @@ -23,10 +21,8 @@ void Start() { } StartCoroutine (Person.GetPersonDetails (people[0].Id, getPersonError => { - if (getPersonError != null) { - errorCount++; - Debug.LogError("Get Person Details failed: " + getPersonError.Message); - } + errorCount++; + Debug.LogError("Get Person Details failed: " + getPersonError.Message); },person => { if (person.DisplayName != "Rich Logan") { errorCount++; @@ -44,18 +40,14 @@ void Start() { } StartCoroutine (Person.GetPersonDetails (getPersonAgain => { - if (getPersonAgain != null) { - errorCount++; - Debug.LogError("Get Person Details failed: " + getPersonAgain.Message); - } + errorCount++; + Debug.LogError("Get Person Details failed: " + getPersonAgain.Message); }, callback => { Debug.Log("Authenticated user is: " + callback.DisplayName); StartCoroutine (person.DownloadAvatar (avatarError => { - if (avatarError != null) { - errorCount++; - Debug.LogError("List people failed: " + avatarError.Message); - } + errorCount++; + Debug.LogError("List people failed: " + avatarError.Message); }, texture => { if (texture.width <= 0) { Debug.Log("Couldn't download user's avatar"); diff --git a/SparkUnity/Assets/Cisco/Spark/Tests/TestRoom.cs b/SparkUnity/Assets/Cisco/Spark/Tests/TestRoom.cs index c1a3e36..63deb1e 100644 --- a/SparkUnity/Assets/Cisco/Spark/Tests/TestRoom.cs +++ b/SparkUnity/Assets/Cisco/Spark/Tests/TestRoom.cs @@ -12,10 +12,8 @@ void Start () { // List Rooms StartCoroutine (Room.ListRooms (listRoomsError => { - if (listRoomsError != null) { - Debug.LogError("Couldn't list Rooms: " + listRoomsError.Message); - errorCount++; - } + Debug.LogError("Couldn't list Rooms: " + listRoomsError.Message); + errorCount++; }, rooms => { Debug.Log("List Rooms Passed!"); int startRoomCount = rooms.Count; @@ -23,10 +21,8 @@ void Start () { // Create New Room var testRoom = new Room("Test Room (CiscoSpark-UnitySDK)", null); StartCoroutine(testRoom.Commit (commitRoomError => { - if (commitRoomError != null) { - Debug.LogError("Couldn't commit Room: " + commitRoomError.Message); - errorCount++; - } + Debug.LogError("Couldn't commit Room: " + commitRoomError.Message); + errorCount++; }, room => { testRoom = room; if (testRoom.Title != "Test Room (CiscoSpark-UnitySDK)") { @@ -39,10 +35,8 @@ void Start () { // Edit Room with Updated Title testRoom.Title = "Updated Test Room (CiscoSpark-UnitySDK)"; StartCoroutine (testRoom.Commit(updateRoomError => { - if (updateRoomError != null) { - Debug.LogError("Couldn't update Room: " + updateRoomError.Message); - errorCount++; - } + Debug.LogError("Couldn't update Room: " + updateRoomError.Message); + errorCount++; }, updatedRoom => { testRoom = updatedRoom; if (testRoom.Title != "Updated Test Room (CiscoSpark-UnitySDK)") { @@ -54,10 +48,8 @@ void Start () { // Get Room Details StartCoroutine (Room.GetRoomDetails (testRoom.Id, roomDetailsError => { - if (roomDetailsError != null) { - Debug.LogError("Couldn't get Room details: " + roomDetailsError.Message); - errorCount++; - } + Debug.LogError("Couldn't get Room details: " + roomDetailsError.Message); + errorCount++; }, retrivedRoom => { testRoom = retrivedRoom; if (testRoom.Title != "Updated Test Room (CiscoSpark-UnitySDK)") { @@ -68,15 +60,11 @@ void Start () { // Delete Room StartCoroutine (testRoom.Delete (deleteRoomError => { - if (deleteRoomError != null) { - Debug.LogError("Couldn't get Room details: " + deleteRoomError.Message); - errorCount++; - } + Debug.LogError("Couldn't get Room details: " + deleteRoomError.Message); + errorCount++; }, result => StartCoroutine (Room.ListRooms (listRoomsError => { - if (listRoomsError != null) { - Debug.LogError ("Couldn't list Rooms: " + listRoomsError.Message); - errorCount++; - } + Debug.LogError ("Couldn't list Rooms: " + listRoomsError.Message); + errorCount++; }, postDeleteRooms => { if (startRoomCount != postDeleteRooms.Count) { Debug.LogError ("Delete Room Failed!"); diff --git a/SparkUnity/Assets/Cisco/Spark/Tests/TestTeam.cs b/SparkUnity/Assets/Cisco/Spark/Tests/TestTeam.cs index 72bf932..a969097 100644 --- a/SparkUnity/Assets/Cisco/Spark/Tests/TestTeam.cs +++ b/SparkUnity/Assets/Cisco/Spark/Tests/TestTeam.cs @@ -6,10 +6,8 @@ void Start () { var errorCount = 0; // List Teams StartCoroutine (Team.ListTeams (listError => { - if (listError != null) { - errorCount++; - Debug.LogError ("List Teams failed: " + listError.Message); - } + errorCount++; + Debug.LogError ("List Teams failed: " + listError.Message); }, teams => { if (teams.Count > 0) { Debug.Log ("ListTeams passed"); @@ -20,10 +18,8 @@ void Start () { // Get Team Details StartCoroutine (Team.GetTeamDetails (teams[0].Id, detailsError => { - if (detailsError != null) { - errorCount++; - Debug.LogError ("List Teams failed: " + detailsError.Message); - } + errorCount++; + Debug.LogError ("List Teams failed: " + detailsError.Message); }, retrievedTeam => { if (retrievedTeam.Name != teams[0].Name) { errorCount++; @@ -36,10 +32,8 @@ void Start () { const string OriginalName = "Unity SDK Test Team"; var t = new Team(OriginalName); StartCoroutine (t.Commit (commitError => { - if (commitError != null) { - errorCount++; - Debug.LogError("GetTeamDetails failed: " + commitError.Message); - } + errorCount++; + Debug.LogError("GetTeamDetails failed: " + commitError.Message); }, createdTeam => { t = createdTeam; if (t.Id == null) { @@ -53,10 +47,8 @@ void Start () { const string NewName = OriginalName + "RENAMED"; t.Name = NewName; StartCoroutine (t.Commit (updateError => { - if (updateError != null) { - errorCount++; - Debug.LogError("Update failed: " + updateError.Message); - } + errorCount++; + Debug.LogError("Update failed: " + updateError.Message); }, updatedTeam => { t = updatedTeam; if (t.Name != NewName) { @@ -68,10 +60,8 @@ void Start () { // Delete Team StartCoroutine (t.Delete (deleteError => { - if (deleteError != null) { - errorCount++; - Debug.LogError("Delete team failed: " + deleteError.Message); - } + errorCount++; + Debug.LogError("Delete team failed: " + deleteError.Message); }, deleteSuccess => { // Error Report if (errorCount > 0) { diff --git a/SparkUnity/Assets/Cisco/Spark/Tests/TestTeamMembership.cs b/SparkUnity/Assets/Cisco/Spark/Tests/TestTeamMembership.cs index dd5c795..20c4a7d 100644 --- a/SparkUnity/Assets/Cisco/Spark/Tests/TestTeamMembership.cs +++ b/SparkUnity/Assets/Cisco/Spark/Tests/TestTeamMembership.cs @@ -10,10 +10,8 @@ void Start () var testTeam = new Team ("SparkUnityTestTeam"); StartCoroutine (testTeam.Commit (error => { - if (error != null) { - Debug.LogError("Could not create target Team: " + error.Message); - errorCount++; - } + Debug.LogError("Could not create target Team: " + error.Message); + errorCount++; }, team => { Debug.Log("Created target Team!"); testTeam = team; @@ -29,10 +27,8 @@ void Start () // Commit the membership to Spark StartCoroutine (teamMembership.Commit (commitError => { - if (commitError != null) { - Debug.LogError ("Couldn't commit team membership: " + commitError.Message); - errorCount++; - } + Debug.LogError ("Couldn't commit team membership: " + commitError.Message); + errorCount++; }, commitResponse => { Debug.Log("Created team membership on Spark!"); teamMembership = commitResponse; @@ -44,20 +40,16 @@ void Start () // Try and commit empty membership StartCoroutine (new TeamMembership ().Commit (emptyCommitError => { // This should error - if (emptyCommitError != null) { - if (!emptyCommitError.Message.Equals ("teamId cannot be null")) { - Debug.LogError ("Empty TeamId test failed"); - } + if (!emptyCommitError.Message.Equals ("teamId cannot be null")) { + Debug.LogError ("Empty TeamId test failed: " + emptyCommitError.Message); } else { Debug.Log("Empty TeamId test passed!"); } // Get Membership Details StartCoroutine (TeamMembership.GetTeamMembershipDetails (teamMembership.Id, membershipDetailsError => { - if (membershipDetailsError != null) { - Debug.LogError ("Get Team Membership Details failed: " + membershipDetailsError.Message); - errorCount++; - } + Debug.LogError ("Get Team Membership Details failed: " + membershipDetailsError.Message); + errorCount++; }, membershipDetails => { teamMembership = membershipDetails; if (membershipDetails.Id != teamMembership.Id) { @@ -69,20 +61,16 @@ void Start () // List Memberships StartCoroutine (TeamMembership.ListTeamMemberships (listMembershipsError => { - if (listMembershipsError != null) { - Debug.LogError("Couldn't list team memberships: " + listMembershipsError.Message); - errorCount++; - } + Debug.LogError("Couldn't list team memberships: " + listMembershipsError.Message); + errorCount++; }, memberships => { Debug.Log("List Team Memberships passed!"); // Convert to moderator teamMembership.IsModerator = true; StartCoroutine (teamMembership.Commit(moderatedError => { - if (moderatedError != null) { - Debug.LogError("Couldn't set moderator flag: " + moderatedError.Message); - errorCount++; - } + Debug.LogError("Couldn't set moderator flag: " + moderatedError.Message); + errorCount++; }, moderatedMembership => { teamMembership = moderatedMembership; if (!teamMembership.IsModerator) { @@ -94,15 +82,11 @@ void Start () // Clean up membership StartCoroutine (teamMembership.Delete (deleteError => { - if (deleteError != null) { - Debug.Log("Couldn't delete membership: " + deleteError.Message); - errorCount++; - } + Debug.Log("Couldn't delete membership: " + deleteError.Message); + errorCount++; }, deleted => StartCoroutine (testTeam.Delete (deleteTeamError => { - if (deleteTeamError != null) { - Debug.LogError ("Couldn't delete target Team: " + deleteTeamError.Message); - errorCount++; - } + Debug.LogError ("Couldn't delete target Team: " + deleteTeamError.Message); + errorCount++; }, deleteTeam => { if (errorCount > 0) { Debug.LogError (errorCount + " tests failed"); diff --git a/SparkUnity/Assets/Cisco/Spark/Tests/TestWebhook.cs b/SparkUnity/Assets/Cisco/Spark/Tests/TestWebhook.cs index 7c52fb3..3bfa030 100644 --- a/SparkUnity/Assets/Cisco/Spark/Tests/TestWebhook.cs +++ b/SparkUnity/Assets/Cisco/Spark/Tests/TestWebhook.cs @@ -9,10 +9,8 @@ void Start () { // List Webhooks StartCoroutine (Webhook.ListWebhooks (listWebhookError => { - if (listWebhookError != null) { - errorCount++; - Debug.LogError ("List Webhooks failed: " + listWebhookError.Message); - } + errorCount++; + Debug.LogError ("List Webhooks failed: " + listWebhookError.Message); }, webhooks => { // List Webhooks Passed var newWebhook = new Webhook ( @@ -23,10 +21,8 @@ void Start () { "86dacc007724d8ea666f88fc77d918dad9537a15" ); StartCoroutine (newWebhook.Commit (commitError => { - if (commitError != null) { - errorCount++; - Debug.LogError("Create Webhook failed: " + commitError.Message); - } + errorCount++; + Debug.LogError("Create Webhook failed: " + commitError.Message); }, commitedWebhook => { newWebhook = commitedWebhook; if (newWebhook.Id == null) { @@ -36,10 +32,8 @@ void Start () { Debug.Log("Create Webhook Passed"); newWebhook.Name = "testingWebhookUpdated"; StartCoroutine (newWebhook.Commit (updateError => { - if (updateError != null) { - errorCount++; - Debug.Log("Update Webhook failed: " + updateError.Message); - } + errorCount++; + Debug.Log("Update Webhook failed: " + updateError.Message); }, updatedWebhook => { newWebhook = updatedWebhook; if (newWebhook.Name != "testingWebhookUpdated") { @@ -50,10 +44,8 @@ void Start () { Debug.Log("Update Webhook Passed"); StartCoroutine (Webhook.GetWebhookDetails (newWebhook.Id, detailsError => { - if (detailsError != null) { - errorCount++; - Debug.LogError("Couldn't get Webhook details: " + detailsError.Message); - } + errorCount++; + Debug.LogError("Couldn't get Webhook details: " + detailsError.Message); }, webhook => { if (newWebhook.Id != webhook.Id) { errorCount++; @@ -61,10 +53,8 @@ void Start () { } else { // Details Passed StartCoroutine (newWebhook.Delete (deleteError => { - if (deleteError != null) { - errorCount++; - Debug.LogError ("Delete Webhook failed: " + deleteError.Message); - } + errorCount++; + Debug.LogError ("Delete Webhook failed: " + deleteError.Message); }, delete => { // Finish and Report if (errorCount == 0) { From 7598b0f4e98d216b629ca7593c5613ec345758a1 Mon Sep 17 00:00:00 2001 From: Rich Logan Date: Tue, 1 Nov 2016 10:17:11 +0000 Subject: [PATCH 3/3] Update README to reflect new callbacks --- README.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 86d0b90..0093327 100644 --- a/README.md +++ b/README.md @@ -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) { @@ -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) {