Quantcast
Channel: David Eastman, Author at The New Stack
Viewing all articles
Browse latest Browse all 80

A Developer Guide to Using Glamorous Toolkit On AT Protocol

$
0
0
moldable

In this post we will explore the AT protocol using Glamorous Toolkit (GT), a moldable development environment tool. The AT Protocol sits beneath the Twitter competitor, Bluesky. The last time we looked at GT, we were briefly introduced to moldable development — a way to understand your systems better by making custom tools that can generate interesting views on that system. (I also slightly insulted Smalltalk users, so maybe this post will be something of an apology).

Glamorous toolkit is designed to explore APIs, like AT, and it can help explore a problem space using lots of small scripts (or moldable tools), possibly made of other views or calls.

There is more to say about the possibilities of moldable development, but today I want to focus on the practicalities of using GT to explore the AT protocol. We will use a prebuilt framework written with GT to do that.

Let’s start with a fresh install of the toolkit. Starting from the GT download page, I went with the Intel Mac install. As it effectively works with an image, you’ll need to run it in place.

When opened, you’ll get immediate access to the docs on the open tab:

So that we can follow along with the worked example, open up “Case studies of Moldable Development” and click on “Working with AT Protocol”. This gives us a new tab window onto the book.

The first thing we need to do is install the Gt4AtProto. This is the framework, written with GT, that will help us work with Bluesky and the AT protocol. But we can do that directly from the snippet on the page in front of us. The book is made of text and runnable snippets (similar to a Jupyter Notebook) so the reference to the repository loader (called “Metacello”) is ready to go:

The language here is called Pharo, which we can think of as a Smalltalk variant or dialect. But we don’t have to worry much about that.

We can execute the snippet with that small arrow ➤ bottom left. (Anytime you want to stop, just close the window and you will get the option to save and quit. You will restart where you left off.)

Execute the snippet and wait. You will know when the framework has loaded from the repository because the snippet returns a somewhat subtle grey circle at the end of the class when any execution is complete:

Now, if you go back to the main “gt” tab, the contents of your tab view will have changed:

Clearly, you could login to Bluseky here — but we’ll do that from a different snippet.

Back to the “Working with AT Protocol” tab: once loaded, click on the “About Glamorous Toolkit for AT Protocol,” which links to the next book page. Click on “Working with the API through the generated client” and we will be ready to start.

Our first job is to log into Bluesky with an app password. Assuming you have a Bluesky account, go to the settings page and create yourself a new App Password. These are designed to allow access to Bluesky for a single app. That unique name just helps you remember it:

OK, if you simply copy the password into the clipboard, we can work with that — although you should also note it down for good measure.

If you go back to GT, you should see the snippet below on the “Working with the API through the generated client” page:

You’ll need to replace the first two variables with your credentials, replacing Tudor’s handle. The domain server is likely to be correct (that is the one for the main Bluesky instance). Make sure you check on your profile page what your full domain name is for the handle — mine is “eastmad.bsky.social”. As it implies, the password will be sucked out of the clipboard.

If you evaluate this, you can use that last button “variable values” to check that everything worked:

The next snippet underneath, the one that mentions the GtApClient, will log you in. So Evaluate that, and Inspect it:

If you get an error, check your creds and make sure the app password is in your clipboard. Or just make it a variable like the handle and pdsUrul.

The set of dictionaries is hopeful, but not very interesting. The next snippet digs a little further in, so let’s inspect the result of that. We will look at how that view is constructed later:

We have a list of all the queries we can make, which means we can start to play with the AT protocol on this account.

Now let’s move off the book page briefly and make our own snippet with one of those queries. You can make your own snippet using that “+” symbol at the bottom of any snippet. Try the content below:

This gives us a nice default “postcard” view:

You can then play with the different views (tabs within the page), like Followers and Following. You can create a post and you can also click through to a thread.

Writing Tooling Around Your Target

This post is about getting you comfortable with the toolkit, but the purpose of the toolkit is to write tooling around your target. So let’s take a look at what a query is made of.

Go back to the list of queries — within a tab pane, you can scroll left and right between document pages. We can then look at what makes up the appBskyActorGetProfileActor query, the one we just used:

So this is an XRPC call. We can see that it interacts with a framework method, with a specific query to Bluesky, pulling out “actor” in the parameter.

appBskyActorGetProfileActor: actor "" 
<xrpcQuery> 
^ AppBskyActorDefsProfileViewDetailed 
  fromRequest: (self 
    queryOn: 'app.bsky.actor.getProfile' 
    parameters: {'actor' -> actor} asDictionary)


My Smalltalk knowledge is minimal, but the chevron (hat) is the return command, so this returns an internally constructed view based on the XRPC query getProfile based on the actor.

Just to confirm what this is referring to, lets quickly look at the Bluseky docs to see what this call does:

Back to GT. To remind us that we can be pretty flexible with exploration because each view is scripted within an inspector, we note that by alt-clicking a view you can get the code behind it. So by alt-clicking on the “Queries” view tab we see the following:

We can edit this. For example, you can see the title of the view is written as part of the view, as well the column name. We can also see the sort method. Even without much knowledge of Smalltalk, this implies that we could simply change the view to reverse the list by swapping around the “:a” and “:b” within the sort block:

Now the AT protocol uses what it calls a “lexicon” to match a schema system for any call. G4Atproto uses this to generate the API, but that is for a deeper exploration at another time.

What Did We Achieve

So in summary, we opened up Glamorous Toolkit, installed the AT Protocol reading gt4atproto, which acts as a dedicated environment written on top of the toolkit. We connected to Bluseky via an app password just using snippets. And we saw how the tooling is made of scripts over XRPC that you can easily modify. Plus, we looked at how we can edit a view.

Glamorous toolkit is designed to explore APIs, like AT, and I hope this gives you an idea how it can help explore a problem space using lots of small scripts (or moldable tools), possibly made of other views or calls. Note how tooling written closer to the target environment makes exploration much easier.

The post A Developer Guide to Using Glamorous Toolkit On AT Protocol appeared first on The New Stack.

How to use Glamorous Toolkit (GT), a moldable development environment tool, to explore the AT Protocol of Bluesky.

Viewing all articles
Browse latest Browse all 80

Trending Articles