Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trivial fix #108

Merged
merged 4 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MoEmbed.Core.Tests/Models/Metadata/TwitterMetadataTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class TwitterExperimentalMetadataTest
[Theory]
[InlineData(
463440424141459456L,
"US Department of the Interior",
"US Department of the Interior (@Interior)",
"https://pbs.twimg.com/profile_images/432081479/DOI_LOGO_normal.jpg",
"Sunsets don't get much better than this one over @GrandTetonNPS. #nature #sunset http://t.co/YuKy2rcjyU"
)]
Expand Down
14 changes: 12 additions & 2 deletions MoEmbed.Core/Models/Metadata/TwitterExperimentalMetadata.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MoEmbed.Models.TweetExperimental;
using MoEmbed.Models.TwitterExperimental;

using Portable.Xaml.Markup;

Expand Down Expand Up @@ -46,6 +46,16 @@ public override async Task<EmbedData> FetchAsync(RequestContext context)
req.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var res = await context.Service.HttpClient.SendAsync(req).ConfigureAwait(false);

if (res.StatusCode == System.Net.HttpStatusCode.NotFound)
{
return new EmbedData()
{
Url = Url,
Title = "Not found",
Description = "Sorry, we can't create an embed for that. It may have been deleted or made private. Please try again.",
};
}

res.EnsureSuccessStatusCode();

var tweet = JsonSerializer.Deserialize<Tweet>(res.Content.ReadAsStream(), new JsonSerializerOptions { Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping });
Expand All @@ -65,7 +75,7 @@ public override async Task<EmbedData> FetchAsync(RequestContext context)
Location = Url,
RestrictionPolicy = RestrictionPolicies.Safe
},
Title = tweet.User.Name,
Title = $"{tweet.User.Name} (@{tweet.User.ScreenName})",
Description = tweet.Text,
Medias = tweet.MediaDetails?.Select(ToMedia).ToList() ?? new(),
RestrictionPolicy = tweet.PossiblySensitive ? RestrictionPolicies.Restricted : RestrictionPolicies.Safe,
Expand Down
2 changes: 1 addition & 1 deletion MoEmbed.Core/Models/TwitterExperimental/BackgroundColor.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System.Text.Json.Serialization;

namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class BackgroundColor

Check warning on line 5 in MoEmbed.Core/Models/TwitterExperimental/BackgroundColor.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'BackgroundColor'
{
[JsonPropertyName("red")]
public int Red { get; set; }

Check warning on line 8 in MoEmbed.Core/Models/TwitterExperimental/BackgroundColor.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'BackgroundColor.Red'

[JsonPropertyName("green")]
public int Green { get; set; }

Check warning on line 11 in MoEmbed.Core/Models/TwitterExperimental/BackgroundColor.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'BackgroundColor.Green'

[JsonPropertyName("blue")]
public int Blue { get; set; }

Check warning on line 14 in MoEmbed.Core/Models/TwitterExperimental/BackgroundColor.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'BackgroundColor.Blue'
}
Expand Down
2 changes: 1 addition & 1 deletion MoEmbed.Core/Models/TwitterExperimental/EditControl.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class EditControl

Check warning on line 6 in MoEmbed.Core/Models/TwitterExperimental/EditControl.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'EditControl'
{
[JsonPropertyName("edit_tweet_ids")]
public List<string> EditTweetIds { get; set; }

Check warning on line 9 in MoEmbed.Core/Models/TwitterExperimental/EditControl.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'EditControl.EditTweetIds'

[JsonPropertyName("editable_until_msecs")]
public string EditableUntilMsecs { get; set; }

Check warning on line 12 in MoEmbed.Core/Models/TwitterExperimental/EditControl.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'EditControl.EditableUntilMsecs'

[JsonPropertyName("is_edit_eligible")]
public bool IsEditEligible { get; set; }

Check warning on line 15 in MoEmbed.Core/Models/TwitterExperimental/EditControl.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'EditControl.IsEditEligible'

[JsonPropertyName("edits_remaining")]
public string EditsRemaining { get; set; }

Check warning on line 18 in MoEmbed.Core/Models/TwitterExperimental/EditControl.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'EditControl.EditsRemaining'
}
Expand Down
2 changes: 1 addition & 1 deletion MoEmbed.Core/Models/TwitterExperimental/Entities.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class Entities

