| 1 |
|
| 2 |
|
| 3 |
module Plugin::Mastodon |
| 4 |
class RestPublicType < Diva::Model |
| 5 |
field.has :server, Plugin::Mastodon::Instance, required: true |
| 6 |
|
| 7 |
attr_reader :datasource_slug |
| 8 |
attr_reader :title |
| 9 |
attr_reader :perma_link |
| 10 |
|
| 11 |
def token |
| 12 |
nil |
| 13 |
end |
| 14 |
|
| 15 |
def response_entities |
| 16 |
:status |
| 17 |
end |
| 18 |
|
| 19 |
def public(only_media: false) |
| 20 |
params[:only_media] = only_media |
| 21 |
if only_media |
| 22 |
@datasource_slug = "mastodon-#{server.domain}-federated-media".to_sym |
| 23 |
@title = Plugin[:mastodon]._("Mastodon/%{domain}/連合タイムライン(メディアのみ)") % {domain: server.domain} |
| 24 |
else |
| 25 |
@datasource_slug = "mastodon-#{server.domain}-federated".to_sym |
| 26 |
@title = Plugin[:mastodon]._("Mastodon/%{domain}/連合タイムライン(全て)") % {domain: server.domain} |
| 27 |
end |
| 28 |
set_endpoint('public') |
| 29 |
end |
| 30 |
|
| 31 |
def public_local(only_media: false) |
| 32 |
params[:only_media] = only_media |
| 33 |
params[:local] = 1 |
| 34 |
if only_media |
| 35 |
@datasource_slug = "mastodon-#{server.domain}-local-media".to_sym |
| 36 |
@title = Plugin[:mastodon]._("Mastodon/%{domain}/ローカルタイムライン(メディアのみ)") % {domain: server.domain} |
| 37 |
else |
| 38 |
@datasource_slug = "mastodon-#{server.domain}-local".to_sym |
| 39 |
@title = Plugin[:mastodon]._("Mastodon/%{domain}/ローカルタイムライン(全て)") % {domain: server.domain} |
| 40 |
end |
| 41 |
set_endpoint('public') |
| 42 |
end |
| 43 |
|
| 44 |
def set_endpoint(endpoint) |
| 45 |
@perma_link = Diva::URI.new('https://%{domain}/api/v1/timelines/%{endpoint}' % { |
| 46 |
domain: server.domain, |
| 47 |
endpoint: endpoint, |
| 48 |
}) |
| 49 |
self |
| 50 |
end |
| 51 |
|
| 52 |
def params |
| 53 |
@params ||= {} |
| 54 |
end |
| 55 |
|
| 56 |
def inspect |
| 57 |
"#<#{self.class}: #{@datasource_slug} #{@perma_link}>" |
| 58 |
end |
| 59 |
end |
| 60 |
end |