Skip to content

Commit 7934c1e

Browse files
SuperTux88denschub
authored andcommitted
Add NodeInfo 2.0 support
1 parent c2eb53e commit 7934c1e

File tree

6 files changed

+252
-23
lines changed

6 files changed

+252
-23
lines changed

app/presenters/node_info_presenter.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def add_configuration(doc)
2626

2727
def add_static_data(doc)
2828
doc.software.name = "diaspora"
29-
doc.protocols.inbound << "diaspora"
30-
doc.protocols.outbound << "diaspora"
29+
doc.protocols.protocols << "diaspora"
3130
end
3231

3332
def add_user_counts(doc)

lib/node_info.rb

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require "json-schema"
33

44
module NodeInfo
5-
VERSIONS = %w(1.0)
5+
VERSIONS = %w(1.0 2.0).freeze
66
SCHEMAS = {}
77
private_constant :VERSIONS, :SCHEMAS
88

@@ -21,17 +21,21 @@ def version_10_hash
2121
end
2222
end
2323

24-
Protocols = Struct.new(:inbound, :outbound) do
25-
def initialize(inbound=[], outbound=[])
26-
super(inbound, outbound)
24+
Protocols = Struct.new(:protocols) do
25+
def initialize(protocols=[])
26+
super(protocols)
2727
end
2828

2929
def version_10_hash
3030
{
31-
"inbound" => inbound,
32-
"outbound" => outbound
31+
"inbound" => protocols,
32+
"outbound" => protocols
3333
}
3434
end
35+
36+
def version_20_array
37+
protocols
38+
end
3539
end
3640

3741
Services = Struct.new(:inbound, :outbound) do
@@ -90,6 +94,8 @@ def as_json(_options={})
9094
case version
9195
when "1.0"
9296
version_10_hash
97+
when "2.0"
98+
version_20_hash
9399
end
94100
end
95101

@@ -124,6 +130,18 @@ def version_10_hash
124130
)
125131
end
126132

