The overarching goal of Project Greenshift is to provide users with a different and perhaps more useful way to discover new content creators on the Steem blockchain. The plan is to use different relationships between content pieces of content to recommend and discover content in a better way than topic filtering or the trending section. But in order to use relationships we need to have a tool that allows us to traverse the blockchain in the first place.
That's where Radiator comes into play. Radiator is a ruby gem developed by @inertia that wraps the Steem API in Ruby. A wrapper is simply a call to another function. The wrapper in this case allows us to write in Ruby as opposed to Javascript. Which is great since it allows us to build using Rails as opposed to a Javascript framework. (Although there is nothing wrong with using Javascript libraries and Rails actually uses some nodejs under the hood).
One of the relationships that we want to build is to get the most recent piece of content that an author has upvoted. This provides us an excellent opportunity for the next few posts to go through some development brainstorming and writing test programs that progressively get more complex to point where we build a function that essentially applies this relationship.
The first test program that we will create will be to get the most recent operation from the blockchain that an account has performed. Below is the full program and the final output as a result from this program:
In every programming language you need to tell the program which external libraries you are using so it knows to pull the useful code of the library when a call is made to that code. The first line essentially tells the interpreter that the program requires the radiator gem later in the program.
Next, we initialize an API object and make a call to get the account history of the @greer184 account which is my main account. It takes an account name, a starting block, and a limit as the argument. To get the most recent operation from my account, we use -1 as the start and use a limit of 0. By using -1 we get the most recent results rather than starting from a block. Using 0, we would get the first operation which would be when this account was created.
We then get a Hashie object returned to us. A Hashie object is basically a hash with some really cool features. A hash is basically a set of key-value pairs which is also known as a dictionary in some other contexts. Basically we can use the key to obtain the value from the hash. The next line gets the operation out of the hash.
In the last line we simply print out the type of the last operation and the Hashie object that contains the relevant information with relation to that operation. In this case at this moment, we see the most recent operation was a vote and the relevant information is the content that was voted upon.
In terms of our relationship, you'll see that we'll need to find a way to sort "vote" operations from other operations and find a way to get the most recent "vote" operation considering a bunch of "vote" operations. And once we solve those two problems, we need a way to do both in a relatively efficient way.
As you can see a lot goes into the programming and we only covered five lines of code today. And major projects have thousands of line of code. And it may seem very overwhelming. But luckily for you and me, there is no deadline for this project and there are no grand promises of a revolutionary technology. Because that would be unrealistic considering I work on this maybe an hour or two per day and this is a hobby project rather than an entrepreneurial pursuit.
Expectations are a programmer's worst nightmare. Believe me on that. But in the meanwhile for those interested in programming whether on the Steem blockchain or not, I wish you happy coding.