From 40acb9f026a0262dad0235cdd74a34f0db3b37a9 Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Thu, 5 Nov 2015 16:58:07 +0000 Subject: [PATCH 1/4] Added support for all fields for /updates/create API method --- BufferAPI/BufferService.cs | 70 ++++++++++++++++++++++++ BufferAPI/BufferUpdate.cs | 103 ++++++++++++++++++++++++++++++++++++ BufferAPI/TimeConversion.cs | 31 +++++++++++ 3 files changed, 204 insertions(+) create mode 100644 BufferAPI/TimeConversion.cs diff --git a/BufferAPI/BufferService.cs b/BufferAPI/BufferService.cs index 19923f5..1fc7ac6 100644 --- a/BufferAPI/BufferService.cs +++ b/BufferAPI/BufferService.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using AncoraMVVM.Rest; using Newtonsoft.Json; +using System; namespace BufferAPI { @@ -101,6 +102,75 @@ public async Task> PostUpdate(string text, { return await PostUpdate(text, profiles.Select(p => p.Id)); } + + /// + /// Posts an update to the given social media profiles. + /// + /// BufferUpdateCreate object describing the update to create. + /// List with all the social media profile ids. + /// HttpResponse with a BufferUpdateCreating object describing the result of the operation. + public async Task> PostUpdate(BufferUpdateCreate update, IEnumerable profileIds) + { + ParameterCollection param = new ParameterCollection(); + + foreach (var id in profileIds) + param.Add("profile_ids[]", id); + + param.Add("text", update.Text); + param.Add("shorten", update.Shorten.ToString().ToLower()); + param.Add("now", update.Now.ToString().ToLower()); + param.Add("top", update.Top.ToString().ToLower()); + param.Add("attachment", update.Attachment.ToString().ToLower()); + + + // schedule + if (update.ScheduledAt != null && update.ScheduledAt != DateTime.MinValue ) + param.Add("scheduled_at", update.ScheduledAtSeconds); + + // media + if (update.Media.Link != null && update.Media.Link.Trim() != "") + param.Add("media[link]", update.Media.Link); + + if (update.Media.Description != null && update.Media.Description.Trim() != "") + param.Add("media[description]", update.Media.Description); + + if (update.Media.Title != null && update.Media.Title.Trim() != "") + param.Add("media[title]", update.Media.Title); + + if (update.Media.Picture != null && update.Media.Picture.Trim() != "") + param.Add("media[picture]", update.Media.Picture); + + if (update.Media.Photo != null && update.Media.Photo.Trim() != "") + param.Add("media[photo]", update.Media.Photo); + + if (update.Media.Thumbnail != null && update.Media.Thumbnail.Trim() != "") + param.Add("media[thumbnail]", update.Media.Thumbnail); + + + // retweet + if (update.Retweet.TweetId != null && update.Retweet.TweetId.Trim() != "") + param.Add("retweet[tweet_id]", update.Retweet.TweetId); + + if (update.Retweet.Comment != null && update.Retweet.Comment.Trim() != "") + param.Add("retweet[comment]", update.Retweet.Comment); + + + var req = CreateRequest("updates/create.json", HttpMethod.Post, param); + + return await Execute(req); + } + + /// + /// Posts an update to the given social media profiles. + /// + /// BufferUpdateCreate object describing the update to create. + /// List with all the social media profiles. + /// HttpResponse with a BufferUpdateCreating object describing the result of the operation. + public async Task> PostUpdate(BufferUpdateCreate update, IEnumerable profiles) + { + return await PostUpdate(update, profiles.Select(p => p.Id)); + } + #endregion } } diff --git a/BufferAPI/BufferUpdate.cs b/BufferAPI/BufferUpdate.cs index 4936d9b..26a13f6 100644 --- a/BufferAPI/BufferUpdate.cs +++ b/BufferAPI/BufferUpdate.cs @@ -81,4 +81,107 @@ public DateTime DueAt [JsonProperty("via")] public string Via { get; set; } } + + + + /// + /// This class represents the media section of a new update to send to buffer + /// + /// + [JsonObject(MemberSerialization.OptIn)] + public class BufferUpdateMedia + { + [JsonProperty("link")] + public string Link { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("picture")] + public string Picture { get; set; } + + [JsonProperty("photo")] + public string Photo { get; set; } + + [JsonProperty("thumbnail")] + public string Thumbnail { get; set; } + + } + + /// + /// This class represents the retweet section of a new update to send to buffer + /// + /// + [JsonObject(MemberSerialization.OptIn)] + public class BufferUpdateRetweet + { + [JsonProperty("tweet_id")] + public string TweetId { get; set; } + + [JsonProperty("comment")] + public string Comment { get; set; } + + } + + + + + /// + /// This class represents a new update to send to buffer + /// + /// + [JsonObject(MemberSerialization.OptIn)] + public class BufferUpdateCreate + { + public BufferUpdateCreate() + { + Media = new BufferUpdateMedia(); + Retweet = new BufferUpdateRetweet(); + + Shorten = true; + Attachment = true; + } + + + // [JsonProperty("text")] + public string Text { get; set; } + + // [JsonProperty("shorten")] + public bool Shorten { get; set; } + + // [JsonProperty("now")] + public bool Now { get; set; } + + // [JsonProperty("top")] + public bool Top { get; set; } + + // [JsonProperty("media")] + public BufferUpdateMedia Media { get; set; } + + // [JsonProperty("attachment")] + public bool Attachment { get; set; } + + + public DateTime ScheduledAt { get; set; } + + // [JsonProperty("scheduled_at")] + public double ScheduledAtSeconds + { + get + { + return BufferAPI.TimeConversion.DateTimeToUnixTimestamp(ScheduledAt); + } + } + + // [JsonProperty("retweet")] + public BufferUpdateRetweet Retweet { get; set; } + + + } + + + } diff --git a/BufferAPI/TimeConversion.cs b/BufferAPI/TimeConversion.cs new file mode 100644 index 0000000..a6ef094 --- /dev/null +++ b/BufferAPI/TimeConversion.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BufferAPI +{ + class TimeConversion + { + public static DateTime UnixTimeStampToDateTime(double? unixTimeStamp) + { + // Unix timestamp is seconds past epoch + System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); + dtDateTime = dtDateTime.AddSeconds(unixTimeStamp.Value).ToLocalTime(); + return dtDateTime; + } + + public static double DateTimeToUnixTimestamp(DateTime dateTime) + { + if (dateTime == null) + { + throw new Exception("Date Time is null, cannot convert."); + } + else + { + return (dateTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds; + } + } + } + +} \ No newline at end of file From 692db13ef8e2d6119e864a01677612085b72ca84 Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Thu, 5 Nov 2015 17:01:12 +0000 Subject: [PATCH 2/4] Revert "Added support for all fields for /updates/create API method" This reverts commit 40acb9f026a0262dad0235cdd74a34f0db3b37a9. --- BufferAPI/BufferService.cs | 70 ------------------------ BufferAPI/BufferUpdate.cs | 103 ------------------------------------ BufferAPI/TimeConversion.cs | 31 ----------- 3 files changed, 204 deletions(-) delete mode 100644 BufferAPI/TimeConversion.cs diff --git a/BufferAPI/BufferService.cs b/BufferAPI/BufferService.cs index 1fc7ac6..19923f5 100644 --- a/BufferAPI/BufferService.cs +++ b/BufferAPI/BufferService.cs @@ -4,7 +4,6 @@ using System.Threading.Tasks; using AncoraMVVM.Rest; using Newtonsoft.Json; -using System; namespace BufferAPI { @@ -102,75 +101,6 @@ public async Task> PostUpdate(string text, { return await PostUpdate(text, profiles.Select(p => p.Id)); } - - /// - /// Posts an update to the given social media profiles. - /// - /// BufferUpdateCreate object describing the update to create. - /// List with all the social media profile ids. - /// HttpResponse with a BufferUpdateCreating object describing the result of the operation. - public async Task> PostUpdate(BufferUpdateCreate update, IEnumerable profileIds) - { - ParameterCollection param = new ParameterCollection(); - - foreach (var id in profileIds) - param.Add("profile_ids[]", id); - - param.Add("text", update.Text); - param.Add("shorten", update.Shorten.ToString().ToLower()); - param.Add("now", update.Now.ToString().ToLower()); - param.Add("top", update.Top.ToString().ToLower()); - param.Add("attachment", update.Attachment.ToString().ToLower()); - - - // schedule - if (update.ScheduledAt != null && update.ScheduledAt != DateTime.MinValue ) - param.Add("scheduled_at", update.ScheduledAtSeconds); - - // media - if (update.Media.Link != null && update.Media.Link.Trim() != "") - param.Add("media[link]", update.Media.Link); - - if (update.Media.Description != null && update.Media.Description.Trim() != "") - param.Add("media[description]", update.Media.Description); - - if (update.Media.Title != null && update.Media.Title.Trim() != "") - param.Add("media[title]", update.Media.Title); - - if (update.Media.Picture != null && update.Media.Picture.Trim() != "") - param.Add("media[picture]", update.Media.Picture); - - if (update.Media.Photo != null && update.Media.Photo.Trim() != "") - param.Add("media[photo]", update.Media.Photo); - - if (update.Media.Thumbnail != null && update.Media.Thumbnail.Trim() != "") - param.Add("media[thumbnail]", update.Media.Thumbnail); - - - // retweet - if (update.Retweet.TweetId != null && update.Retweet.TweetId.Trim() != "") - param.Add("retweet[tweet_id]", update.Retweet.TweetId); - - if (update.Retweet.Comment != null && update.Retweet.Comment.Trim() != "") - param.Add("retweet[comment]", update.Retweet.Comment); - - - var req = CreateRequest("updates/create.json", HttpMethod.Post, param); - - return await Execute(req); - } - - /// - /// Posts an update to the given social media profiles. - /// - /// BufferUpdateCreate object describing the update to create. - /// List with all the social media profiles. - /// HttpResponse with a BufferUpdateCreating object describing the result of the operation. - public async Task> PostUpdate(BufferUpdateCreate update, IEnumerable profiles) - { - return await PostUpdate(update, profiles.Select(p => p.Id)); - } - #endregion } } diff --git a/BufferAPI/BufferUpdate.cs b/BufferAPI/BufferUpdate.cs index 26a13f6..4936d9b 100644 --- a/BufferAPI/BufferUpdate.cs +++ b/BufferAPI/BufferUpdate.cs @@ -81,107 +81,4 @@ public DateTime DueAt [JsonProperty("via")] public string Via { get; set; } } - - - - /// - /// This class represents the media section of a new update to send to buffer - /// - /// - [JsonObject(MemberSerialization.OptIn)] - public class BufferUpdateMedia - { - [JsonProperty("link")] - public string Link { get; set; } - - [JsonProperty("description")] - public string Description { get; set; } - - [JsonProperty("title")] - public string Title { get; set; } - - [JsonProperty("picture")] - public string Picture { get; set; } - - [JsonProperty("photo")] - public string Photo { get; set; } - - [JsonProperty("thumbnail")] - public string Thumbnail { get; set; } - - } - - /// - /// This class represents the retweet section of a new update to send to buffer - /// - /// - [JsonObject(MemberSerialization.OptIn)] - public class BufferUpdateRetweet - { - [JsonProperty("tweet_id")] - public string TweetId { get; set; } - - [JsonProperty("comment")] - public string Comment { get; set; } - - } - - - - - /// - /// This class represents a new update to send to buffer - /// - /// - [JsonObject(MemberSerialization.OptIn)] - public class BufferUpdateCreate - { - public BufferUpdateCreate() - { - Media = new BufferUpdateMedia(); - Retweet = new BufferUpdateRetweet(); - - Shorten = true; - Attachment = true; - } - - - // [JsonProperty("text")] - public string Text { get; set; } - - // [JsonProperty("shorten")] - public bool Shorten { get; set; } - - // [JsonProperty("now")] - public bool Now { get; set; } - - // [JsonProperty("top")] - public bool Top { get; set; } - - // [JsonProperty("media")] - public BufferUpdateMedia Media { get; set; } - - // [JsonProperty("attachment")] - public bool Attachment { get; set; } - - - public DateTime ScheduledAt { get; set; } - - // [JsonProperty("scheduled_at")] - public double ScheduledAtSeconds - { - get - { - return BufferAPI.TimeConversion.DateTimeToUnixTimestamp(ScheduledAt); - } - } - - // [JsonProperty("retweet")] - public BufferUpdateRetweet Retweet { get; set; } - - - } - - - } diff --git a/BufferAPI/TimeConversion.cs b/BufferAPI/TimeConversion.cs deleted file mode 100644 index a6ef094..0000000 --- a/BufferAPI/TimeConversion.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace BufferAPI -{ - class TimeConversion - { - public static DateTime UnixTimeStampToDateTime(double? unixTimeStamp) - { - // Unix timestamp is seconds past epoch - System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); - dtDateTime = dtDateTime.AddSeconds(unixTimeStamp.Value).ToLocalTime(); - return dtDateTime; - } - - public static double DateTimeToUnixTimestamp(DateTime dateTime) - { - if (dateTime == null) - { - throw new Exception("Date Time is null, cannot convert."); - } - else - { - return (dateTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds; - } - } - } - -} \ No newline at end of file From 0582481d7215bd17a2d24b821c43ec11567ee410 Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Thu, 5 Nov 2015 17:01:56 +0000 Subject: [PATCH 3/4] Revert "Revert "Added support for all fields for /updates/create API method"" This reverts commit 692db13ef8e2d6119e864a01677612085b72ca84. --- BufferAPI/BufferService.cs | 70 ++++++++++++++++++++++++ BufferAPI/BufferUpdate.cs | 103 ++++++++++++++++++++++++++++++++++++ BufferAPI/TimeConversion.cs | 31 +++++++++++ 3 files changed, 204 insertions(+) create mode 100644 BufferAPI/TimeConversion.cs diff --git a/BufferAPI/BufferService.cs b/BufferAPI/BufferService.cs index 19923f5..1fc7ac6 100644 --- a/BufferAPI/BufferService.cs +++ b/BufferAPI/BufferService.cs @@ -4,6 +4,7 @@ using System.Threading.Tasks; using AncoraMVVM.Rest; using Newtonsoft.Json; +using System; namespace BufferAPI { @@ -101,6 +102,75 @@ public async Task> PostUpdate(string text, { return await PostUpdate(text, profiles.Select(p => p.Id)); } + + /// + /// Posts an update to the given social media profiles. + /// + /// BufferUpdateCreate object describing the update to create. + /// List with all the social media profile ids. + /// HttpResponse with a BufferUpdateCreating object describing the result of the operation. + public async Task> PostUpdate(BufferUpdateCreate update, IEnumerable profileIds) + { + ParameterCollection param = new ParameterCollection(); + + foreach (var id in profileIds) + param.Add("profile_ids[]", id); + + param.Add("text", update.Text); + param.Add("shorten", update.Shorten.ToString().ToLower()); + param.Add("now", update.Now.ToString().ToLower()); + param.Add("top", update.Top.ToString().ToLower()); + param.Add("attachment", update.Attachment.ToString().ToLower()); + + + // schedule + if (update.ScheduledAt != null && update.ScheduledAt != DateTime.MinValue ) + param.Add("scheduled_at", update.ScheduledAtSeconds); + + // media + if (update.Media.Link != null && update.Media.Link.Trim() != "") + param.Add("media[link]", update.Media.Link); + + if (update.Media.Description != null && update.Media.Description.Trim() != "") + param.Add("media[description]", update.Media.Description); + + if (update.Media.Title != null && update.Media.Title.Trim() != "") + param.Add("media[title]", update.Media.Title); + + if (update.Media.Picture != null && update.Media.Picture.Trim() != "") + param.Add("media[picture]", update.Media.Picture); + + if (update.Media.Photo != null && update.Media.Photo.Trim() != "") + param.Add("media[photo]", update.Media.Photo); + + if (update.Media.Thumbnail != null && update.Media.Thumbnail.Trim() != "") + param.Add("media[thumbnail]", update.Media.Thumbnail); + + + // retweet + if (update.Retweet.TweetId != null && update.Retweet.TweetId.Trim() != "") + param.Add("retweet[tweet_id]", update.Retweet.TweetId); + + if (update.Retweet.Comment != null && update.Retweet.Comment.Trim() != "") + param.Add("retweet[comment]", update.Retweet.Comment); + + + var req = CreateRequest("updates/create.json", HttpMethod.Post, param); + + return await Execute(req); + } + + /// + /// Posts an update to the given social media profiles. + /// + /// BufferUpdateCreate object describing the update to create. + /// List with all the social media profiles. + /// HttpResponse with a BufferUpdateCreating object describing the result of the operation. + public async Task> PostUpdate(BufferUpdateCreate update, IEnumerable profiles) + { + return await PostUpdate(update, profiles.Select(p => p.Id)); + } + #endregion } } diff --git a/BufferAPI/BufferUpdate.cs b/BufferAPI/BufferUpdate.cs index 4936d9b..26a13f6 100644 --- a/BufferAPI/BufferUpdate.cs +++ b/BufferAPI/BufferUpdate.cs @@ -81,4 +81,107 @@ public DateTime DueAt [JsonProperty("via")] public string Via { get; set; } } + + + + /// + /// This class represents the media section of a new update to send to buffer + /// + /// + [JsonObject(MemberSerialization.OptIn)] + public class BufferUpdateMedia + { + [JsonProperty("link")] + public string Link { get; set; } + + [JsonProperty("description")] + public string Description { get; set; } + + [JsonProperty("title")] + public string Title { get; set; } + + [JsonProperty("picture")] + public string Picture { get; set; } + + [JsonProperty("photo")] + public string Photo { get; set; } + + [JsonProperty("thumbnail")] + public string Thumbnail { get; set; } + + } + + /// + /// This class represents the retweet section of a new update to send to buffer + /// + /// + [JsonObject(MemberSerialization.OptIn)] + public class BufferUpdateRetweet + { + [JsonProperty("tweet_id")] + public string TweetId { get; set; } + + [JsonProperty("comment")] + public string Comment { get; set; } + + } + + + + + /// + /// This class represents a new update to send to buffer + /// + /// + [JsonObject(MemberSerialization.OptIn)] + public class BufferUpdateCreate + { + public BufferUpdateCreate() + { + Media = new BufferUpdateMedia(); + Retweet = new BufferUpdateRetweet(); + + Shorten = true; + Attachment = true; + } + + + // [JsonProperty("text")] + public string Text { get; set; } + + // [JsonProperty("shorten")] + public bool Shorten { get; set; } + + // [JsonProperty("now")] + public bool Now { get; set; } + + // [JsonProperty("top")] + public bool Top { get; set; } + + // [JsonProperty("media")] + public BufferUpdateMedia Media { get; set; } + + // [JsonProperty("attachment")] + public bool Attachment { get; set; } + + + public DateTime ScheduledAt { get; set; } + + // [JsonProperty("scheduled_at")] + public double ScheduledAtSeconds + { + get + { + return BufferAPI.TimeConversion.DateTimeToUnixTimestamp(ScheduledAt); + } + } + + // [JsonProperty("retweet")] + public BufferUpdateRetweet Retweet { get; set; } + + + } + + + } diff --git a/BufferAPI/TimeConversion.cs b/BufferAPI/TimeConversion.cs new file mode 100644 index 0000000..a6ef094 --- /dev/null +++ b/BufferAPI/TimeConversion.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BufferAPI +{ + class TimeConversion + { + public static DateTime UnixTimeStampToDateTime(double? unixTimeStamp) + { + // Unix timestamp is seconds past epoch + System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); + dtDateTime = dtDateTime.AddSeconds(unixTimeStamp.Value).ToLocalTime(); + return dtDateTime; + } + + public static double DateTimeToUnixTimestamp(DateTime dateTime) + { + if (dateTime == null) + { + throw new Exception("Date Time is null, cannot convert."); + } + else + { + return (dateTime - new DateTime(1970, 1, 1).ToLocalTime()).TotalSeconds; + } + } + } + +} \ No newline at end of file From bfd163dc2d3f8011b59e2d85653700b45fdc8e4a Mon Sep 17 00:00:00 2001 From: Patrick Scott Date: Thu, 5 Nov 2015 17:08:48 +0000 Subject: [PATCH 4/4] minor change --- BufferAPI/BufferUpdate.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/BufferAPI/BufferUpdate.cs b/BufferAPI/BufferUpdate.cs index 26a13f6..3f59b93 100644 --- a/BufferAPI/BufferUpdate.cs +++ b/BufferAPI/BufferUpdate.cs @@ -91,22 +91,22 @@ public DateTime DueAt [JsonObject(MemberSerialization.OptIn)] public class BufferUpdateMedia { - [JsonProperty("link")] + //[JsonProperty("link")] public string Link { get; set; } - [JsonProperty("description")] + //[JsonProperty("description")] public string Description { get; set; } - [JsonProperty("title")] + // [JsonProperty("title")] public string Title { get; set; } - [JsonProperty("picture")] + //[JsonProperty("picture")] public string Picture { get; set; } - [JsonProperty("photo")] + //[JsonProperty("photo")] public string Photo { get; set; } - [JsonProperty("thumbnail")] + //[JsonProperty("thumbnail")] public string Thumbnail { get; set; } } @@ -118,10 +118,10 @@ public class BufferUpdateMedia [JsonObject(MemberSerialization.OptIn)] public class BufferUpdateRetweet { - [JsonProperty("tweet_id")] + //[JsonProperty("tweet_id")] public string TweetId { get; set; } - [JsonProperty("comment")] + //[JsonProperty("comment")] public string Comment { get; set; } }