Hive Developer logo

Hive Developer Portal

RB: Get Posts

This example will output posts depending on which category is provided as the arguments.

Full, runnable src of Get Posts can be downloaded as part of: tutorials/ruby (or download just this tutorial:

Also see:



This script will pick a method to call based on the arguments passed. The expected categories are:

We will base the name of the API method to execute on the provided argument. Once we know which method to execute, we can build the query options. The defaults for this script is limit: 10 and tag: ''.

For each post we retrieve, we are going to build up a summary to display the interesting fields. In this case, we’re interested in:

To Run

First, set up your workstation using the steps provided in Getting Started. Then you can create and execute the script (or clone from this repository):

git clone
cd devportal/tutorials/ruby/04_get_posts
bundle install
ruby get_posts_by_category.rb trending 1 hive

Example Output

2021-03-17 15:47:36 UTC
  Post: Introducing DEC Farming on Cub Finance | Changes to Dens/Farms, 24 Hours Left for Wrapping CUB
  By: leofinance
  Replies: 81
  Promoted: 0.000 HBD
  Words: 1331

Error Handling

We’re checking the result for error in case the remote node has an issue to raise. Normally, it will be nil, but if it’s populated, output error.message and exit.