I regularly pursue education and self-improvement in my off-time. This time, I decided to dedicate my weekend to create a CLI that provides access to scraped data that lives on a website using the Nokogiri gem.
Since I’m in the process of creating a new Shopify app, and I know that app reviews are crucial to the growth of Shopify apps, I decided that my project would expose Shopify’s apps and give access to those apps most recent reviews.
The CLI essentials for the project were to:
- Have a CLI for interfacing with the application;
- Pull data from an external source;
- Implement both list and detail views. The data provided must go at least one level deep; and
- The application is pretty DRY.
The technical goals of this project were to highlight the learnings made over the last 7 seven weeks so far:
- Basic control flow — how “if” statements work
- Variable scopes — method, instance and class
- Object instantiation — #new (and possibly #initialize)
- The meaning of the “self” keyword
- Method types — class vs. instance methods
- Method return types — knowing what methods return
- Iterating through collections — at least using #each with a block
The basic flow of the app is to welcome the user and take an input right away. The CLI user can search for a Shopify app either by name or by URL, which rely on the
ShopifyApp.find_by_url class methods.
When an input is received, the CLI will immediately attempt to return an App Detail view listing the app’s most relevant information. From this App Detail view, a sub-menu is provided to give access to the app’s 10 most recent reviews, as well as some basic sentiment analysis on the app’s overall rating as well as the 10 latest reviews.
The data from the app comes from two separate sources; a nifty list of all Shopify App Stores to grab all of the store’s apps and of course the Shopify App Store itself to traverse and grab the 10 most recent reviews from each app on the Shopify App Store.
The order of execution is to:
(1) instantiate a new
ShopifyApp object and to provide it with as much information as is available from the page listing all apps — including the ShopifyApp
(2) leverage each app’s
:developer_url to traverse the Shopify App Store and collect the ten most recent reviews and return those as hashes
(3) instantiate a new
AppReview object for each hash provided in #2 and assign it to the app itself. This completes the OO relationship
(4) from there, the CLI enables access to both of these objects and their relationships to each other through terminal commands.
The idea is to provide this functionality within an object-oriented context, such that the
ShopifyApps and the
AppReviews are objects which can be interacted with and extended upon.
Launch the CLI by navigating to the root of the project and running
Version 0.2.0 introduces basis sentiment analysis for apps and reviews. When an app has been found, it will automatically display its overall sentiment. This information can also be reaccessed using
$ overall sentiment
Once you access an app’s reviews using
$ latest reviews you can then call
$ trending sentiment to return the way people feel about an app lately, rather than overall. This data is calculated from the 10 latest reviews collected. This information will also be appended to the
app details table.
An obvious iteration for the next version will be to make use of the mechanize ruby gem to interact with objects on pages (i.e. click on buttons).
This will enable me to use the same logic but to iterate it across each page which contains reviews. Once apps have all of their reviews attached rather than just a sample of the latest 10, additional functionality will be possible such as macro-level methods to return data across all Shopify Apps, and more complex sentiment analysis, such as word clouds and so on.
Bug reports and pull requests are welcome on the project’s GitHub repository. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.