Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions lib/mastodon/announcement.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
require 'mastodon/announcement_reaction'

module Mastodon
class Announcement < Mastodon::Base
# @!attribute [r] id
# @return [String]
# @!attribute [r] text
# @return [String]
# @!attribute [r] published?
# @return [Boolean]
# @!attribute [r] all_day?
# @return [Boolean]
# @!attribute [r] created_at
# @return [String]
# @!attribute [r] updated_at
# @return [String]
# @!attribute [r] read?
# @return [Boolean]
# @!attribute [r] reactions
# @return [Mastodon::Collection<Mastodon::AnnouncementReaction>]
# @!attribute [r] scheduled_at
# @return [String]
# @!attribute [r] starts_at
# @return [String]
# @!attribute [r] ends_at
# @return [String]

normal_attr_reader :id,
:text,
:created_at,
:updated_at,
:scheduled_at,
:starts_at,
:ends_at

predicate_attr_reader :published,
:all_day,
:read

collection_attr_reader :reactions, Mastodon::AnnouncementReaction

def initialize(attributes = {})
attributes.fetch('id')
super
end
end
end
26 changes: 26 additions & 0 deletions lib/mastodon/announcement_reaction.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module Mastodon
class AnnouncementReaction < Mastodon::Base
# @!attribute [r] name
# @return [String]
# @!attribute [r] count
# @return [Integer]
# @!attribute [r] me?
# @return [Boolean]
# @!attribute [r] url
# @return [String]
# @!attribute [r] static_url
# @return [String]

normal_attr_reader :name,
:count,
:url,
:static_url

predicate_attr_reader :me

def initialize(attributes = {})
attributes.fetch('name')
super
end
end
end
17 changes: 17 additions & 0 deletions lib/mastodon/featured_tag.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Mastodon
class FeaturedTag < Mastodon::Base
# @!attribute [r] id
# @return [String]
# @!attribute [r] name
# @return [String]
# @!attribute [r] statuses_count
# @return [String]
# @!attribute [r] last_status_at
# @return [String]

normal_attr_reader :id,
:name,
:statuses_count,
:last_status_at
end
end
20 changes: 20 additions & 0 deletions lib/mastodon/identity_proof.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Mastodon
class IdentityProof < Mastodon::Base
# @!attribute [r] provider
# @return [String]
# @!attribute [r] provider_username
# @return [String]
# @!attribute [r] updated_at
# @return [String]
# @!attribute [r] proof_url
# @return [String]
# @!attribute [r] profile_url
# @return [String]

normal_attr_reader :provider,
:provider_username,
:updated_at,
:proof_url,
:profile_url
end
end
44 changes: 44 additions & 0 deletions lib/mastodon/poll.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'mastodon/emoji'

module Mastodon
class Poll < Mastodon::Base
# @!attribute [r] id
# @return [String]
# @!attribute [r] expires_at
# @return [String]
# @!attribute [r] votes_count
# @return [Integer]
# @!attribute [r] voters_count
# @return [Integer]
# @!attribute [r] expired?
# @return [Boolean]
# @!attribute [r] voted?
# @return [Boolean]
# @!attribute [r] multiple?
# @return [Boolean]
# @!attribute [r] own_votes
# @return [Array<Integer>]
# @!attribute [r] options
# @return [Array<Hash>]
# @!attribute [r] emojis
# @return [Mastodon::Collection<Mastodon::Emoji>]

normal_attr_reader :id,
:expires_at,
:votes_count,
:voters_count,
:own_votes,
:options

predicate_attr_reader :voted,
:multiple,
:expired

collection_attr_reader :emojis, Mastodon::Emoji

def initialize(attributes = {})
attributes.fetch('id')
super
end
end
end
22 changes: 22 additions & 0 deletions lib/mastodon/push_subscription.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Mastodon
class PushSubscription < Mastodon::Base
# @!attribute [r] id
# @return [String]
# @!attribute [r] endpoint
# @return [String]
# @!attribute [r] server_key
# @return [String]
# @!attribute [r] alerts
# @return [Hash]

normal_attr_reader :id,
:endpoint,
:server_key,
:alerts

def initialize(attributes = {})
attributes.fetch('id')
super
end
end
end
8 changes: 8 additions & 0 deletions lib/mastodon/rest/accounts.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'mastodon/rest/utils'
require 'mastodon/account'
require 'mastodon/access_token'
require 'mastodon/identity_proof'

module Mastodon
module REST
Expand Down Expand Up @@ -82,6 +83,13 @@ def create_account(params = {})
def search_accounts(query, params = {})
perform_request_with_collection(:get, '/api/v1/accounts/search', { q: query }.merge(params), Mastodon::Account)
end

# List of account identity proofs
# @param id [Integer]
# @return [Mastodon::Collection<Mastodon::IdentityProof>]
def identity_proofs(id)
perform_request_with_collection(:get, "/api/v1/accounts/#{id}/identity_proofs", options, Mastodon::IdentityProof)
end
end
end
end
37 changes: 37 additions & 0 deletions lib/mastodon/rest/announcements.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require 'mastodon/rest/utils'
require 'mastodon/announcement'

module Mastodon
module REST
module Announcements
include Mastodon::REST::Utils

# See all currently active announcements set by admins for this instance
# @param with_dismissed [Boolean]
# @return [Mastodon::Collection<Mastodon::Announcement>]
def announcements(with_dismissed = false)
perform_request_with_collection(:get, '/api/v1/announcements/', { 'with_dismissed': with_dismissed }, Mastodon::Announcement)
end

