-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.rb
62 lines (50 loc) · 1.61 KB
/
plugin.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true
# name: discourse-launchpad-onebox
# about: Onebox plugin to show launchpad group members
# version: 1.0.0
# authors: Philipp Kewisch (@kewisch)
# url: https://github.com/kewisch/discourse-launchpad-onebox
require_relative '../../lib/onebox'
class Onebox::Engine::LaunchpadMemberOnebox
include Onebox::Engine
REGEX = %r{^https://launchpad.net/~(?<group>[a-z][a-z0-9-]*)/\+members$}
matches_regexp(REGEX)
always_https
def match
@match ||= @url.match(REGEX)
end
def to_html
html = <<~HTML
<aside class="onebox allowlistedgeneric" data-onebox-src="#{@url}">
<header class="source">
<img class="site-icon" src="https://launchpad.net/@@/favicon-32x32.png?v=2022">
<a href="#{group_raw['web_link']}" target="_blank" rel="nofollow ugc noopener" tabindex="-1">Launchpad</a>
</header>
<article class="onebox-body">
<h3>#{group_raw['display_name']}</h3>
<p>
<ul>
HTML
raw['entries'].each do |item|
html += "\n<li><a href='#{item['web_link']}'>#{item['display_name']}</a></li>"
end
html += <<~HTML
</ul>
</p>
</article>
</aside>
HTML
html
end
def data
raw['entries'].clone
end
def raw
members_url = "https://api.launchpad.net/devel/~#{match[:group]}/members"
@raw ||= ::MultiJson.load(URI.parse(members_url).open(read_timeout: timeout))
end
def group_raw
group_url = "https://api.launchpad.net/devel/~#{match[:group]}"
@group_raw ||= ::MultiJson.load(URI.parse(group_url).open(read_timeout: timeout))
end
end