Skip to content

Commit

Permalink
feat: add initial support for query parameters to exploreDirectory me…
Browse files Browse the repository at this point in the history
…thod
  • Loading branch information
JKRhb committed Jan 5, 2024
1 parent 7adfed6 commit 8f99cd8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
22 changes: 18 additions & 4 deletions lib/src/core/implementation/wot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,17 @@ class WoT implements scripting_api.WoT {

@override
Future<scripting_api.ThingDiscoveryProcess> exploreDirectory(
Uri url, [
Uri url, {
scripting_api.ThingFilter? filter,
]) async {
int? offset,
int? limit,
scripting_api.DirectoryPayloadFormat? format,
}) async {
// TODO(JKRhb): Add support for the collection format.
if (format == scripting_api.DirectoryPayloadFormat.collection) {
throw ArgumentError('Format "$format" is currently not supported.');
}

final thingDescription = await requestThingDescription(url);

if (!thingDescription.isValidDirectoryThingDescription) {
Expand All @@ -124,8 +132,14 @@ class WoT implements scripting_api.WoT {

final consumedDirectoryThing = await consume(thingDescription);

final interactionOutput =
await consumedDirectoryThing.readProperty("things");
final interactionOutput = await consumedDirectoryThing.readProperty(
"things",
uriVariables: {
if (offset != null) "offset": offset,
if (limit != null) "limit": limit,
if (format != null) "format": format.toString(),
},
);
final rawThingDescriptions = await interactionOutput.value();

if (rawThingDescriptions is! List<Object?>) {
Expand Down
36 changes: 34 additions & 2 deletions lib/src/core/scripting_api/wot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,35 @@ import "discovery/thing_filter.dart";
import "exposed_thing.dart";
import "types.dart";

/// Enumeration for specifying the value of the `format` query parameter when
/// using the `exploreDirectory` discovery method.
///
/// See [section 7.3.2.1.5] of the [WoT Discovery] specification for more
/// information.
///
/// [WoT Discovery]: https://www.w3.org/TR/2023/REC-wot-discovery-20231205
/// [section 7.3.2.1.5]: https://www.w3.org/TR/2023/REC-wot-discovery-20231205/#exploration-directory-api-things-listing
enum DirectoryPayloadFormat {
/// Indicates that an array of Thing Descriptions should be returned.
///
/// This is the default value.
array,

/// Indicates that an collection of Thing Descriptions should be returned.
collection,
;

@override
String toString() {
switch (this) {
case array:
return "array";
case collection:
return "collection";
}
}
}

/// Interface for a [WoT] runtime.
///
/// See WoT Scripting API specification,
Expand All @@ -39,9 +68,12 @@ abstract interface class WoT {
/// [ThingDescription] objects for Thing Descriptions that match an optional
/// [filter] argument of type [ThingFilter].
Future<ThingDiscoveryProcess> exploreDirectory(
Uri url, [
Uri url, {
ThingFilter? filter,
]);
int? offset,
int? limit,
DirectoryPayloadFormat? format,
});

/// Discovers [ThingDescription]s from a given [url] using the specified
/// [method].
Expand Down

0 comments on commit 8f99cd8

Please sign in to comment.