# Dismiss an announcement
# @param announcement_id [Integer]
def dismiss_announcement(announcement_id)
perform_request(:post, "/api/v1/announcements/#{announcement_id}", {})
end

# Dismiss an announcement
# @param announcement_id [Integer]
# @param emoji [String]
def add_annoucement_reaction(announcement_id, emoji)
perform_request(:put, "/api/v1/announcements/#{announcement_id}/reactions/#{emoji}", {})
end

# Dismiss an announcement
# @param announcement_id [Integer]
# @param emoji [String]
def remove_annoucement_reaction(announcement_id, emoji)
perform_request(:delete, "/api/v1/announcements/#{announcement_id}/reactions/#{emoji}", {})
end
end
end
end
16 changes: 16 additions & 0 deletions lib/mastodon/rest/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
require 'mastodon/rest/lists'
require 'mastodon/rest/scheduled_statuses'
require 'mastodon/rest/conversations'
require 'mastodon/rest/favourites'
require 'mastodon/rest/featured_tags'
require 'mastodon/rest/oauth'
require 'mastodon/rest/polls'
require 'mastodon/rest/push_subscriptions'
require 'mastodon/rest/directory'
require 'mastodon/rest/trends'
require 'mastodon/rest/announcements'

module Mastodon
module REST
Expand All @@ -40,6 +48,14 @@ module API
include Mastodon::REST::Lists
include Mastodon::REST::ScheduledStatuses
include Mastodon::REST::Conversations
include Mastodon::REST::Favourites
include Mastodon::REST::FeaturedTags
include Mastodon::REST::OAuth
include Mastodon::REST::Polls
include Mastodon::REST::PushSubscriptions
include Mastodon::REST::Directory
include Mastodon::REST::Trends
include Mastodon::REST::Announcements
end
end
end
21 changes: 21 additions & 0 deletions lib/mastodon/rest/directory.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require 'mastodon/rest/utils'
require 'mastodon/account'

module Mastodon
module REST
module Directory
include Mastodon::REST::Utils

# List accounts visible in the directory
# @param options [Hash]
# @option options :offset [String]
# @option options :limit [String]
# @option options :order [String]
# @option options :local [Boolean]
# @return [Mastodon::Collection<Mastodon::Account>]
def view_directory(options = {})
perform_request_with_collection(:get, '/api/v1/directory', options, Mastodon::Account)
end
end
end
end
20 changes: 20 additions & 0 deletions lib/mastodon/rest/favourites.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'mastodon/rest/utils'
require 'mastodon/status'

module Mastodon
module REST
module Favourites
include Mastodon::REST::Utils

# Get a list of statuses that the current user has favourited
# @param options [Hash]
# @option options :limit [String]
# @option options :min_id [Integer]
# @option options :max_id [Integer]
# @return [Mastodon::Collection<Mastodon::Status>]
def favourites(options = {})
perform_request_with_collection(:get, "/api/v1/favourites", options, Mastodon::Status)
end
end
end
end
36 changes: 36 additions & 0 deletions lib/mastodon/rest/featured_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
require 'mastodon/rest/utils'
require 'mastodon/featured_tag'
require 'mastodon/hashtag'

module Mastodon
module REST
module FeaturedTags
include Mastodon::REST::Utils

# View featured tags for the current user
# @return [Mastodon::Collection<Mastodon::FeaturedTag>]
def featured_tags
perform_request_with_collection(:get, '/api/v1/featured_tags', {}, Mastodon::FeaturedTag)
end

# Feature a tag
# @param name [String]
# @return [Mastodon::FeaturedTag]
def feature_tag(name)
perform_request_with_object(:post, '/api/v1/featured_tags', {name: name}, Mastodon::FeaturedTag)
end

# Unfeature a tag
# @param tag_id [Integer]
def unfeature_tag(tag_id)
perform_request(:delete, "/api/v1/featured_tags/#{tag_id}")
end

# Get suggested tags to feature
# @return [Mastodon::Collection<Mastodon::Hashtag>]
def suggested_tags_to_feature
perform_request_with_collection(:get, '/api/v1/featured_tags/suggestions', {}, Mastodon::Hashtag)
end
end
end
end
7 changes: 7 additions & 0 deletions lib/mastodon/rest/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def add_accounts_to_list(id, account_ids = [])
def remove_accounts_from_list(id, account_ids = [])
perform_request(:delete, "/api/v1/lists/#{id}/accounts", { 'account_ids[]': account_ids })
end

# Lists that you have added the given account ID to
# @param id [Integer]
# @return [Mastodon::Collection<Mastodon::List>]
def lists_containing_account(account_id)
perform_request_with_collection(:get, "/api/v1/accounts/#{account_id}/lists", {}, Mastodon::List)
end
end
end
end
7 changes: 7 additions & 0 deletions lib/mastodon/rest/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ def notifications(options = {})
perform_request_with_collection(:get, '/api/v1/notifications', options, Mastodon::Notification)
end

# Get a single notification
# @param notification_id [Integer]
# @return Mastodon::Notification
def notification(notification_id)
perform_request_with_object(:get, "/api/v1/notifications/#{notification_id}", {}, Mastodon::Notification)
end

# Dismiss a notification
# @param id [Integer]
def dismiss_notification(id)
Expand Down
Loading