Ruby Programming Tutorial - Lesson 43 - EasySteem Ruby Api :) Talking to Steem blockchain

View this thread on: d.buzz | hive.blog | peakd.com | ecency.com
·@bilal-haider·
0.000 HBD
Ruby 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

![Screenshot from 2018-04-02 03-53-50.png](https://steemitimages.com/DQmRrx6JxQ5x74DegU95cpNoWmGWeSzTSUPcUWHPYGDQB6G/Screenshot%20from%202018-04-02%2003-53-50.png)

Which should return us bilal-haider's 10 followers 
like so
![Screenshot from 2018-04-02 03-54-58.png](https://steemitimages.com/DQmQLpygfEZk5ovx9km5ncATb5BkHi271bPJ78ZAY2jtL92/Screenshot%20from%202018-04-02%2003-54-58.png)

> 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 ```
![Screenshot from 2018-04-02 01-46-34.png](https://steemitimages.com/DQmPFGDPTA6DfEkUXK4YzzjjmTZih3Bh5MYHDbHDrwcjN8M/Screenshot%20from%202018-04-02%2001-46-34.png)

and also install paint gem, for give our text colors in terminal

``` gem install paint ```
![Screenshot from 2018-04-02 02-48-01.png](https://steemitimages.com/DQmVsHRrMHwsB1uC79NDP8ymTJFG6EfvNAC8JuQS1k5svMc/Screenshot%20from%202018-04-02%2002-48-01.png)

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
![Screenshot from 2018-04-02 03-36-52.png](https://steemitimages.com/DQmQYKVHXeWigjQKwm5Nuun2BnGsMxDJ41Z6SNE4mtqdZj7/Screenshot%20from%202018-04-02%2003-36-52.png)


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
![Screenshot from 2018-04-02 03-47-57.png](https://steemitimages.com/DQmfSdAzDBfWvNTrfMrpVyXmZCQ9HLftAdSK3xSKzpNEknr/Screenshot%20from%202018-04-02%2003-47-57.png)

## 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"

```
![Screenshot from 2018-04-02 03-51-57.png](https://steemitimages.com/DQmcanjvp4LitNuzEedPYLjFwQYNNULdM3i3mbPUddbTMAx/Screenshot%20from%202018-04-02%2003-51-57.png)


## Get virtual Steem Supply
```
require_relative 'easysteem'

puts EasySteem.supply
```
![Screenshot from 2018-04-02 03-59-53.png](https://steemitimages.com/DQmQQev6YAJy3Dvqhtyu6Zbd1WA6HVvXqDLzQCQerYZWrgs/Screenshot%20from%202018-04-02%2003-59-53.png)

## Get following stream.. see who is following whom at real time

```
require_relative 'easysteem'

puts EasySteem.follow_stream
```
![Screenshot from 2018-04-02 04-02-16.png](https://steemitimages.com/DQmYMWRQRsV8AAZVcyRLT7qejBoGAtNaPRDyd6CdGFGmjA4/Screenshot%20from%202018-04-02%2004-02-16.png)

```
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. ;)

![Screenshot from 2018-04-02 04-03-39.png](https://steemitimages.com/DQmf5xP8NXvvcJKADYXLMujoR6gRPfC1MUGRpW2PFFiABEm/Screenshot%20from%202018-04-02%2004-03-39.png)
👍 , , , , , , , , , , , , , , , , , , , , , , ,