Let‘s develop a Steemit API Wrapper for Java

in #steem8 years ago

Hay Steemers,

I would like to provide some new tools to the Steemit univers and as you may have noticed due to my posts here, my preferred programming language is Java. But, so far there is no kind of API Wrapper for Steemit which makes it pretty hard to develop new tools to me.

WRAPPER
Source

Because of that, I’ve spend some time to do a short proof of concept which you can find later in this article. My main question for now is, are there people out there that are also interested in a Java API for Steemit or are there even people who would like to contribute? If so, please leave a comment right here so I know if the work is worth it. Please keep in mind that this API wrapper could also be usefull for android apps.

If I feel like this project is worth the work, I will create a new GitHub repository for the project so everybody could help to make this small project a success.

Proof of Concept

For this proof of concept I’ve used the “tyrus-standalone-client” for the websocket communication in Java. So far, this is the only dependency that is needed so far, which makes the pom pretty easy to understand:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>dez1337.steemit.com</groupId>
    <artifactId>steemit-api-wrapper</artifactId>
    <version>1.0-SNAPSHOT</version>
    <name>Steemit Java API Wrapper</name>
    <url>http://www.steemit.com/@dez1337</url>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.tyrus.bundles</groupId>
            <artifactId>tyrus-standalone-client</artifactId>
            <version>1.13</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.0</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <java.version>1.8</java.version>
    </properties>
</project>

After that I’ve created one simple Java class that only do one websocket request. Here is the code of this class:

package dez.steemit.com;

import java.io.IOException;
import java.net.URI;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import javax.websocket.ClientEndpointConfig;
import javax.websocket.Endpoint;
import javax.websocket.EndpointConfig;
import javax.websocket.MessageHandler;
import javax.websocket.Session;

import org.glassfish.tyrus.client.ClientManager;


public class JavaAPIWrapper {
    private static CountDownLatch messageLatch;
    private static final String SENT_MESSAGE = "{\"jsonrpc\": \"2.0\", \"params\": [\"database_api\", \"get_account_count\", [1]], \"id\": 1 \"method\": \"call\"}";

    public static void main(String[] args) {
        try {
            messageLatch = new CountDownLatch(1);

            final ClientEndpointConfig cec = ClientEndpointConfig.Builder.create().build();

            ClientManager client = ClientManager.createClient();
            client.connectToServer(new Endpoint() {

                @Override
                public void onOpen(Session session, EndpointConfig config) {
                    try {
                        session.addMessageHandler(new MessageHandler.Whole<String>() {

                            @Override
                            public void onMessage(String message) {
                                System.out.println("Received message: " + message);
                                messageLatch.countDown();
                            }
                        });
                        session.getBasicRemote().sendText(SENT_MESSAGE);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }, cec, new URI("wss://node.steem.ws"));
            messageLatch.await(100, TimeUnit.SECONDS);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

If you run the application, it print something like this:

Received message: {"id":1,"result":121305}

So everything is working as expected!

At this point I have to say thanks to @aglo whose article showed me how to format the websocket requests and also a huge thanks to @xeroc and @jesta for providing the service “node.steem.ws”.

Summary

Please do not forget to give me some feedback for the idea and make sure to follow me by pressing the button below, so you’ll never miss new posts!

alt text
Source

Thank you and best regards!

Sort:  

Hi @dez1337 ! Thanks for sharing your project with us ! Can I use it for collecting data on steemit users ? If yes how can I do that? I'm looking at the github repo but there are no examples on how to query the Steemit API for obtaining data on number of users and number of posts in a given date.

is it possible to make a stemmit time Watch Movies and TV Shows instantly
poppcorn time + steemit = ? dtube + bot searting tv series using ,watchfree.io putlocker.is ,movieonline.io, powered by steemit tool that allows you to play hundreds of movies and series ,

steemit.time. powered by stemmit

No more downloads hassle! The best movies & TV shows, for free! Directly on Stemmit Time Online in HD + subtitles, with Torrents Time Engine™

:D Sadly the Steem blockchain is not made to host videos, but the idea is nice in general :D :)

Hi @dez1337 . Thanks for sharing this. I also program in Java and was looking for something like this. But this post is 9 months old. Do you have some more updated posts on how to build a Java wrapper for Steemit API ?

Hay @alketcecaj,

thank you for your interest - Just check my blog - This project has grown a lot since this post :)

Best regards!

Thank you @dez1337! Java is my favorite language, I'm glad to find a wrapper in Java

Hi @dez1337,

Thanks for sharing this code!

I'm looking for an API that allows me to create content (POSTs). I have been reading the documentation and it seems that we can only retrieve information or just create a comments or up-vote.

I wonder if you could point me to some API that allows creating POST in steemit.com.

Thanks,

@realskilled

Hay @realskilled ,

Please checkout my blog and also the latest update post of SteemJ 0.4.0.

The version allows you to post using:

steemj.createPost(.....)

Let me know if you face an issue 😊👍

Hi @dez1337
Thanks for your comment.
The point is that I need to figure out how could I use this from PHP :)
A tricky point, right?

Haha okay .. I get your point :) Sadly, I am not aware of a fully working PHP api wrapper 😢 I don't know what sub systems you have, but I guess it may be easier to switch to another language like javascript, python or java instead of starting a PHP project :/

Oh, wouldn't like to switch right now. I'm a Drupal dev. :)

I see i see 🙈 There is a PHP lib at github and I just checked - The developer planned the creating posts feature for the "next weeks".

This post has been ranked within the top 50 most undervalued posts in the second half of Dec 21. We estimate that this post is undervalued by $6.43 as compared to a scenario in which every voter had an equal say.

See the full rankings and details in The Daily Tribune: Dec 21 - Part II. You can also read about some of our methodology, data analysis and technical details in our initial post.

If you are the author and would prefer not to receive these comments, simply reply "Stop" to this comment.

If you can make, make it, I'm sure it will be highly valued and appreciated. @jesta made a python api for steem, and fabien or fabian made one for javascript.

Hehe, thank you for the feedback. You are right, for sure, but it will be a good amount of work and I am not sure if I can finish it parallel to my normal work :D But I'll give it a try :)

The more tools the better!

As @krnel mentioned, there are some pretty solid tools for python already with @xeroc's piston.steem and @furion's steemtools.

Coin Marketplace

STEEM 0.18
TRX 0.16
JST 0.030
BTC 60480.09
ETH 2363.08
USDT 1.00
SBD 2.65