Check warning on line 6 in MoEmbed.Core/Models/TwitterExperimental/Entities.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'Entities'
{
[JsonPropertyName("hashtags")]
public List<Hashtag> Hashtags { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class ExtMediaAvailability
{
Expand Down
2 changes: 1 addition & 1 deletion MoEmbed.Core/Models/TwitterExperimental/Hashtag.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class Hashtag
{
Expand Down
2 changes: 1 addition & 1 deletion MoEmbed.Core/Models/TwitterExperimental/Large.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class Large
{
Expand Down
3 changes: 1 addition & 2 deletions MoEmbed.Core/Models/TwitterExperimental/Media.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

// Tweet myDeserializedClass = JsonConvert.DeserializeObject<Tweet>(myJsonResponse);
namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class Media
{
Expand Down
2 changes: 1 addition & 1 deletion MoEmbed.Core/Models/TwitterExperimental/MediaDetail.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class MediaDetail
{
Expand Down
3 changes: 1 addition & 2 deletions MoEmbed.Core/Models/TwitterExperimental/Medium.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json.Serialization;

// Tweet myDeserializedClass = JsonConvert.DeserializeObject<Tweet>(myJsonResponse);
namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class Medium
{
Expand Down
3 changes: 1 addition & 2 deletions MoEmbed.Core/Models/TwitterExperimental/OriginalInfo.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json.Serialization;

// Tweet myDeserializedClass = JsonConvert.DeserializeObject<Tweet>(myJsonResponse);
namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class OriginalInfo
{
Expand Down
3 changes: 1 addition & 2 deletions MoEmbed.Core/Models/TwitterExperimental/Photo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

// Tweet myDeserializedClass = JsonConvert.DeserializeObject<Tweet>(myJsonResponse);
namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class Photo
{
Expand Down
3 changes: 1 addition & 2 deletions MoEmbed.Core/Models/TwitterExperimental/Sizes.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json.Serialization;

// Tweet myDeserializedClass = JsonConvert.DeserializeObject<Tweet>(myJsonResponse);
namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class Sizes
{
Expand Down
3 changes: 1 addition & 2 deletions MoEmbed.Core/Models/TwitterExperimental/Small.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json.Serialization;

// Tweet myDeserializedClass = JsonConvert.DeserializeObject<Tweet>(myJsonResponse);
namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class Small
{
Expand Down
3 changes: 1 addition & 2 deletions MoEmbed.Core/Models/TwitterExperimental/Thumb.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json.Serialization;

// Tweet myDeserializedClass = JsonConvert.DeserializeObject<Tweet>(myJsonResponse);
namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class Thumb
{
Expand Down
3 changes: 1 addition & 2 deletions MoEmbed.Core/Models/TwitterExperimental/Tweet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

// Tweet myDeserializedClass = JsonConvert.DeserializeObject<Tweet>(myJsonResponse);
namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class Tweet
{
Expand Down
3 changes: 1 addition & 2 deletions MoEmbed.Core/Models/TwitterExperimental/User.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Text.Json.Serialization;

// Tweet myDeserializedClass = JsonConvert.DeserializeObject<Tweet>(myJsonResponse);
namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class User
{
Expand Down
3 changes: 1 addition & 2 deletions MoEmbed.Core/Models/TwitterExperimental/UserMention.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

// Tweet myDeserializedClass = JsonConvert.DeserializeObject<Tweet>(myJsonResponse);
namespace MoEmbed.Models.TweetExperimental
namespace MoEmbed.Models.TwitterExperimental
{
public class UserMention
{
Expand Down