Hive Developer logo

Hive Developer Portal

RB: Search Tags

Performing a search for tags.

Full, runnable src of Search Tags can be downloaded as part of: tutorials/ruby (or download just this tutorial: devportal-master-tutorials-ruby-16_search_tags.zip).

This tutorial will return tags sorted by trending, up to a specified limit.

Also see:

Sections

  1. Making the api call - performing the lookup
    1. Example api call - make the call in code
    2. Example api call using script - using our tutorial script
    3. Example Output - output from a successful call
    4. Tag Fields - details of fields returned
  2. To Run - Running the example.

Making the api call

search_tags.rb

To request the a list of tags, we can use the get_trending_tags method:

api = Radiator::Api.new

api.get_trending_tags(nil, 100) do |tags|
  puts tags
end

Notice, the above example can request up to 100 tags as an array.

Example api call

If we want to get 10 tags starting from the tag named “music” …

api.get_trending_tags("music", 10) do |content| ...

Example api call using script

And to do the same with our tutorial script, which has its own default limit of 10. Internally, the api method only allows at most 100 results, so this tutorial will paginate the results to go beyond 100:

ruby search_tags.rb

Example Output

From the example we get the following output from our script:

tag: hive-148441, total_payouts: 13831.392 HBD, top_posts: 1716, comments: 3996
tag: hive-167922, total_payouts: 13735.647 HBD, top_posts: 1901, comments: 16164
tag: hive-105017, total_payouts: 4798.170 HBD, top_posts: 301, comments: 825
tag: hive-140217, total_payouts: 4513.385 HBD, top_posts: 385, comments: 692
tag: hive-120586, total_payouts: 4001.515 HBD, top_posts: 413, comments: 1435
tag: hive-194913, total_payouts: 3365.291 HBD, top_posts: 432, comments: 1480
tag: hive-163772, total_payouts: 3149.881 HBD, top_posts: 157, comments: 1155
tag: hive-129496, total_payouts: 2946.808 HBD, top_posts: 262, comments: 644
tag: hive-158489, total_payouts: 2938.784 HBD, top_posts: 135, comments: 1058
tag: hive-175254, total_payouts: 2651.732 HBD, top_posts: 196, comments: 1202

Tag fields

Tags in the results of get_trending_tags returns the following fields:

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 https://gitlab.syncad.com/hive/devportal.git
cd devportal/tutorials/ruby/16_search_tags
bundle install
ruby search_tags.rb [limit]