133+
def version_20_hash
134+
deep_compact(
135+
"version" => "2.0",
136+
"software" => software.version_10_hash,
137+
"protocols" => protocols.version_20_array,
138+
"services" => services.version_10_hash,
139+
"openRegistrations" => open_registrations,
140+
"usage" => usage.version_10_hash,
141+
"metadata" => metadata
142+
)
143+
end
144+
127145
def deep_compact(hash)
128146
hash.tap do |hash|
129147
hash.reject! {|_, value|

spec/controllers/node_info_controller_spec.rb

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
expect(jrd).to include "links" => [{
1616
"rel" => "http://nodeinfo.diaspora.software/ns/schema/1.0",
1717
"href" => node_info_url("1.0")
18+
}, {
19+
"rel" => "http://nodeinfo.diaspora.software/ns/schema/2.0",
20+
"href" => node_info_url("2.0")
1821
}]
1922
end
2023
end
@@ -28,24 +31,27 @@
2831
end
2932
end
3033

31-
context "version 1.0" do
32-
it "responds to JSON" do
33-
get :document, version: "1.0", format: :json
34+
%w(1.0 2.0).each do |version|
35+
context "version #{version}" do
36+
it "responds to JSON" do
37+
get :document, version: version, format: :json
3438

35-
expect(response).to be_success
36-
end
39+
expect(response).to be_success
40+
end
3741

38-
it "calls NodeInfoPresenter" do
39-
expect(NodeInfoPresenter).to receive(:new).with("1.0")
40-
.and_return(double(as_json: {}, content_type: "application/json"))
42+
it "calls NodeInfoPresenter" do
43+
expect(NodeInfoPresenter).to receive(:new).with(version)
44+
.and_return(double(as_json: {}, content_type: "application/json"))
4145

42-
get :document, version: "1.0", format: :json
43-
end
46+
get :document, version: version, format: :json
47+
end
4448

45-
it "notes the schema in the content type" do
46-
get :document, version: "1.0", format: :json
49+
it "notes the schema in the content type" do
50+
get :document, version: version, format: :json
4751

48-
expect(response.content_type).to eq "application/json; profile=http://nodeinfo.diaspora.software/ns/schema/1.0#"
52+
expect(response.content_type)
53+
.to eq("application/json; profile=http://nodeinfo.diaspora.software/ns/schema/#{version}#")
54+
end
4955
end
5056
end
5157
end

spec/lib/connection_tester_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@
116116
ni_document = NodeInfo.build do |doc|
117117
doc.version = "1.0"
118118
doc.open_registrations = true
119-
doc.protocols.inbound << "diaspora"
120-
doc.protocols.outbound << "diaspora"
119+
doc.protocols.protocols << "diaspora"
121120
doc.software.name = "diaspora"
122121
doc.software.version = "a.b.c.d"
123122
end

spec/presenters/node_info_presenter_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,30 @@
128128
expect(hash).to include "metadata" => include("xmppChat" => true)
129129
end
130130
end
131+
132+
context "version 2.0" do
133+
it "provides generic pod data in json" do
134+
expect(NodeInfoPresenter.new("2.0").as_json.as_json).to eq(
135+
"version" => "2.0",
136+
"software" => {
137+
"name" => "diaspora",
138+
"version" => AppConfig.version_string
139+
},
140+
"protocols" => ["diaspora"],
141+
"services" => {
142+
"inbound" => [],
143+
"outbound" => AppConfig.configured_services.map(&:to_s)
144+
},
145+
"openRegistrations" => AppConfig.settings.enable_registrations?,
146+
"usage" => {
147+
"users" => {}
148+
},
149+
"metadata" => {
150+
"nodeName" => AppConfig.settings.pod_name,
151+
"xmppChat" => AppConfig.chat.enabled?
152+
}
153+
)
154+
end
155+
end
131156
end
132157
end

vendor/nodeinfo/schemas/2.0.json

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
2+
3+
{
4+
"$schema": "http://json-schema.org/draft-04/schema#",
5+
"id": "http://nodeinfo.diaspora.software/ns/schema/2.0#",
6+
"description": "NodeInfo schema version 2.0.",
7+
"type": "object",
8+
"additionalProperties": false,
9+
"required": [
10+
"version",
11+
"software",
12+
"protocols",
13+
"services",
14+
"openRegistrations",
15+
"usage",
16+
"metadata"
17+
],
18+
"properties": {
19+
"version": {
20+
"description": "The schema version, must be 2.0.",
21+
"enum": [
22+
"2.0"
23+
]
24+
},
25+
"software": {
26+
"description": "Metadata about server software in use.",
27+
"type": "object",
28+
"additionalProperties": false,
29+
"required": [
30+
"name",
31+
"version"
32+
],
33+
"properties": {
34+
"name": {
35+
"description": "The canonical name of this server software.",
36+
"type": "string",
37+
"pattern": "^[a-z0-9-]+$"
38+
},
39+
"version": {
40+
"description": "The version of this server software.",
41+
"type": "string"
42+
}
43+
}
44+
},
45+
"protocols": {
46+
"description": "The protocols supported on this server.",
47+
"type": "array",
48+
"minItems": 1,
49+
"items": {
50+
"enum": [
51+
"activitypub",
52+
"buddycloud",
53+
"dfrn",
54+
"diaspora",
55+
"libertree",
56+
"ostatus",
57+
"pumpio",
58+
"tent",
59+
"xmpp",
60+
"zot"
61+
]
62+
}
63+
},
64+
"services": {
65+
"description": "The third party sites this server can connect to via their application API.",
66+
"type": "object",
67+
"additionalProperties": false,
68+
"required": [
69+
"inbound",
70+
"outbound"
71+
],
72+
"properties": {
73+
"inbound": {
74+
"description": "The third party sites this server can retrieve messages from for combined display with regular traffic.",
75+
"type": "array",
76+
"minItems": 0,
77+
"items": {
78+
"enum": [
79+
"atom1.0",
80+
"gnusocial",
81+
"imap",
82+
"pnut",
83+
"pop3",
84+
"pumpio",
85+
"rss2.0",
86+
"twitter"
87+
]
88+
}
89+
},
90+
"outbound": {
91+
"description": "The third party sites this server can publish messages to on the behalf of a user.",
92+
"type": "array",
93+
"minItems": 0,
94+
"items": {
95+
"enum": [
96+
"atom1.0",
97+
"blogger",
98+
"buddycloud",
99+
"diaspora",
100+
"dreamwidth",
101+
"drupal",
102+
"facebook",
103+
"friendica",
104+
"gnusocial",
105+
"google",
106+
"insanejournal",
107+
"libertree",
108+
"linkedin",
109+
"livejournal",
110+
"mediagoblin",
111+
"myspace",
112+
"pinterest",
113+
"pnut",
114+
"posterous",
115+
"pumpio",
116+
"redmatrix",
117+
"rss2.0",
118+
"smtp",
119+
"tent",
120+
"tumblr",
121+
"twitter",
122+
"wordpress",
123+
"xmpp"
124+
]
125+
}
126+
}
127+
}
128+
},
129+
"openRegistrations": {
130+
"description": "Whether this server allows open self-registration.",
131+
"type": "boolean"
132+
},
133+
"usage": {
134+
"description": "Usage statistics for this server.",
135+
"type": "object",
136+
"additionalProperties": false,
137+
"required": [
138+
"users"
139+
],
140+
"properties": {
141+
"users": {
142+
"description": "statistics about the users of this server.",
143+
"type": "object",
144+
"additionalProperties": false,
145+
"properties": {
146+
"total": {
147+
"description": "The total amount of on this server registered users.",
148+
"type": "integer",
149+
"minimum": 0
150+
},
151+
"activeHalfyear": {
152+
"description": "The amount of users that signed in at least once in the last 180 days.",
153+
"type": "integer",
154+
"minimum": 0
155+
},
156+
"activeMonth": {
157+
"description": "The amount of users that signed in at least once in the last 30 days.",
158+
"type": "integer",
159+
"minimum": 0
160+
}
161+
}
162+
},
163+
"localPosts": {
164+
"description": "The amount of posts that were made by users that are registered on this server.",
165+
"type": "integer",
166+
"minimum": 0
167+
},
168+
"localComments": {
169+
"description": "The amount of comments that were made by users that are registered on this server.",
170+
"type": "integer",
171+
"minimum": 0
172+
}
173+
}
174+
},
175+
"metadata": {
176+
"description": "Free form key value pairs for software specific values. Clients should not rely on any specific key present.",
177+
"type": "object",
178+
"minProperties": 0,
179+
"additionalProperties": true
180+
}
181+
}
182+
}

0 commit comments

Comments
 (0)