mastodon / mastodon-api

A ruby interface for the Mastodon API
175 stars 61 forks source link

New release for Ruby 2.7.1 #49

Open ushitora-anqou opened 4 years ago

ushitora-anqou commented 4 years ago

The following code doesn't run on the latest release (2.0.0) with Ruby 2.7.1, but works fine on the master branch.

rest = Mastodon::REST::Client.new(base_url: "...", bearer_token: "...")
rest.verify_credentials

Maybe a new release is required?

shavs commented 4 years ago

I second this - doing a bundle update in my project, specifying spec.add_runtime_dependency 'mastodon-api', '~> 2.0', seems to bring down dependencies with versions like:

...
Using http 3.3.0
...

... whereas master has version 4, so I'd expect it to be using a version on 4.X, rather than 3.3.0. As mastodon-api is the only thing in my application making HTTP calls, I'm fairly certain that a new release is required.

I get an exception with Ruby 2.7, calling create_status:

FrozenError: can't modify frozen String: ""
  /home/shavs/.gem/gems/http-3.3.0/lib/http/response/body.rb:52:in `force_encoding'
  /home/shavs/.gem/gems/http-3.3.0/lib/http/response/body.rb:52:in `to_s'
  /usr/lib/ruby/2.7.0/forwardable.rb:229:in `empty?'
  /home/shavs/.gem/gems/mastodon-api-2.0.0/lib/mastodon/rest/request.rb:26:in `perform'
  /home/shavs/.gem/gems/mastodon-api-2.0.0/lib/mastodon/rest/utils.rb:10:in `perform_request'
  /home/shavs/.gem/gems/mastodon-api-2.0.0/lib/mastodon/rest/utils.rb:18:in `perform_request_with_object'
  /home/shavs/.gem/gems/mastodon-api-2.0.0/lib/mastodon/rest/statuses.rb:24:in `create_status'

(oddly, I still receive the status, even though there is an exception... :shrug: )

I'm relatively new to Ruby (but I'm familiar with JS/PHP dev workflows), so feel free to correct me if I'm wrong with any of this info!

Gargron commented 4 years ago

I really gotta sit down and go over this gem again and make sure all the APIs that Mastodon has are properly represented in it then push a new release out :grimacing:

shavs commented 4 years ago

Hopefully this is of some use, and I apologise if this is a wall of text/Markdown, but here is a list of all the API endpoints not currently implemented:

Missing endpoints:

Other notes

I went through the documentation currently available on JoinMastodon, so hopefully this covers it all. However, it was all done by hand, so there may be some issues with it. And, feel free to copy it etc. so that you can format it however you please! :+1:

passthejoe commented 4 years ago

I can confirm that mastodon-api is throwing this error when used in Ruby 2.7.

I am using mastodon-api in a project that also uses the twitter gem, and I have to use an older version of the twitter gem because of the conflict between http 3.3.0 and http 4.4.1.

reinboldg commented 3 years ago

Same issue here

$ ruby -v
ruby 2.7.0p0 (2019-12-25 revision 647ee6f091) [x86_64-linux-gnu]
Traceback (most recent call last):
        7: from /home/gregory/bin/ecchi:179:in `<main>'
        6: from /home/gregory/.gem/ruby/2.7.0/gems/mastodon-api-2.0.0/lib/mastodon/rest/media.rb:17:in `upload_media'
        5: from /home/gregory/.gem/ruby/2.7.0/gems/mastodon-api-2.0.0/lib/mastodon/rest/utils.rb:18:in `perform_request_with_object'
        4: from /home/gregory/.gem/ruby/2.7.0/gems/mastodon-api-2.0.0/lib/mastodon/rest/utils.rb:10:in `perform_request'
        3: from /home/gregory/.gem/ruby/2.7.0/gems/mastodon-api-2.0.0/lib/mastodon/rest/request.rb:26:in `perform'
        2: from /usr/lib/ruby/2.7.0/forwardable.rb:229:in `empty?'
        1: from /home/gregory/.gem/ruby/2.7.0/gems/http-3.3.0/lib/http/response/body.rb:52:in `to_s'
/home/gregory/.gem/ruby/2.7.0/gems/http-3.3.0/lib/http/response/body.rb:52:in `force_encoding': can't modify frozen String: "" (FrozenError)
mahlonsmith commented 1 year ago

Bumping. This seems to have been broken for some time. Similar errors under Ruby 3.x.

[5] pry(main)> client.conversations
FrozenError: can't modify frozen String: ""
from /usr/local/lib/ruby/gems/3.1/gems/http-3.3.0/lib/http/response/body.rb:52:in `force_encoding'
passthejoe commented 1 year ago

I stopped using this gem some time ago. It's possible to post to Mastodon with the HTTP gem and a Mastodon bearer token. I remember seeing a tutorial on doing this in Python, and somehow I figured it out in Ruby. I can't find where I did that, and now that Mastodon has all of this newfound popularity maybe I should write up how I did it.

If I or someone else can find a tutorial on how to do this, hopefully you (or I) can post it.

hortoncd commented 1 year ago

This PR resolves the FrozenError, but hasn't been shipped yet. You can fork from that repo source and install from the branch for now, if nothing else.

RyanTG commented 1 year ago

@passthejoe Your comment here was really helpful. I only need to write statuses, and it was proving to be a big hassle to get this gem working given all the ancient dependencies. I looked at your repo and saw how you're using the http gem: https://github.com/passthejoe/blogPoster/blob/d2cfa6815f995b4e81ee548f51e35b0225994eb8/blogPoster.rb#L631

HTTP.auth("Bearer " + @mastodon_bearer_token)
    .post(@mastodon_base_url + "/api/v1/statuses", :params => {:status => @yourText + " " + @yourURL})

Works great - very simple!

passthejoe commented 1 year ago

It was a nice discovery. I think I saw somebody do it in Python and then just hacked it into Ruby.

On Sun, Mar 19, 2023 at 6:37 PM Ryan TG @.***> wrote:

@passthejoe https://github.com/passthejoe Your comment here was really helpful. I only need to write statuses, and it was proving to be a big hassle to get this gem working given all the ancient dependencies. I looked at your repo and saw how you're using the http gem: https://github.com/passthejoe/blogPoster/blob/d2cfa6815f995b4e81ee548f51e35b0225994eb8/blogPoster.rb#L631

HTTP.auth("Bearer " + @mastodon_bearer_token) .@.***_base_url + "/api/v1/statuses", :params => {:status => @yourText + " " + @yourURL})

Works great - very simple!

— Reply to this email directly, view it on GitHub https://github.com/mastodon/mastodon-api/issues/49#issuecomment-1475487067, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAX2TB445PGEIEBZCIIW6X3W46YFRANCNFSM4OQNRL5A . You are receiving this because you were mentioned.Message ID: @.***>