public static void AddComment(string checkinId, string text, Action success, Action <Exception> failure) { var client = (new FourSquareWebClient()).GetWrappedClientTemporary(); var uuri = FourSquareWebClient.BuildFourSquareUri( "checkins/" + checkinId + "/addcomment", GeoMethodType.None, "text", text); // real app will... %20%26%20 for space & space ( & ) var uri = uuri.Uri; var newUri = FourSquareWebClient.CreateServiceRequest(uri, true); client.UploadStringCompleted += (x, xe) => //client.DownloadStringCompleted += (x, xe) => { Exception e = null; if (xe.Error != null) { e = xe.Error; } else { string rs = xe.Result; try { var json = FourSquareDataLoaderBase <LoadContext> .ProcessMetaAndNotificationsReturnJson(rs); } catch (Exception ee) { e = new UserIntendedException("There was a problem adding your comment, please try again later.", ee); } } client = null; // Result now if there is not a photo. if (e != null) { failure(e); } else { success(); } }; // POST request. client.UploadStringAsync(newUri, string.Empty); //client.DownloadStringAsyncWithPost(newUri, string.Empty); }
public static void AddComment(string checkinId, string text, Action success, Action<Exception> failure) { var client = (new FourSquareWebClient()).GetWrappedClientTemporary(); var uuri = FourSquareWebClient.BuildFourSquareUri( "checkins/" + checkinId + "/addcomment", GeoMethodType.None, "text", text); // real app will... %20%26%20 for space & space ( & ) var uri = uuri.Uri; var newUri = FourSquareWebClient.CreateServiceRequest(uri, true); client.UploadStringCompleted += (x, xe) => //client.DownloadStringCompleted += (x, xe) => { Exception e = null; if (xe.Error != null) { e = xe.Error; } else { string rs = xe.Result; try { var json = FourSquareDataLoaderBase<LoadContext>.ProcessMetaAndNotificationsReturnJson(rs); } catch (Exception ee) { e = new UserIntendedException("There was a problem adding your comment, please try again later.", ee); } } client = null; // Result now if there is not a photo. if (e != null) failure(e); else success(); }; // POST request. client.UploadStringAsync(newUri, string.Empty); //client.DownloadStringAsyncWithPost(newUri, string.Empty); }
// DESIGN: Not a very good place for a web service call like this. public static void AddNewTip(string venueId, string tipText, Stream photo, Action <Tip, Exception> result) { // NOTE: Official API supports an extra "url" parameter to associate var client = (new FourSquareWebClient()).GetWrappedClientTemporary(); var uuri = FourSquareWebClient.BuildFourSquareUri( "tips/add", GeoMethodType.None, "venueId", venueId, "text", tipText); Uri uri = uuri.Uri; var newUri = FourSquareWebClient.CreateServiceRequest(uri, true); client.UploadStringCompleted += (x, xe) => { Exception e = null; Tip t = null; if (xe.Error != null) { e = xe.Error; } else { string rs = xe.Result; try { var json = FourSquareDataLoaderBase <LoadContext> .ProcessMetaAndNotificationsReturnJson(rs); Tip tip = Tip.ParseJson(json["tip"], typeof(Venue), venueId); if (photo != null) { // Result comes after the photo upload. var req = Model.PhotoAddLoadContext.AddPhotoToTip(tip.TipId, false, false); req.SetPhotoBytes(photo); FourSquare.Instance.AddPhoto(req, (pic) => { // that's it.. //RefreshVenue(null); result(tip, null); }, (fail) => { result(null, fail); }); } } catch (Exception ee) { e = new UserIntendedException("There was a problem adding the tip, please try again later.", ee); } } client = null; // Result now if there is not a photo. if (photo == null) { result(t, e); } }; // POST request. client.UploadStringAsync(newUri, string.Empty); //client.DownloadStringAsyncWithPost(r, string.Empty); }
// DESIGN: Not a very good place for a web service call like this. public static void AddNewTip(string venueId, string tipText, Stream photo, Action<Tip,Exception> result) { // NOTE: Official API supports an extra "url" parameter to associate var client = (new FourSquareWebClient()).GetWrappedClientTemporary(); var uuri = FourSquareWebClient.BuildFourSquareUri( "tips/add", GeoMethodType.None, "venueId", venueId, "text", tipText); Uri uri = uuri.Uri; var newUri = FourSquareWebClient.CreateServiceRequest(uri, true); client.UploadStringCompleted += (x, xe) => { Exception e = null; Tip t = null; if (xe.Error != null) { e = xe.Error; } else { string rs = xe.Result; try { var json = FourSquareDataLoaderBase<LoadContext>.ProcessMetaAndNotificationsReturnJson(rs); Tip tip = Tip.ParseJson(json["tip"], typeof(Venue), venueId); if (photo != null) { // Result comes after the photo upload. var req = Model.PhotoAddLoadContext.AddPhotoToTip(tip.TipId, false, false); req.SetPhotoBytes(photo); FourSquare.Instance.AddPhoto(req, (pic) => { // that's it.. //RefreshVenue(null); result(tip, null); }, (fail) => { result(null, fail); }); } } catch (Exception ee) { e = new UserIntendedException("There was a problem adding the tip, please try again later.", ee); } } client = null; // Result now if there is not a photo. if (photo == null) { result(t, e); } }; // POST request. client.UploadStringAsync(newUri, string.Empty); //client.DownloadStringAsyncWithPost(r, string.Empty); }