Skip to content

RagtimeWilly/Rxddit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Build Status NuGet

.NET Client for reddit utilizing Reactive Extensions

Installing from NuGet

PM> Install-Package Rxddit

Polling Client

The polling client exposes an IObservable<RedditPostData> which will be populated with new post data from a specified subreddit peridodically.

For example, the below code polls /r/funny for new posts every 10 seconds:

var reddit = new RedditClient(() => new HttpClient());

Action<Exception> onError = (ex) => { Console.WriteLine($"An error occurred: {ex}"); };

var pollingClient = new RedditPollingClient(reddit, "funny", TimeSpan.FromSeconds(10), onError);

var resetEvent = new ManualResetEvent(false);

var subscription = pollingClient
  .Posts
  .Subscribe(
    x => Console.WriteLine($"New post: {x.Title}"),
    ex =>
    {
        Console.WriteLine($"Error while retrieving reddit posts: {ex.Message}");
        resetEvent.Set();
    },
    () =>
    {
        Console.WriteLine("Finished retrieving posts");
        resetEvent.Set();
    });

pollingClient.Start();

resetEvent.WaitOne();

Historical Client

The historical client will retrieve post data for a specified subreddit back to a specified date (or until it runs out of posts) and expose them as a IObservable<RedditPostData>.

For example, the below code will retrieve all posts back to 2017-03-01 from /r/music:

var reddit = new RedditClient(() => new HttpClient());

Action<Exception, string> onError = (ex, s) => { Console.WriteLine($"An error occurred: {s} : {ex}"); };

var historicalClient = new RedditHistoricalClient(reddit, "music", new DateTime(2017, 03, 03), onError);

var subscription = historicalClient
  .Posts
  .Subscribe(
    x => Console.WriteLine($"Post found: {x.Title}"),
    ex =>
    {
        Console.WriteLine($"Error while retrieving reddit posts: {ex.Message}");
        resetEvent.Set();
    },
    () =>
    {
        Console.WriteLine("Finished retrieving posts");
        resetEvent.Set();
    });

historicalClient.Start();

Getting help

If you have any problems or suggestions please create an issue or a pull request

About

.NET client for reddit utilizing Reactive Extensions

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages