Steam Top Sellers CLI Gem
In my process of learning Ruby, I’ve been working on a CLI gem that I’ll discuss here. My goal was to create a command line interface that could retrieve a list of the currently top selling games at the Steam Store. Upon retrieving the list, the user would then be able to select a game and get more detailed information.
The original intention was to organize the project through three classes: a Scraper
, Game
, and CLI
. The Scraper would be responsible for scraping the data from the Steam website. The Game
class would be used to instantiate objects for each game based on data retrieved by the Scraper
. The CLI
would then be used to tie the other classes together and create an interface for the user to interact with this data. In execution, most of this would go according to plan, but there would be some changes necessary.
I initially used Nokogiri for the Scraper
class, then manually navigated through the CSS selectors on the Steam Store frontpage as well as the individual game pages. It was a tedious process, but worked well enough to acquire the necessary data. However, two major roadblocks soon arose:
1) For certain games, the Steam Store would put up an age verification page before allowing the user to continue to the game page, and when using Open-URI to access the page, it would be blocked. I looked into ways of getting around the age verification and it involved creating a cookie, but that was out of scope of what I wanted to accomplish with the project.
2) As soon as I finished the Scraper
methods, the Steam Store changed its entire website and CSS structure for its holiday sale, and rewriting the methods temporarily only to revert to the old methods when the sale was over seemed tedious and inefficient.
So after doing some research, I was able to find a better way: leveraging the Steam Storefront API. I created a new class, SteamAPIHandler
, to acquire the JSON data and parse it, using the data to create Game
objects that could then interact with the CLI
. This allowed me access to a much larger amount of data and proved to be much more efficient as well. For example, here’s an old Scraper
method:
…compared to a new SteamAPIHandler
method that accomplishes the same thing:
In practice, the CLI
, upon loading, uses the SteamAPIHandler
to acquire the top sellers and create Game
objects from the data. It prints out the information on the screen, then, when the user selects a game to get more information on, the CLI
uses the SteamAPIHandler
to acquire additional data and print it out. I had a method that acquired the additional information as soon as the CLI
loaded, but it caused additional load time as it had to make ten queries to the API in succession, as opposed to one at a time where the load time is much less noticeable.
Overall, it was a good learning experience and I accomplished what I had set out to do. You can see the source code for this project here on Github.