Ruby Programming Tutorial - Lesson 43 - EasySteem Ruby Api :) Talking to Steem blockchain
ruby·@bilal-haider·
0.000 HBDRuby Programming Tutorial - Lesson 43 - EasySteem Ruby Api :) Talking to Steem blockchain
# Radiator Is a ruby gem written by @inertia its an API to talk to steemit blockchain via ruby. We are going to further Easify this radiator Gem in here.. so that we can do something like this  Which should return us bilal-haider's 10 followers like so  > Create a Module which makes it easy to use Radiator gem :) <3 #### Creating a directory called Analyzer cd to this directory and install radiator and paint gems ``` gem install radiator ```  and also install paint gem, for give our text colors in terminal ``` gem install paint ```  You will see that, after creating an **EasySteem** module, how easily we can talk to steem blockchain ``` puts EasySteem.reblog_stream ``` will start a steam for us, where it will show us who is sharing whom posts at the moment :) like so  Lets start by analyzing what operations steem blockchain provides us :p - we can post - we can vote - we can transfer - we can claim rewards - we can flag - we can comment - we can watch streams :) > We don't have a lot of methods in this module, but we can extend it in upcoming articles. This way we can create an Easy Api to interact with steem blockchain Our module so far has only 7 methods in it :p thanks to my laziness You don't need to understand this code, if you don't want to.. you should be able to use it that's what matters :) ``` require 'radiator' require 'json' require 'paint' module EasySteem def EasySteem.supply api = Radiator::Api.new api.get_dynamic_global_properties do |properties| properties.virtual_supply end end def EasySteem.followers(*options) api = Radiator::FollowApi.new if options[2] == nil _start = 0 elsif _start = options[2] end api.get_followers(options[0], _start, 'blog', options[1]) do |followers| followers.map(&:follower) end end def EasySteem.voting_stream stream = Radiator::Stream.new stream.operations(:vote) do |op| print "#{op.voter} voted for #{op.author}" puts " (weight: #{op.weight / 100.0}%)" end end def EasySteem.comment_stream stream = Radiator::Stream.new stream.operations(:comment) do |op| if op.parent_author != "" print "#{op.author} commented on #{op.parent_author}\'s Post. " puts "Permlink: #{op.parent_permlink}" elsif print "#{op.author} commented on a Post. \n" puts "Permlink: #{op.permlink}" end end end def EasySteem.follow_stream stream = Radiator::Stream.new stream.operations(:custom_json) do |op| if op.id == "follow" _myhash = JSON.parse(op.json) if _myhash[0] == "follow" _info = _myhash[1] puts "#{Paint[_info['follower'], :red]} has followed #{Paint[_info['following'], :green]}" end end end end def EasySteem.reblog_stream stream = Radiator::Stream.new stream.operations(:custom_json) do |op| if op.id == "follow" _myhash = JSON.parse(op.json) # p _myhash if _myhash[0] == "reblog" _info = _myhash[1] puts "#{Paint[_info['account'], :green]} has shared #{Paint[_info['author'], :cyan]}\'s Post" end end end end def EasySteem.stream stream = Radiator::Stream.new stream.operations do |op| puts op end end end ``` Once you have gems installed an you also have EasySteem module. you are ready to use it like so ``` require_relative 'easysteem' puts EasySteem.supply ``` Which returns virtual Steem supply .. ## get reblogs stream ``` require_relative 'easysteem' puts EasySteem.reblog_stream ``` which outputs  ## Get followers of a person ``` require_relative 'easysteem' ## returns bilal-haider's 10 followers puts EasySteem.followers "bilal-haider", 10 ## returns bilal-haider's 10 followers starting from "a-0-a" puts EasySteem.followers "bilal-haider", 10, "a-0-a" ```  ## Get virtual Steem Supply ``` require_relative 'easysteem' puts EasySteem.supply ```  ## Get following stream.. see who is following whom at real time ``` require_relative 'easysteem' puts EasySteem.follow_stream ```  ``` require_relative 'easysteem' puts EasySteem.follow_stream puts EasySteem.supply puts EasySteem.followers "bilal-haider", 100 puts EasySteem.stream puts EasySteem.voting_stream puts EasySteem.comment_stream puts EasySteem.follow_stream puts EasySteem.reblog_stream ``` These are few other Methods which you can call using EasySteem I hope you liked it. ;) 