Skip to content

Commit

Permalink
Added support for parameters for the "verify_credentials" method
Browse files Browse the repository at this point in the history
  • Loading branch information
abjerner committed Dec 4, 2016
1 parent ad835b6 commit d4d6226
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Skybrud.Social/Skybrud.Social.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@
<Compile Include="Twitter\Endpoints\Raw\TwitterFavoritesRawEndpoint.cs" />
<Compile Include="Twitter\Enums\TwitterListMode.cs" />
<Compile Include="Twitter\Objects\Lists\TwitterList.cs" />
<Compile Include="Twitter\Options\Account\TwitterVerifyCrendetialsOptions.cs" />
<Compile Include="Twitter\Options\Favorites\TwitterGetFavoritesOptions.cs" />
<Compile Include="Twitter\Endpoints\Raw\TwitterSearchRawEndpoint.cs" />
<Compile Include="Twitter\Endpoints\TwitterSearchEndpoint.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Skybrud.Social.Http;
using Skybrud.Social.Twitter.OAuth;
using Skybrud.Social.Twitter.Options.Account;

namespace Skybrud.Social.Twitter.Endpoints.Raw {

Expand Down Expand Up @@ -31,6 +32,13 @@ public SocialHttpResponse VerifyCredentials() {
return Client.DoHttpGetRequest("https://api.twitter.com/1.1/account/verify_credentials.json");
}

/// <see>
/// <cref>https://dev.twitter.com/rest/reference/get/account/verify_credentials</cref>
/// </see>
public SocialHttpResponse VerifyCredentials(TwitterVerifyCrendetialsOptions options) {
return Client.DoHttpGetRequest("https://api.twitter.com/1.1/account/verify_credentials.json", options);
}

#endregion

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Skybrud.Social.Twitter.Endpoints.Raw;
using Skybrud.Social.Twitter.Options.Account;
using Skybrud.Social.Twitter.Responses;

namespace Skybrud.Social.Twitter.Endpoints {
Expand Down Expand Up @@ -38,6 +39,13 @@ public TwitterUserResponse VerifyCredentials() {
return TwitterUserResponse.ParseResponse(Raw.VerifyCredentials());
}

/// <summary>
/// Verify and get information about the user authenticated user (requires an access token).
/// </summary>
public TwitterUserResponse VerifyCredentials(TwitterVerifyCrendetialsOptions options) {
return TwitterUserResponse.ParseResponse(Raw.VerifyCredentials(options));
}

#endregion

}
Expand Down
12 changes: 11 additions & 1 deletion src/Skybrud.Social/Twitter/Objects/TwitterUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,15 @@ public int FavoritesCount {
/// </summary>
public TwitterUserEntities Entities { get; private set; }

/// <summary>
/// Gets the email of the user. The email is only included in the response when using the
/// <code>verify_credentials</code> in the account endpoint with the right parameters.
/// </summary>
/// <see>
/// <cref>https://dev.twitter.com/rest/reference/get/account/verify_credentials</cref>
/// </see>
public string Email { get; private set; }

#endregion

#region Constructors
Expand Down Expand Up @@ -293,7 +302,8 @@ public static TwitterUser Parse(JsonObject obj) {
ProfileSidebarBorderColor = obj.GetString("profile_sidebar_border_color"),
ProfileSidebarFillColor = obj.GetString("profile_sidebar_fill_color"),
ProfileTextColor = obj.GetString("profile_text_color"),
ProfileUseBackgroundImage = obj.GetBoolean("profile_use_background_image")
ProfileUseBackgroundImage = obj.GetBoolean("profile_use_background_image"),
Email = obj.GetString("email")
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Skybrud.Social.Http;
using Skybrud.Social.Interfaces;

namespace Skybrud.Social.Twitter.Options.Account {

/// <summary>
/// Options for a call to verify the authenticated user (or the <em>credentials</em> of the user).
/// </summary>
/// <see>
/// <cref>https://dev.twitter.com/rest/reference/get/account/verify_credentials</cref>
/// </see>
public class TwitterVerifyCrendetialsOptions : IGetOptions {

#region Properties

/// <summary>
/// Gets or sets whether entities should be included in the response. Default is <code>true</code>.
///
/// Notice that both the user object and the status object will have their own <code>entities</code> property.
/// The Twitter API documentation doesn't this further, but at the time of writing, this property only seems to
/// effect the <code>entities</code> property on the status object.
/// in the API documentation.
/// </summary>
public bool IncludeEntities { get; set; }

/// <summary>
/// Gets or sets whether the latest tweet (status message) of the user should be skipped in the response.
/// Default is <code>false</code> (meaning it is included by default).
/// </summary>
public bool SkipStatus { get; set; }

/// <summary>
/// Gets or sets the email of the authenticated user should be included in the response. Default is
/// <code>false</code>.
///
/// Notice that this qill require the <strong>Request email addresses from users</strong> option to be enabled
/// in the settings of your Twitter app.
/// </summary>
public bool IncludeEmail { get; set; }

#endregion

#region Constructors

/// <summary>
/// Initializes a new instance with default options.
/// </summary>
public TwitterVerifyCrendetialsOptions() {
IncludeEntities = true;
}

#endregion

#region Member properties

public SocialQueryString GetQueryString() {
SocialQueryString query = new SocialQueryString();
if (!IncludeEntities) query.Add("include_entities", "false");
if (SkipStatus) query.Add("skip_status", "true");
if (IncludeEmail) query.Add("include_email", "true");
return query;
}

#endregion

}

}

0 comments on commit d4d6226

Please sign in to comment.