DEV Community

Cover image for View Count Day 2 -- Collecting Data
Corey Alexander
Corey Alexander

Posted on View Count Day 2 -- Collecting Data

Took a break for a few days but back at it today for Day 2 of this Hackathon!

Last time I decided that I would use Rails, so today, let's start setting up a Rails app. We'll start on the backend for collecting the data from the API, and we'll make our way to the front-end later.

To get started, I generated a Rails app using the rails new CLI.
Commit: 53c6c89c

From here, I installed DelayedJob and DelayedJobActiveRecord, which are my default tools for running background jobs in Rails. I do this in my database to avoid running a separate service and I also get co-transactionality between my business logic and my job enqueuing. I'm really just using it for this project since it's what I'm most familiar with, and I don't want to have to spin up something like Redis if I can avoid it.
Commit: 3ecd413

Now let's set up the models we need! For the moment, we are going to have a single user, so we aren't even going to model that, and just go right into Articles. Articles matches the terminology used in the API docs, so that is what I ended up naming the table. Here we record the name and a few other pieces of data about the articles.
Commit: 1fae1ad

Since that we have a model, it's time to start hitting the API and getting some data. So I created a simple job to hit the articles/me route and persist each article to the DB. Here I took the time to make sure pagination worked nicely to grab any number of articles. I might have been able to do this later, but I wanted to solve it while I was thinking about it and playing with the API.
Commit: 31b4a99

Next, I needed a model to actually hold the view and comment count data. This needs to be separate from Article cause we need to keep a historical record of the statistics. I created the ArticleStats table, such that a single Article will have many ArticleStats.
I also augmented the job I created before to generate a new Stat row on each run.
Commit: 99c8765

And with all that, I'm gonna call it a day! Looking forward to the next time I work on this, I think we'll be ready to try getting this hosted on the Digital Ocean App Platform.
Check back for more updates soon!

Photo by Gia Oris on Unsplash

Top comments (3)

raddevus profile image

Good to see forward progress. Keep up the good work. Would you help me out with understanding the markup to create that series list that you've added. I can't find the markup anywhere. If you would reply to this message with the markup syntax for the series that you have in this article I would greatly appreciate it. Thx

coreyja profile image
Corey Alexander • Edited

I've been using the 'UI' to do it instead of Markdown but I can show you how!

Get to the editor for a post, either by editing or making a new one.

Edit a post

Then go to this gear at the bottom, next to 'Save/Publish'

Gear Icon on Post Editor

Which opens this modal which has the series settings!

Settings Modal

Once you make a series name or select an existing one you'll want to save/publish the post to make it 'stick'!

raddevus profile image

thanks, I couldn't find out how to do that anywhere. I will try it out.