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)

dev.to/bitsrfr/getting-started

Follow

This is all of the Ruby code you need:

#!/usr/bin/env ruby

require "http"

HTTP.auth("Bearer YourMastodonAccessTokenGoesHere")
.post("ruby.social/api/v1/statuses", :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.

github.com/passthejoe/blogpost

@passthejoe

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
Ruby.social

A Mastodon instance for Rubyists & friends