/// <summary> /// Creates a new photo album on behalf of the user. /// </summary> /// <param name="title">The title of the album.</param> /// <param name="message">An initial remark about the album.</param> /// <returns>The <see cref="Album"/> just posted to the user's profile.</returns> /// <exception cref="OpenGraphException">Thrown if the server fails to perform the request.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="title"/> is <see langword="null"/> or empty.</exception> public Album CreateAlbum(string title, string message) { if (string.IsNullOrEmpty(title)) throw new ArgumentNullException("title"); var content = new Dictionary<string, string> { { "name", title } }; if (!string.IsNullOrEmpty(message)) content.Add("message", message); return Session.PostToConnection<Album>(ID, "albums", content.ToPostString()); }
/// <summary> /// Creates a <see cref="Note"/> on behalf of the user. /// </summary> /// <param name="subject">The title of the Note.</param> /// <param name="message">The Note's contents.</param> /// <returns>The <see cref="Note"/> just posted to the user's profile.</returns> /// <exception cref="OpenGraphException">Thrown if the server fails to perform the request.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="subject"/> or <paramref name="message"/> is <see langword="null"/> or empty.</exception> public Note CreateNote(string subject, string message) { if (string.IsNullOrEmpty(subject)) throw new ArgumentNullException("subject"); if (string.IsNullOrEmpty(message)) throw new ArgumentNullException("message"); var content = new Dictionary<string, string> { { "subject", subject }, { "message", message } }; return Session.PostToConnection<Note>(ID, "notes", content.ToPostString()); }
/// <summary> /// Creates a new event on behalf of this user. /// </summary> /// <param name="name">The name of the event to create.</param> /// <param name="starts">The time that the event starts.</param> /// <param name="ends">The time that the event ends.</param> /// <param name="description">The event's description.</param> /// <param name="privacy">The event's privacy setting. Valid values are <c>"OPEN"</c>, <c>"CLOSED"</c>, and <c>"SECRET"</c>.</param> /// <returns>The <see cref="GraphEvent"/> created on behalf of the user.</returns> /// <exception cref="OpenGraphException">Thrown if the server fails to perform the request.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> is <see langword="null"/> or empty.</exception> public GraphEvent CreateEvent(string name, string description, string privacy, DateTime starts, DateTime ends) { if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); Session.ValidateAndRefresh(); string url = string.Format(CultureInfo.InvariantCulture, "{0}{1}/events?access_token={2}", Session.BaseUrl, ID, Session.AccessToken); Dictionary<string, string> par = new Dictionary<string, string>(); par.Add("name", name); par.Add("start_time", UnixTime.FromDateTime(starts.ToUniversalTime()).ToString()); par.Add("end_time", UnixTime.FromDateTime(ends.ToUniversalTime()).ToString()); par.Add("description", description); par.Add("privacy", privacy); string postContent = par.ToPostString(); string jsonResponse = Fetcher.Post(url, postContent); JToken result = Fetcher.FromJsonText(jsonResponse); if (result.HasValues && result["error"] != null) throw ExceptionParser.Parse(result["error"]); return Session.Request<GraphEvent>(result["id"].ToString()); }
/// <summary> /// Creates a new event on behalf of this user. /// </summary> /// <param name="name">The name of the event to create.</param> /// <param name="starts">The time that the event starts.</param> /// <param name="ends">The time that the event ends.</param> /// <returns>The <see cref="GraphEvent"/> created on behalf of the user.</returns> /// <exception cref="OpenGraphException">Thrown if the server fails to perform the request.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="name"/> is <see langword="null"/> or empty.</exception> public GraphEvent CreateEvent(string name, DateTime starts, DateTime ends) { const string ISO8601_FORMAT = @"yyyy-MM-ddTHH\:mm\:ss.fffffffzzz"; if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); Session.ValidateAndRefresh(); string url = string.Format(CultureInfo.InvariantCulture, "{0}{1}/events?access_token={2}", Session.BaseUrl, ID, Session.AccessToken); Dictionary<string, string> par = new Dictionary<string,string>(); par.Add("name", name); par.Add("start_time", starts.ToString(ISO8601_FORMAT)); par.Add("end_time", ends.ToString(ISO8601_FORMAT)); string postContent = par.ToPostString(); string jsonResponse = Fetcher.Post(url, postContent); JToken result = Fetcher.FromJsonText(jsonResponse); if (result.HasValues && result["error"] != null) throw ExceptionParser.Parse(result["error"]); return Session.Request<GraphEvent>(result["id"].ToString()); }
/// <summary> /// Writes a link to the user's profile. /// </summary> /// <param name="linkUrl">The URL of the link</param> /// <param name="message">A descriptive message with the link.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="linkUrl"/> or <paramref name="message"/> is <see langword="null"/> or empty.</exception> /// <exception cref="OpenGraphException">Thrown if the server fails to perform the request.</exception> /// <returns>The <see cref="Link"/> just posted to the current user's profile.</returns> public Link WriteLink(string linkUrl, string message) { if (string.IsNullOrEmpty(linkUrl)) throw new ArgumentNullException("linkUrl"); if (string.IsNullOrEmpty(message)) throw new ArgumentNullException("message"); Session.ValidateAndRefresh(); string url = string.Format(CultureInfo.InvariantCulture, "{0}{1}/links?access_token={2}", Session.BaseUrl, ID, Session.AccessToken); Dictionary<string, string> par = new Dictionary<string, string>(); par.Add("message", message); par.Add("link", linkUrl); string postContent = par.ToPostString(); string jsonResponse = Fetcher.Post(url, postContent); JToken result = Fetcher.FromJsonText(jsonResponse); if (result.HasValues && result["error"] != null) throw ExceptionParser.Parse(result["error"]); return Session.Request<Link>(result["id"].ToString()); }
/// <summary> /// Writes a new <see cref="Post"/> to the user's feed. /// </summary> /// <param name="message">The post message.</param> /// <param name="pictureUrl">A URL of an optional picture associated with the post. The default value of this parameter is <see langword="null"/>.</param> /// <param name="linkUrl">A URL of an optional link to be associated with this post. The default value of this parameter is <see langword="null"/>.</param> /// <param name="linkName">The name of the optional link to be associated with this post. The default value of this parameter is <see langword="null"/>.</param> /// <param name="linkDescription">The description of the optional link associated with this post. The default value of this parameter is <see langword="null"/>.</param> /// <returns>The <see cref="Post"/> just posted to the current user's feed.</returns> /// <exception cref="OpenGraphException">Thrown if the server fails to perform the request.</exception> /// <exception cref="ArgumentNullException">Thrown if <paramref name="message"/> is <see langword="null"/> or empty.</exception> public Post WriteFeed(string message, string pictureUrl = null, string linkUrl = null, string linkName = null, string linkDescription = null) { if (string.IsNullOrEmpty(message)) throw new ArgumentNullException("message"); Session.ValidateAndRefresh(); string url = string.Format(CultureInfo.InvariantCulture, "{0}{1}/feed?access_token={2}", Session.BaseUrl, ID, Session.AccessToken); Dictionary<string, string> par = new Dictionary<string, string>(); par.Add("message", message); if (pictureUrl != null) par.Add("picture", pictureUrl); if (linkUrl != null) { par.Add("link", linkUrl); if (linkName != null) par.Add("name", linkName); if (linkDescription != null) par.Add("description", linkDescription); } string postContent = par.ToPostString(); string jsonResponse = Fetcher.Post(url, postContent); JToken result = Fetcher.FromJsonText(jsonResponse); if (result.HasValues && result["error"] != null) throw ExceptionParser.Parse(result["error"]); return Session.Request<Post>(result["id"].ToString()); }