/// <summary> /// Constructs a collection of Flickr photographs. The collection is a result /// of the passed in method, and numPerPage represents how many should be /// fetched at a time. /// </summary> /// <param name="numPerPage"></param> internal FlickrPhotos(FlickrMethod photoQuery, int numPerPage) { _photoQueryMethod = photoQuery; _photoListCache = new Dictionary<int, List<FlickrPhoto>>(); _numPerPage = numPerPage; _count = Int32.MaxValue; _user = null; }
public void AuthenticateUser(object sender, EventArgs e) { AuthenticationGrid.Visibility = Visibility.Hidden; Flickr.AsynchGetAuthenticatedUser(frob, Dispatcher, delegate(object o) { user = (AuthorizedFlickrUser)o; AuthenticationGrid.Visibility = Visibility.Hidden; confirmAuthentButton.IsEnabled = false; authenticateButton.Visibility = Visibility.Hidden; logInLabel.Visibility = Visibility.Visible; Flickr.AsynchGetRecentlyUpdated(user, cv.Dispatcher, delegate(object photos) { cv.Data = (FlickrPhotos)photos; }); }); }
internal FlickrPhotos(FlickrMethod method, int numPerPage, AuthorizedFlickrUser user) : this(method, numPerPage) { _user = user; }
/// <summary> /// Parses the given autohrization info in to an AuthorizedFlickrUser /// </summary> /// <param name="xmlNodeList"></param> /// <returns></returns> private static AuthorizedFlickrUser ParseAuthorizationInfo(XmlNodeList xmlNodeList) { AuthorizedFlickrUser afu = new AuthorizedFlickrUser(); foreach (XmlNode outputArg in xmlNodeList) { if (outputArg.Name == "token") { afu.Token = outputArg.InnerText; } else if (outputArg.Name == "perms") { afu.Permissions = outputArg.InnerText; } else if (outputArg.Name == "user") { for (int i = 0; i < outputArg.Attributes.Count; i++) { if (outputArg.Attributes[i].Name == "nsid") { afu.NSID = outputArg.Attributes[i].InnerText; } else if (outputArg.Attributes[i].Name == "username") { afu.Username = outputArg.Attributes[i].InnerText; } else if (outputArg.Attributes[i].Name == "fullname") { afu.Fullname = outputArg.Attributes[i].InnerText; } } } } if (afu.Token == "") return null; else return afu; }
/// <summary> /// Gets the authorization info a logged in user /// </summary> /// <param name="frob"></param> /// <returns></returns> private static AuthorizedFlickrUser GetAuthorizationInfo(string frob) { AuthorizedFlickrUser flickrUser = null; FlickrMethod method = new FlickrMethod(ApiKey, "flickr.auth.getToken"); method.AddParameter("frob", frob); XmlNode rspNode = null; if (method.MakeSignedRequest(SharedSecret, out rspNode)) { foreach (XmlNode outputArg in rspNode.ChildNodes) { if (outputArg.Name == "auth") { flickrUser = ParseAuthorizationInfo(outputArg.ChildNodes); } } } authorizedUser = flickrUser; return flickrUser; }
/// <summary> /// Posts the given comments about the given photo. /// </summary> /// <param name="comments"></param> /// <param name="photo"></param> /// <param name="user"></param> /// <returns></returns> public static bool PostComments(string comments, FlickrPhoto photo, AuthorizedFlickrUser user) { FlickrMethod method = new FlickrMethod(ApiKey, "flickr.photos.comments.addComment", user.Token, SharedSecret); method.AddParameter("comment_text", comments); method.AddParameter("photo_id", photo.ID); XmlNode rspNode = null; return method.MakeRequest(out rspNode); }
/// <summary> /// Gets the list of a users most recently updated photos /// </summary> /// <param name="user"></param> /// <returns></returns> public static FlickrPhotos GetRecentlyUpdated(AuthorizedFlickrUser user) { FlickrMethod method = new FlickrMethod(ApiKey, "flickr.photos.recentlyUpdated", user.Token, SharedSecret); int updateTime = 1; method.AddParameter("min_date", updateTime.ToString()); FlickrPhotos photos = new FlickrPhotos(method, 50, user); photos.GetPhoto(0); // we call this to force the call to get the total # count return photos; }
/// <summary> /// Asynchrnousy posts comments about the given photo. /// </summary> /// <param name="comments"></param> /// <param name="photo"></param> /// <param name="user"></param> /// <param name="notificationDispatcher"></param> /// <param name="notificationEvent"></param> public static void AsynchPostComments(string comments, FlickrPhoto photo, AuthorizedFlickrUser user, Dispatcher notificationDispatcher, FlickrWorkCompleteDelegate notificationEvent) { AddToWorkQueue(delegate() { bool result = PostComments(comments, photo, user); if (notificationDispatcher != null && notificationEvent != null) { notificationDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, notificationEvent, result); } } ); }
/// <summary> /// Asynchronously gets the most recently updated photos for a given user /// </summary> /// <param name="user"></param> /// <param name="notificationDispatcher"></param> /// <param name="notificationEvent"></param> public static void AsynchGetRecentlyUpdated(AuthorizedFlickrUser user, Dispatcher notificationDispatcher, FlickrWorkCompleteDelegate notificationEvent) { { AddToWorkQueue(delegate() { FlickrPhotos photos = GetRecentlyUpdated(user); if (notificationDispatcher != null && notificationEvent != null) { notificationDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, notificationEvent, photos); } } ); } }