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

Add media v2 variants #1198

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 6 additions & 5 deletions src/Tweetinvi.AspNet/Tweetinvi.AspNet.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>5.0.4</VersionPrefix>
Expand All @@ -7,7 +7,7 @@
<AssemblyOriginatorKeyFile>../tweetinvi.snk</AssemblyOriginatorKeyFile>
<AssemblyName>Tweetinvi.AspNet</AssemblyName>
<RootNamespace>Tweetinvi.AspNet</RootNamespace>
<TargetFrameworks>netstandard2.0;netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp2.1;netcoreapp3.1;net6.0</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>1591</NoWarn>
</PropertyGroup>
Expand Down Expand Up @@ -46,12 +46,13 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Tweetinvi.Core\Tweetinvi.Core.csproj" />
<ProjectReference Include="..\Tweetinvi\Tweetinvi.csproj" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.0" />
</ItemGroup>

<ItemGroup>

<ProjectReference Include="..\Tweetinvi\Tweetinvi.csproj" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions src/Tweetinvi.Controllers/Tweet/TweetsV2Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ public Task<ITwitterResult<TweetHideV2Response>> ChangeTweetReplyVisibilityAsync
{
return _queryExecutor.ChangeTweetReplyVisibilityAsync(parameters, request);
}

public Task<ITwitterResult<TweetV2Response>> PublishTweetAsync(IPublishTweetV2Parameters parameters, ITwitterRequest request)
{
return _queryExecutor.PublishTweetAsync(parameters, request);
}
}
}
10 changes: 10 additions & 0 deletions src/Tweetinvi.Controllers/Tweet/TweetsV2QueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public interface ITweetsV2QueryExecutor
Task<ITwitterResult<TweetV2Response>> GetTweetAsync(IGetTweetV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<TweetsV2Response>> GetTweetsAsync(IGetTweetsV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<TweetHideV2Response>> ChangeTweetReplyVisibilityAsync(IChangeTweetReplyVisibilityV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<TweetV2Response>> PublishTweetAsync(IPublishTweetV2Parameters parameters, ITwitterRequest request);
}

public class TweetsV2QueryExecutor : ITweetsV2QueryExecutor
Expand Down Expand Up @@ -54,5 +55,14 @@ public Task<ITwitterResult<TweetHideV2Response>> ChangeTweetReplyVisibilityAsync
request.Query.HttpContent = _jsonContentFactory.Create(content);
return _twitterAccessor.ExecuteRequestAsync<TweetHideV2Response>(request);
}

public Task<ITwitterResult<TweetV2Response>> PublishTweetAsync(IPublishTweetV2Parameters parameters, ITwitterRequest request)
{
request.Query.HttpMethod = HttpMethod.POST;
request.Query.Url = _tweetQueryGenerator.GetTweetQuery(parameters);
request.Query.HttpContent = _jsonContentFactory.Create(parameters);
var stringContent = request.Query.HttpContent.ReadAsStringAsync().Result;
return _twitterAccessor.ExecuteRequestAsync<TweetV2Response>(request);
}
}
}
11 changes: 11 additions & 0 deletions src/Tweetinvi.Controllers/Tweet/TweetsV2QueryGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,16 @@ public void AddTweetFieldsParameters(IBaseTweetsV2Parameters parameters, StringB
query.AddParameterToQuery("tweet.fields", parameters.TweetFields);
query.AddParameterToQuery("user.fields", parameters.UserFields);
}

/// <summary>
/// Publish a tweet V2
/// </summary>
/// <param name="parameters"></param>
/// <returns></returns>
public string GetTweetQuery(IPublishTweetV2Parameters parameters)
{
var query = new StringBuilder($"{Resources.TweetV2_Get}");
return query.ToString();
}
}
}
2 changes: 2 additions & 0 deletions src/Tweetinvi.Core/Core/Controllers/V2/ITweetsV2Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Tweetinvi.Core.Web;
using Tweetinvi.Models;
using Tweetinvi.Models.V2;
using Tweetinvi.Parameters;
using Tweetinvi.Parameters.V2;

