Skip to content

Instantly share code, notes, and snippets.

View jasongaylord's full-sized avatar
⏲️
Trying to find time to code.

Jason N. Gaylord jasongaylord

⏲️
Trying to find time to code.
View GitHub Profile
public class RetrieveTweetsViewComponent : ViewComponent
{
protected TwitterOptions TwitterOptions { get; private set; }
public RetrieveTweetsViewComponent(IOptions<TwitterOptions> options = null)
{
if (options != null)
TwitterOptions = options.Value;
else
TwitterOptions = new TwitterOptions();
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ViewFeatures" Version="2.1.3" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.1" />
public class TwitterOptions
{
[Required]
public string ConsumerKey { get; set; } = "";
[Required]
public string ConsumerSecret { get; set; } = "";
public string Username { get; set; }
}
public class Token
{
public string access_token { get; set; }
}
public class TweetRaw
{
public string id_str { get; set; }
public string text { get; set; }
public string created_at { get; set; }
public string in_reply_to_screen_name { get; set; }
public UserRaw user { get; set; }
}
public class UserRaw
public class Tweet
{
public string Username { get; set; }
public string Message { get; set; }
public string Avatar { get; set; }
public string Timestamp { get; set; }
public string Id { get; set; }
}
public interface ITwitterService
{
string ObtainBearerToken(string consumerKey, string consumerSecret);
Task<List<Tweet>> RetrieveTweetsAsync(TwitterOptions options);
}
public class TwitterService : ITwitterService
{
public string ObtainBearerToken(string consumerKey, string consumerSecret)
{
var applicationAuthorization = Convert.ToBase64String(Encoding.UTF8.GetBytes(string.Format("{0}:{1}", Uri.EscapeDataString(consumerKey), Uri.EscapeDataString(consumerSecret))));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.twitter.com/oauth2/token");
request.Headers.Add("Authorization", "Basic " + applicationAuthorization);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
@jasongaylord
jasongaylord / droptables.sql
Created November 12, 2018 18:22
Drop All Cloudscribe Tables
drop table dbo.cs_UserToken;
drop table dbo.cs_UserRole;
drop table dbo.cs_UserLogin;
drop table dbo.cs_UserLocation;
drop table dbo.cs_UserClaim;
drop table dbo.cs_User;
drop table dbo.cs_SystemLog;
drop table dbo.cs_SiteHost;
drop table dbo.cs_Site;
drop table dbo.cs_Role;
@jasongaylord
jasongaylord / youtube.cs
Created February 20, 2019 04:23
YouTube API Connection
public List<Google.Apis.YouTube.v3.Data.SearchResult> LatestVideos()
{
var youTubeService = new YouTubeService(
new BaseClientService.Initializer() {
ApplicationName = "{Project}",
ApiKey = "{API_key}"
}
);
var listRequest = youTubeService.Search.List("snippet");