Pular para o conteúdo principal

The Bluesky REST API

 You may have heard that Twitter has been blocked in Brazil. It has been defying local authorities and justice blocked its access from Brazil.

Have that said, most Brazilians migrated to Bluesky, the social network created by Twitter's founder. I moved to there as well (feel free to follow me, be aware I post a lot in Portuguese) and I am amazed with two things:

* The REST API is well documented and easy to use;

* Bluesky supports The AT Protocol, which seems to be great alternative of how we consume content from the internet (which is currently dominated by suspicious algorithms).


In this post let's reach the API to query about Java and build a dashboard out of it. 


The API Endpoint

We will be using the app.bsky.feed.searchPosts endpoint. It returns a JSON in the following format


{
"posts": [
{
"uri": "at://did:plc:xsqyottmupmtgs7q3quar6yx/app.bsky.feed.post/3l36s7n76bv2x",
"cid": "bafyreid43mz5v7lkck3om3wbwlcje2dddv2wsru32x5mqupfke5a7jdg6e",
"author": {
"did": "did:plc:xsqyottmupmtgs7q3quar6yx",
"handle": "wanningcatboy.bsky.social",
"displayName": "sam - ʷᵃⁿⁿⁱⁿᵍ ᵐⁱⁿʰᵃ ᵛⁱᵈᵃ",
"avatar": "https://cdn.bsky.app/img/avatar/plain/did:plc:xsqyottmupmtgs7q3quar6yx/bafkreif7ulgduagwph4jim5y34irfkcwgzfjwktejgvjnvnur4zw4hae7e@jpeg",
"associated": {
"chat": {
"allowIncoming": "following"
}
},
"labels": [],
"createdAt": "2024-08-29T22:00:51.821Z"
},
"record": {
"$type": "app.bsky.feed.post",
"createdAt": "2024-09-02T17:12:20.219Z",
"langs": [
"pt"
],
"reply": {
"parent": {
"cid": "bafyreibt6uol25amqmam4ekb6ybj2y3o4da7wtloe6osbwyv5rvcvemh3m",
"uri": "at://did:plc:jxgcpi3zvllx7fdd2hiigejy/app.bsky.feed.post/3l36gchfci72k"
},
"root": {
"cid": "bafyreibt6uol25amqmam4ekb6ybj2y3o4da7wtloe6osbwyv5rvcvemh3m",
"uri": "at://did:plc:jxgcpi3zvllx7fdd2hiigejy/app.bsky.feed.post/3l36gchfci72k"
}
},
"text": "Eu já entrei na facul com o objetivo de aprender logo java pq meu irmão eh dev pleno de Java e sempre fez propaganda pra mim kakakakakak"
},
"replyCount": 0,
"repostCount": 0,
"likeCount": 0,
"quoteCount": 0,
"indexedAt": "2024-09-02T17:12:20.219Z",
"labels": []
}
],
"cursor": "1"
}


To query it we need an API Key, which can be acquired going to your Profile Settings -> App Passwords -> Create App Password 



The API seems to enable CORS from any web app, hence for our application we will be using Dashbuilder

Our Application: A simple Dashboard

We used to use JavaFX or JavaFX Script on this blogs (e.g. Having fun creating a JavaFX App to Visualize Tweet Sentiments), but in this post we will be using a tool that I have been working until last year: Dashbuilder.

Dashbuilder allow us to write YAML that compiles to HTML pages and it is focused on Dashboard application, but is very flexible to render any external component, making it some sort of microfrontend tool.

Here are the steps we follow to create the dashboard:

* First we created the Dataset, which is basically the JSON above with a JSONAta expression to retrieve what we want. In our case we retrieved the author, author handle, text and the number of likes:

$.posts.[author.displayName, author.handle, record.text, likeCount]

* Then we extracted parameters from the dataset, such as the token, the search term and the API limit. This makes the YAML easily reusable;

* Finally we created the actual visualization. In this part you are free to create what you want from the data, since I was just testing it I simply created two barcharts to show who is talking more about the term and the most liked user and a table with the requests. Here' s the result:


You can see the result YAML on my github and you can even run it on Serverless Logic Webtools or in my personal Dashbuilder editor (which uses a more recent Dashbuilder version with Patternfly v5)


Thanks for reading!






Comentários

Postagens mais visitadas deste blog

Dancing lights with Arduino - The idea

I have been having fun with Arduino these days! In this article I am going to show how did I use an electret mic with Arduino to create a Dancing Lights circuit. Dancing Lights   I used to be an eletronician before starting the IT college. I had my own electronics maintenance office to fix television, radios, etc. In my free time I used to create electronic projects to sell and I made a few "reais" selling a version of Dancing lights, but it was too limited: it simply animated lamps using a relay in the output of a 4017 CMOS IC. The circuit was a decimal counter  controlled by a 555. 4017 decimal counter. Source in the image When I met Arduino a few years ago, I was skeptical because I said: I can do this with IC, why should I use a microcontroller. I thought that Arduino was for kids. But now my pride is gone and I am having a lot of fun with Arduino :-) The implementation of Dancing Lights with Arduino uses an electret mic to capture the sound and light leds...

Simplest JavaFX ComboBox autocomplete

Based on this Brazilian community post , I've created a sample Combobox auto complete. What it basically does is: When user type with the combobox selected, it will work on a temporary string to store the typed text; Each key typed leads to the combobox to be showed and updated If backspace is type, we update the filter Each key typed shows the combo box items, when the combobox is hidden, the filter is cleaned and the tooltip is hidden:   The class code and a sample application is below. I also added the source to my personal github , sent me PR to improve it and there are a lot of things to improve, like space and accents support.

Creating Fat JARs for JavaFX Applications

A FAT JAR is a type of Java application distribution where a single JAR contains all other dependencies, so no additional file is required to run the JAR besides the Java Virtual Machine. For any Java maven based application, creating a FAR JAR could be solved by using Maven Shade Plugin . However, creating FAT Jars using JavaFX may be a challenge because JavaFX uses modules. Fortunately this subject was intensely discussed in the WEB, and a good explanation and a solution was provided by Jose Pereda in this StackOverflow response. In this post I want to briefly share the steps to make a FAT JAR and post an example on my github so I can point others to check the example. How to create a FAT JAR for a JavaFX application? 1- Create a main class that will run your application. This class must have the main method and call your actual application static launch method; 2- Add the Shade Plugin to your project. For those using Gradle notice that Jose Pereda also provided an answer about it i...