Ruby Steem tutorial 3 - Get Steem posts information

In the previous tutorial, we discussed how to get Steem account information via radiator, today we will learn how to get Steem post information, e.g. author, votes, pending payouts, also we will see how to vote a post in Ruby program. If you haven’t setup your development environments, please check my first tutorial.

Image credit to: pixabay.com

Read user’s most recent posts

FollowApi class can be used to access posts from a particular user, or from user’s feed. The following code will read a user’s latest three posts.

1
2
3
4
5
6
7
8
9
10
11
require 'radiator'
user = 'yuxid'
followapi = Radiator::FollowApi.new
# get latest posts from a particular user
posts = followapi.get_blog_entries(user, -1, 3)
for post in posts.result
puts post.permlink
end

Get latest posts from user’s feed

FollowApi can be used to get posts from user’s feed as well.

1
2
3
4
feeds = followapi.get_feed_entries(user, -1, 3)
for feed in feeds.result
puts '@' + feed.author + '/' + feed.permlink
end

Get posts by payout

We may be interested in the top posts in a particular category. For example, get top 5 posts by payout in utopian-io category:

1
2
3
4
5
6
7
8
9
10
11
dbapi = Radiator::DatabaseApi.new
posts = dbapi.get_post_discussions_by_payout({"tag":"utopian-io","limit":5})
for post in posts.result
puts '--------------'
puts post.author
puts post.title
puts post.created
puts post.pending_payout_value
puts post.url
puts post.net_votes
end

Get comments by payout

Comments work in the similar way to posts. To get comments by payout in utopian-io category:

1
2
3
4
5
6
7
8
9
comments = dbapi.get_comment_discussions_by_payout({"tag":"utopian-io","limit":5})
for comment in comments.result
puts '--------------'
puts comment.author
puts comment.created
puts comment.pending_payout_value
puts comment.url
puts comment.net_votes
end

vote

To cast a vote to a post, we need to get the private posting key. Replace PRIVATE_POSTING_KEY by your private posting key in the following code:

1
2
3
4
5
6
7
8
9
10
11
12
13
require 'radiator'
tx = Radiator::Transaction.new(wif: 'PRIVATE_POSTING_KEY')
vote = {
type: :vote,
voter: 'yuxid',
author: 'elear',
permlink: 'utopian-the-landing-page-is-finally-out-have-a-look',
weight: 10000
}
tx.operations << vote
tx.process(true)
Share