Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added "Attachments" property to the "FacebookPost" class
- Loading branch information
Showing
6 changed files
with
318 additions
and
1 deletion.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/Skybrud.Social.Facebook/Models/Attachments/FacebookAttachment.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Newtonsoft.Json.Linq; | ||
using Skybrud.Essentials.Json.Extensions; | ||
|
||
namespace Skybrud.Social.Facebook.Models.Attachments { | ||
|
||
/// <summary> | ||
/// Class representing a Facebook attachment. | ||
/// </summary> | ||
/// <see> | ||
/// <cref>https://developers.facebook.com/docs/graph-api/reference/v2.12/attachment</cref> | ||
/// </see> | ||
public class FacebookAttachment : FacebookAttachmentBase { | ||
|
||
#region Properties | ||
|
||
/// <summary> | ||
/// Gets an array of all sub attachments within the attachment. Not all attachments have sub attachments. | ||
/// </summary> | ||
public FacebookAttachmentBase[] SubAttachments { get; } | ||
|
||
/// <summary> | ||
/// Gets whether the attachment has any sub attachments. | ||
/// </summary> | ||
public bool HasSubAttachments => SubAttachments.Length > 0; | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
|
||
/// <summary> | ||
/// Initializes a new instance based on the specified <paramref name="obj"/>. | ||
/// </summary> | ||
/// <param name="obj">The instance of <see cref="JObject"/> representing the event.</param> | ||
private FacebookAttachment(JObject obj) : base(obj) { | ||
SubAttachments = obj.GetArrayItems("subattachments", FacebookAttachmentBase.Parse); | ||
} | ||
|
||
#endregion | ||
|
||
#region Static methods | ||
|
||
/// <summary> | ||
/// Parses the specified <paramref name="obj"/> into an instance of <see cref="FacebookAttachment"/>. | ||
/// </summary> | ||
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param> | ||
/// <returns>An instance of <see cref="FacebookAttachment"/>.</returns> | ||
public new static FacebookAttachment Parse(JObject obj) { | ||
return obj == null ? null : new FacebookAttachment(obj); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
src/Skybrud.Social.Facebook/Models/Attachments/FacebookAttachmentBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using Newtonsoft.Json.Linq; | ||
using Skybrud.Essentials.Json.Extensions; | ||
using Skybrud.Social.Facebook.Models.Common.Tags; | ||
|
||
namespace Skybrud.Social.Facebook.Models.Attachments { | ||
|
||
/// <summary> | ||
/// Class representing a Facebook attachment. | ||
/// </summary> | ||
/// <see> | ||
/// <cref>https://developers.facebook.com/docs/graph-api/reference/v2.12/attachment</cref> | ||
/// </see> | ||
public class FacebookAttachmentBase : FacebookObject { | ||
|
||
#region Properties | ||
|
||
/// <summary> | ||
/// Gets the text accompanying the attachment. | ||
/// </summary> | ||
public string Description { get; } | ||
|
||
/// <summary> | ||
/// Gets whether the <see cref="Description"/> property was included in the response. | ||
/// </summary> | ||
public bool HasDescription => !String.IsNullOrWhiteSpace(Description); | ||
|
||
/// <summary> | ||
/// Gets an array of the profiles tagged in the <see cref="Description"/> property. | ||
/// </summary> | ||
public FacebookProfileTag[] DescriptionTags { get; } | ||
|
||
/// <summary> | ||
/// Gets whether the <see cref="DescriptionTags"/> property was included in the response. | ||
/// </summary> | ||
public bool HasDescriptionTagsTags => DescriptionTags.Length > 0; | ||
|
||
/// <summary> | ||
/// Gets a reference to the media data of the attachment. | ||
/// </summary> | ||
public FacebookAttachmentMedia Media { get; } | ||
|
||
/// <summary> | ||
/// Gets whether the <see cref="Media"/> property was included in the response. | ||
/// </summary> | ||
public bool HasMedia => Media != null; | ||
|
||
/// <summary> | ||
/// Gets the title of the attachment. | ||
/// </summary> | ||
public string Title { get; } | ||
|
||
/// <summary> | ||
/// Gets the type of the attachment. | ||
/// </summary> | ||
public string Type { get; } | ||
|
||
/// <summary> | ||
/// Gets the URL of the attachment. | ||
/// </summary> | ||
public string Url { get; } | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
|
||
/// <summary> | ||
/// Initializes a new instance based on the specified <paramref name="obj"/>. | ||
/// </summary> | ||
/// <param name="obj">The instance of <see cref="JObject"/> representing the event.</param> | ||
protected FacebookAttachmentBase(JObject obj) : base(obj) { | ||
Description = obj.GetString("id"); | ||
DescriptionTags = obj.GetArrayItems("description_tags", FacebookProfileTag.Parse); | ||
Media = obj.GetObject("media", FacebookAttachmentMedia.Parse); | ||
Title = obj.GetString("title"); | ||
Type = obj.GetString("type"); | ||
Url = obj.GetString("url"); | ||
} | ||
|
||
#endregion | ||
|
||
#region Static methods | ||
|
||
/// <summary> | ||
/// Parses the specified <paramref name="obj"/> into an instance of <see cref="FacebookAttachmentBase"/>. | ||
/// </summary> | ||
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param> | ||
/// <returns>An instance of <see cref="FacebookAttachmentBase"/>.</returns> | ||
public static FacebookAttachmentBase Parse(JObject obj) { | ||
return obj == null ? null : new FacebookAttachmentBase(obj); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
src/Skybrud.Social.Facebook/Models/Attachments/FacebookAttachmentImage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Newtonsoft.Json.Linq; | ||
using Skybrud.Essentials.Json.Extensions; | ||
|
||
namespace Skybrud.Social.Facebook.Models.Attachments { | ||
|
||
/// <summary> | ||
/// Class representing an image of a Facebook attachment. | ||
/// </summary> | ||
public class FacebookAttachmentImage : FacebookObject { | ||
|
||
#region Properties | ||
|
||
/// <summary> | ||
/// Gets the height of the image. | ||
/// </summary> | ||
public int Height { get; } | ||
|
||
/// <summary> | ||
/// Gets the source URL of the image. | ||
/// </summary> | ||
public string Src { get; } | ||
|
||
/// <summary> | ||
/// Gets the width of the image. | ||
/// </summary> | ||
public int Width { get; } | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
|
||
private FacebookAttachmentImage(JObject obj) : base(obj) { | ||
Height = obj.GetInt32("height"); | ||
Src = obj.GetString("src"); | ||
Width = obj.GetInt32("width"); | ||
} | ||
|
||
#endregion | ||
|
||
#region Static methods | ||
|
||
/// <summary> | ||
/// Parses the specified <paramref name="obj"/> into an instance of <see cref="FacebookAttachmentImage"/>. | ||
/// </summary> | ||
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param> | ||
/// <returns>An instance of <see cref="FacebookAttachmentImage"/>.</returns> | ||
public static FacebookAttachmentImage Parse(JObject obj) { | ||
return obj == null ? null : new FacebookAttachmentImage(obj); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/Skybrud.Social.Facebook/Models/Attachments/FacebookAttachmentMedia.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Newtonsoft.Json.Linq; | ||
using Skybrud.Essentials.Json.Extensions; | ||
|
||
namespace Skybrud.Social.Facebook.Models.Attachments { | ||
|
||
/// <summary> | ||
/// Class with media data about a Facebook attachment. | ||
/// </summary> | ||
public class FacebookAttachmentMedia : FacebookObject { | ||
|
||
#region Properties | ||
|
||
/// <summary> | ||
/// Gets a reference to the image of the attachment. | ||
/// </summary> | ||
public FacebookAttachmentImage Image { get; } | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
|
||
private FacebookAttachmentMedia(JObject obj) : base(obj) { | ||
Image = obj.GetObject("image", FacebookAttachmentImage.Parse); | ||
} | ||
|
||
#endregion | ||
|
||
#region Static methods | ||
|
||
/// <summary> | ||
/// Parses the specified <paramref name="obj"/> into an instance of <see cref="FacebookAttachmentMedia"/>. | ||
/// </summary> | ||
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param> | ||
/// <returns>An instance of <see cref="FacebookAttachmentMedia"/>.</returns> | ||
public static FacebookAttachmentMedia Parse(JObject obj) { | ||
return obj == null ? null : new FacebookAttachmentMedia(obj); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
55 changes: 55 additions & 0 deletions
55
src/Skybrud.Social.Facebook/Models/Attachments/FacebookAttachmentTarget.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using Newtonsoft.Json.Linq; | ||
using Skybrud.Essentials.Json.Extensions; | ||
|
||
namespace Skybrud.Social.Facebook.Models.Attachments { | ||
|
||
/// <summary> | ||
/// Class representing the target object of a Facebook attachment. | ||
/// </summary> | ||
public class FacebookAttachmentTarget : FacebookObject { | ||
|
||
#region Properties | ||
|
||
/// <summary> | ||
/// Gets the ID of the object in the attachment. An attachment may refer to an external URL, in which case an ID isn't available. | ||
/// </summary> | ||
public string Id { get; } | ||
|
||
/// <summary> | ||
/// Gets whether the <see cref="Id"/> property was included in the response. | ||
/// </summary> | ||
public bool HasId => !String.IsNullOrWhiteSpace(Id); | ||
|
||
/// <summary> | ||
/// Gets the URL to the attachment. | ||
/// </summary> | ||
public string Url { get; } | ||
|
||
#endregion | ||
|
||
#region Constructors | ||
|
||
private FacebookAttachmentTarget(JObject obj) : base(obj) { | ||
Id = obj.GetString("id"); | ||
Url = obj.GetString("url"); | ||
} | ||
|
||
#endregion | ||
|
||
#region Static methods | ||
|
||
/// <summary> | ||
/// Parses the specified <paramref name="obj"/> into an instance of <see cref="FacebookAttachmentTarget"/>. | ||
/// </summary> | ||
/// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param> | ||
/// <returns>An instance of <see cref="FacebookAttachmentTarget"/>.</returns> | ||
public static FacebookAttachmentTarget Parse(JObject obj) { | ||
return obj == null ? null : new FacebookAttachmentTarget(obj); | ||
} | ||
|
||
#endregion | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters