mastodon-api
mastodon-api copied to clipboard
New release for Ruby 2.7.1
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?
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!
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:
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:
- [ ] Accounts
- [ ] Main account methods
- [ ] Statuses
- Method:
GET
- Route:
/api/v1/accounts/#{id}/statuses
- Method:
- [ ] Lists
- Method:
GET
- Route:
/api/v1/accounts/#{id}/lists
- Method:
- [ ] Identity Proofs
- Method:
GET
- Route:
/api/v1/accounts/#{id}/identity_proofs
- Method:
- [ ] Feature on Profile (pins)
- Method:
POST
- Route:
/api/v1/accounts/#{id}/pin
- Method:
- [ ] Unfeature on Profile (unpin)
- Method:
POST
- Route:
/api/v1/accounts/#{id}/unpin
- Method:
- [ ] Statuses
- [ ] Bookmarks (might be deprecated, though - also, see Statuses)
- Method:
GET
- Route:
/api/v1/bookmarks
- Method:
- [ ] Favorites
- Method:
GET
- Route:
/api/v1/favourites
- Method:
- [ ] Reports (some of the documentation is also missing in the API docs) (
/api/v1/reports
)- [ ] File a report
- Method:
GET
- Route:
/api/v1/reports
- Method:
- [x] Create a Report
- Method:
POST
- Route:
/api/v1/reports
- Method:
- [ ] File a report
- [ ] Featured Tags (
/api/v1/featured_tags
)- [ ] View your featured tags
- Method:
GET
- Route:
/api/v1/featured_tags
- Method:
- [ ] Feature a tag
- Method:
POST
- Route:
/api/v1/featured_tags
- Method:
- [ ] Unfeature a tag
- Method:
DELETE
- Route:
/api/v1/featured_tags/#{id}
- Method:
- [ ] Suggested tags to feature
- Method:
GET
- Route:
/api/v1/featured_tags/suggestions
- Method:
- [ ] View your featured tags
- [ ] Preferences (
/api/v1/preferences
)- [ ] View user preferences
- Method:
GET
- Route:
/api/v1/preferences
- Method:
- [ ] View user preferences
- [ ] Suggestions
- [ ] Follow suggestions
- Method:
GET
- Route:
/api/v1/suggestions
- Method:
- [ ] Remove a suggestion
- Method:
DELETE
- Route:
/api/v1/suggestions/#{account_id}
- Method:
- [ ] Follow suggestions
- [ ] Main account methods
- [ ] Apps
- [ ] OAuth
- [ ] Authorize
- Method:
GET
- Route:
/api/v1/oauth/authorize
- Method:
- [ ] Obtain a Token
- Method:
POST
- Route:
/api/v1//oauth/token
- Method:
- [ ] Revoke token
- Method:
POST
- Route:
/api/v1/oauth/revoke
- Method:
- [ ] Authorize
- [ ] OAuth
- [ ] Statuses
- [ ] Media
- [ ] Update an attachment (Get an Attachment, before it is attached to a status and posted...)
- Method:
GET
- Route:
/api/v1/media/#{id}
- Method:
- [ ] Focal points
- No direct API documentation exists for this
- [ ] Update an attachment (Get an Attachment, before it is attached to a status and posted...)
- [ ] Polls (I'm not sure whether all API endpoints are documented)
- [ ] View a poll
- Method:
GET
- Route:
/api/v1/polls/#{id}
- Method:
- [ ] Vote on a poll
- Method:
POST
- Route:
/api/v1/polls/#{id}/votes
- Method:
- [ ] View a poll
- [ ] Media
- [ ] Timelines
- [ ] Markers
- [ ] Get saved timeline position
- Method:
GET
- Route:
/api/v1/markers
- Method:
- [ ] Save position in timeline
- Method:
POST
- Route:
/api/v1/markers
- Method:
- [ ] Get saved timeline position
- [ ] Markers
- [ ] Notifications
- [ ] Main notification methods
- [ ] Get a single notification
- Method:
GET
- Route:
/api/v1/notifications/#{id}
- Method:
- [ ] Dismiss a single notification
- Method:
POST
- Route:
/api/v1/notifications/#{id}/dismiss
- Method:
- [ ] Get a single notification
- [ ] Push
- [ ] Subscribe to push notifications
- Method:
POST
- Route:
/api/v1/push/subscription
- Method:
- [ ] Get current subscription
- Method:
GET
- Route:
/api/v1/push/subscription
- Method:
- [ ] Change types of notifications
- Method:
PUT
- Route:
/api/v1/push/subscription
- Method:
- [ ] Remove current subscription
- Method:
DELETE
- Route:
/api/v1/push/subscription
- Method:
- [ ] Subscribe to push notifications
- [ ] Main notification methods
- [ ] Trends
- [ ] Trending tags
- Method:
GET
- Route:
/api/v1/trends
- Method:
- [ ] Trending tags
- [ ] Directory
- [ ] View profile directory
- Method:
GET
- Route
/api/v1/directory
- Method:
- [ ] View profile directory
- [ ] Admin (not currently complete documentation for API)
- [ ] Announcements
- [ ] View all announcements
- Method:
GET
- Route:
/api/v1/announcements
- Method:
- [ ] Dismiss an announcements
- Method:
POST
- Route:
/api/v1/announcements/#{id}/dismiss
- Method:
- [ ] Add reaction
- Method:
PUT
- Route:
/api/v1/announcements/#{id}/reactions/#{name}
- Method:
- [ ] Remove reaction
- Method:
DELETE
- Route:
/api/v1/announcements/#{id}/reactions/#{name}
- Method:
- [ ] View all announcements
- [ ] Proofs
- [ ] View identity proof
- Method:
GET
- Route:
/api/proofs
- Method:
- [ ] View identity proof
- [ ] OEmbed
- [ ] OEmbed as JSON
- Method:
GET
- Route:
/api/oembed
- Method:
- [ ] OEmbed as JSON
Other notes
-
timelines/streaming
might need manual review, I didn't look deeply into these endpoints as they're related to streaming APIs.
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:
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
.
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)
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'
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.
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.
@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!
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: @.***>