namespace Tweetinvi.Core.Controllers.V2
Expand All @@ -11,5 +12,6 @@ public interface ITweetsV2Controller
Task<ITwitterResult<TweetV2Response>> GetTweetAsync(IGetTweetV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<TweetsV2Response>> GetTweetsAsync(IGetTweetsV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<TweetHideV2Response>> ChangeTweetReplyVisibilityAsync(IChangeTweetReplyVisibilityV2Parameters parameters, ITwitterRequest request);
Task<ITwitterResult<TweetV2Response>> PublishTweetAsync(IPublishTweetV2Parameters parameters, ITwitterRequest request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Newtonsoft.Json;

using System.Diagnostics;

using Tweetinvi.Models.Entities.ExtendedEntities;

namespace Tweetinvi.Core.Models.TwitterEntities.ExtendedEntities;

[DebuggerDisplay("ContentType: {ContentType} Url: {URL}")]
public class MediaEntityVariantV2 : IVideoEntityVariant
{
[JsonProperty("bit_rate")]
public int Bitrate { get; set; }
[JsonProperty("content_type")]
public string ContentType { get; set; }
[JsonProperty("url")]
public string URL { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface ITweetsV2QueryGenerator
string GetTweetsQuery(IGetTweetsV2Parameters parameters);
string GetChangeTweetReplyVisibilityQuery(IChangeTweetReplyVisibilityV2Parameters parameters);
void AddTweetFieldsParameters(IBaseTweetsV2Parameters parameters, StringBuilder query);
string GetTweetQuery(IPublishTweetV2Parameters parameters);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Threading.Tasks;
using Tweetinvi.Models.V2;
using Tweetinvi.Parameters;
using Tweetinvi.Parameters.V2;

namespace Tweetinvi.Client.V2
Expand All @@ -12,6 +13,8 @@ public interface ITweetsV2Client
/// <inheritdoc cref="GetTweetAsync(IGetTweetV2Parameters)"/>
Task<TweetV2Response> GetTweetAsync(string tweetId);

Task<TweetV2Response> PublishTweetAsync(IPublishTweetV2Parameters parameters);

/// <summary>
/// Get a tweet
/// <para>Read more : https://developer.twitter.com/en/docs/twitter-api/tweets/lookup/api-reference/get-tweets-id </para>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Tweetinvi.Core.Web;
using Tweetinvi.Models.V2;
using Tweetinvi.Parameters;
using Tweetinvi.Parameters.V2;

namespace Tweetinvi.Client.Requesters.V2
Expand All @@ -10,5 +11,6 @@ public interface ITweetsV2Requester
Task<ITwitterResult<TweetV2Response>> GetTweetAsync(IGetTweetV2Parameters parameters);
Task<ITwitterResult<TweetsV2Response>> GetTweetsAsync(IGetTweetsV2Parameters parameters);
Task<ITwitterResult<TweetHideV2Response>> ChangeTweetReplyVisibilityAsync(IChangeTweetReplyVisibilityV2Parameters parameters);
Task<ITwitterResult<TweetV2Response>> PublishTweetAsync(IPublishTweetV2Parameters parameters);
}
}
10 changes: 10 additions & 0 deletions src/Tweetinvi.Core/Public/Models/V2/MediaV2.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using Newtonsoft.Json;

using System.Diagnostics;

using Tweetinvi.Core.Models.TwitterEntities.ExtendedEntities;

namespace Tweetinvi.Models.V2
{
/// <summary>
/// A media, video, image, gif...
/// <para>Read more here : https://developer.twitter.com/en/docs/twitter-api/data-dictionary/object-model/media </para>
/// </summary>
[DebuggerDisplay("Type: {Type} MediaKey: {MediaKey}")]
public class MediaV2
{
/// <summary>
Expand Down Expand Up @@ -43,6 +48,11 @@ public class MediaV2
/// </summary>
[JsonProperty("width")] public int Width { get; set; }

/// <summary>
/// Each media object may have multiple display or playback variants, with different resolutions or formats
/// </summary>
[JsonProperty("variants")] public MediaEntityVariantV2[] Variants { get; set; }

/************* METRICS ************/

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class TweetIncludesV2
/// <summary>
/// Medias associated with the tweets, like the images attached.
/// </summary>
[JsonProperty("media")] public MediaV2[] Media { get; set; }
[JsonProperty("media")] public MediaV2[] Medias { get; set; }

/// <summary>
/// Places associated with the tweets
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Newtonsoft.Json;

using Tweetinvi.Core.Models.TwitterEntities.ExtendedEntities;

namespace Tweetinvi.Models.V2
{
public class TweetEntitiesV2
Expand Down Expand Up @@ -31,5 +33,7 @@ public class TweetEntitiesV2
/// Urls found in the tweet.
/// </summary>
[JsonProperty("urls")] public UrlV2[] Urls { get; set; }

[JsonIgnore] public MediaV2[] Medias { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ public class TweetV2Response
/// but which did not prevent the request to be resolved.
/// </summary>
[JsonProperty("errors")] public ErrorV2[] Errors { get; set; }

/// <summary>
/// The Tweet referenced in the response.
/// </summary>
[JsonIgnore] public TweetV2 QuotedTweet { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Tweetinvi.Core/Public/Models/V2/TweetV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,10 @@ public class TweetV2
/// Public engagement metrics for the Tweet at the time of the request.
/// </summary>
[JsonProperty("public_metrics")] public TweetPublicMetricsV2 PublicMetrics { get; set; }

/// <summary>
/// Author of the Tweet
/// </summary>
[JsonIgnore] public UserV2 TweetAuthor { get; set; }
}
}
5 changes: 5 additions & 0 deletions src/Tweetinvi.Core/Public/Models/V2/UserV2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public class UserV2
/// </summary>
[JsonProperty("profile_image_url")] public string ProfileImageUrl { get; set; }

/// <summary>
/// The URL to this user's profile banner.
/// </summary>
[JsonProperty("profile_banner_url")] public string ProfileBannerUrl { get; set; }

/// <summary>
/// Indicates if this user has chosen to protect their Tweets (in other words, if this user's Tweets are private).
/// </summary>
Expand Down
Loading
Loading