Skip to content

wgillingham/jhaCC_wgillingham

Repository files navigation

A Code Exercise using .Net Core 3.1 and Twitter API

In a nutshell, gather some stats from a sample of the twitter stream via the Sampled stream API.

Important

You must supply you own twitter bearer token.

Your twitter bearer token must be placed in appsettings.json (/jhaCC_Console/appsettings.json or appsettings.DEVELOPMENT.json)

      "Services": {
        "Monitor": {
          "MessageMonitorTwitter": {
            "TwitterBearerToken": "*** YOUR TOKEN HERE ***"
          }
        }
      }

Solution file (jhaCC_wgillingham.sln) contains three project

jhaCC_Lib - Library of objects required to digest twitter feed

  • Models

    • FeedDataBase.cs - Base class to contain data gleened from feed
    • FeedDataTwitter.cs - Inherits from FeedDataBase.cs and overrides ConsumeMessageDetails - which accepts MessageDetails. We accumulate based on this data
    • KeyAccumulator.cs - wrapper arround ConcurrentDictionary that allows us to store values/counts (used for stats on emojis, hashtags, urls)
    • MessageDetails.cs - Container object for what was gleened from a single message
  • Resources

    • emojiRegEx.txt - a regex string from https://github.com/Felk/UnicodeEmojiRegex and is Copyright (c) 2020 Felix König. I simply generated and used the regex string from the aformentioned project. The project could be incorportated directly into an application to create the regex string on demand.
  • Services

    • Distiller
      • IMessageDistiller.cs - interface exposing method DistillMessageAsync and ConsumeMessageAsync.
      • MessageDistillerTwitter.cs - implentation of IMessageDistiller for twitter feed
    • Monitor
      • IMessageMonitor.cs - interface exposing method RetrieveMessagesAsync - used to retrieve messages in whatever manner you see fit
      • MessageMonitorBackgroundService.cs - BackgroundService. Expects IMessageMonitor instance injected and will process via RetrieveMessagesAsync()
      • MessageMonitorTwitter.cs - implentation of IMessageMonitor. streams https://api.twitter.com/2/tweets/sample/stream and processes messages via injected IMessageDistiller instance
    • Reporting
      • AutoReportBackgroundService.cs - BackgroundService. Executes injected implentation of IAutoReport (calls its RenderReport method on a schedule)
      • AutoReportConsole.cs - Implentation of IAutoReport. Renders stats from injected FeedDataBase to the console (RenderReport())
      • IAutoReport.cs - interface exposing RenderReport method. Expected to render a report on a schedule (i.e. ever 20 seconds)
      • ReportListenerBackgroundService.cs - BackgroundService. Cheap report via http://localhost:8888 (configured via appsettings.json)

jhaCC_Console - this is your best option to execute as a demo

  • Program.cs - References jhaCC_Lib. ConfigureServices and runs the host. See console for output. Also http://localhost:8888 (by default) for 2% fancier output.

jhaCC_Test (XUnit implentation)

  • DistillTwitterMessageTestData.cs - testdata container for MessageDistillerTests - for use as [ClassData] exposed data
  • MessageDistillerTests.cs - simple test case example. 6 instances of DistillTwitterMessageTestData are individually sent to DistillTwitterMessageResultsVerified. Simple test to count number of emojis/hashtags/domains expected and found in each message

About

Exercise in .Net Core 3.1 using Twitter API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages