Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit a4fd191

Browse files
committed
Added connector metadata sample and REST API endpoints.
1 parent d85d12b commit a4fd191

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<connector>
2+
<display>Twitch Chat</display>
3+
<description>TODO</description>
4+
<wiki>https://github.com/codeoverflow-org/chatoverflow/wiki/Twitch-Chat</wiki>
5+
<icon48>
6+
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAC4AAAAwCAYAAABuZUjcAAABEklEQVRoge3X0Q2CMBRA0QthGpzCIXQC9wB3cSXn0Y9ColJoi32PvqT3R4JNOGmaQpvb+cFUDzwxUvtxfTlMsSPz8B44HQlJbYabmm2AbvpdgzdakECv3xstBpcJOLi5ZQIOfj0asad5qZirDQ8pM7PwLjwkqsV2xfZWmjp+kdkZr3DtKly7CteuwrWrcO3MwnN9ZKWeTf8+y5qd8QoXbPDdLB0+AKPvj5Lhq2jgXip8Ew2MJcKDaChvqUShIfwC8p3GffleKFuI1L7QIDfjomiQgYujIT9cBQ154WpoyAdXRUM+ePBBkUWhoax9PBoNbh9P+aiP3dd3YVKSnHExNMjBRdEgAxdHQ364ChrywtXQAG9A2SgNqLuDfQAAAABJRU5ErkJggg==
7+
</icon48>
8+
</connector>

src/main/scala/org/codeoverflow/chatoverflow/ui/web/rest/DTOs.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ object DTOs {
2121

2222
case class Types(pluginTypes: Seq[PluginType], requirementTypes: RequirementTypes, connectorTypes: Seq[String])
2323

24+
case class ConnectorMetadata(found: Boolean, displayName: String, description: String, wikiUrl: String, icon: String)
25+
2426
case class RequirementTypes(input: Seq[String], output: Seq[String], parameter: Seq[String])
2527

2628
case class APIAndSpecificType(interface: String, implementation: String, connector: String, found: Boolean)

src/main/scala/org/codeoverflow/chatoverflow/ui/web/rest/types/TypeController.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ class TypeController(implicit val swagger: Swagger) extends JsonServlet with Typ
3131
}
3232
}
3333

34+
get("/connector/metadata", operation(getConnectorsMetadata)) {
35+
authKeyRequired {
36+
getConnectorTypes.map(typeString => typeString -> readConnectorMetadata(typeString))
37+
}
38+
}
39+
40+
get("/connector/metadata/:qualifiedConnectorType", operation(getConnectorMetadata)) {
41+
authKeyRequired {
42+
val qualifiedConnectorType = params("qualifiedConnectorType")
43+
readConnectorMetadata(qualifiedConnectorType)
44+
}
45+
}
46+
3447
get("/", operation(getTypes)) {
3548
authKeyRequired {
3649
Types(getPluginTypes, getRequirementTypes, getConnectorTypes)
@@ -78,4 +91,20 @@ class TypeController(implicit val swagger: Swagger) extends JsonServlet with Typ
7891

7992
private def getConnectorTypes = chatOverflow.typeRegistry.getConnectorTypes
8093

94+
private def readConnectorMetadata(typeString: String): ConnectorMetadata = {
95+
96+
val ressource = getClass.getResourceAsStream(s"/connector/${typeString.toLowerCase}.xml")
97+
98+
if (ressource == null) {
99+
ConnectorMetadata(found = false, "", "", "", "")
100+
} else {
101+
val node = xml.Utility.trim(xml.XML.load(ressource))
102+
ConnectorMetadata(found = true,
103+
(node \ "display").text,
104+
(node \ "description").text,
105+
(node \ "wiki").text,
106+
(node \ "icon48").text)
107+
}
108+
}
109+
81110
}

src/main/scala/org/codeoverflow/chatoverflow/ui/web/rest/types/TypesControllerDefinition.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,19 @@ trait TypesControllerDefinition extends SwaggerSupport with TagSupport with Auth
2525
description "Shows the fully qualified type strings of all connectors."
2626
parameter authHeader
2727
tags controllerTag)
28+
val getConnectorsMetadata: OperationBuilder =
29+
(apiOperation[Map[String, ConnectorMetadata]]("getConnectorsMetadata")
30+
summary "Shows the metadata of all connectors, if found."
31+
description "Shows a map of connector type string and metadata with display name, description, wiki url and base64 encoded icon."
32+
parameter authHeader
33+
tags controllerTag)
34+
val getConnectorMetadata: OperationBuilder =
35+
(apiOperation[ConnectorMetadata]("getConnectorMetadata")
36+
summary "Shows the metadata of a specified connector, if found."
37+
description "Shows the connectors metadata with display name, description, wiki url and base64 encoded icon."
38+
parameter pathParam[String]("qualifiedConnectorType").description("The qualified connector type string of a registered connector.")
39+
parameter authHeader
40+
tags controllerTag)
2841
val getTypes: OperationBuilder =
2942
(apiOperation[Types]("getTypes")
3043
summary "Shows all possible types of plugins, requirements and connectors."

0 commit comments

Comments
 (0)