It was bothering me that there is a Python tutorial that shows how to post to Mastodon with only the Requests module.

So I figured out how to do the same thing in Ruby using the HTTP gem.

First get your access token (use the web page below to figure that out)

This is all of the Ruby code you need:

#!/usr/bin/env ruby

require "http"

HTTP.auth("Bearer YourMastodonAccessTokenGoesHere")
.post("", :params => {:status => "You can toot to Mastodon using the HTTP gem in TWO lines. I'm doing it right now"})

The reason I'm doing this is that my app needs basic functionality in terms of posting to Twitter and Mastodon, and the gems are a) overkill for that and b) the mastodon-api gem doesn't work with Ruby >= 2.7.

This will make my app MUCH simpler.



I ran into this problem yesterday (mastodon-api gem vs Ruby 2.7+) and it’s been fixed on the github HEAD, so it’ll work if you install from there.

(Now onward to getting gd2-ffij working on Raspbian.)

@suetanvil I had some success using the http gem. What I'm missing is a way to detect failure to post. I'll be working on that

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!