Skip to content

Commit

Permalink
refactor: prefer clientFactories parameter to addClientFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
JKRhb committed Dec 19, 2023
1 parent 4489819 commit 3d863e7
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 20 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ import 'package:dart_wot/dart_wot.dart';
Future<void> main(List<String> args) async {
final CoapClientFactory coapClientFactory = CoapClientFactory();
final servient = Servient()..addClientFactory(coapClientFactory);
final servient = Servient(
protocolClients: [coapClientFactory]
);
final wot = await servient.start();
final thingDescriptionJson = '''
Expand Down
2 changes: 1 addition & 1 deletion example/coap_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Future<void> handleThingDescription(
}

Future<void> main(List<String> args) async {
final servient = Servient()..addClientFactory(CoapClientFactory());
final servient = Servient(clientFactories: [CoapClientFactory()]);

final wot = await servient.start();
final uri = Uri.parse('coap://plugfest.thingweb.io:5683/testthing');
Expand Down
6 changes: 5 additions & 1 deletion example/coap_dns_sd_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ void handleThingDescription(ThingDescription thingDescription) =>
print('Discovered TD with title "${thingDescription.title}".');

Future<void> main(List<String> args) async {
final servient = Servient()..addClientFactory(CoapClientFactory());
final servient = Servient(
clientFactories: [
CoapClientFactory(),
],
);

final wot = await servient.start();
final uri = Uri.parse('_wot._udp.local');
Expand Down
7 changes: 6 additions & 1 deletion example/coaps_readproperty.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ Future<void> main(List<String> args) async {
),
pskCredentialsCallback: _pskCredentialsCallback,
);
final servient = Servient()..addClientFactory(coapClientFactory);

final servient = Servient(
clientFactories: [
coapClientFactory,
],
);

final wot = await servient.start();

Expand Down
18 changes: 11 additions & 7 deletions example/complex_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,19 @@ Future<BasicCredentials?> basicCredentialsCallback(
}

Future<void> main() async {
const coapConfig = CoapConfig(blocksize: 64);
final CoapClientFactory coapClientFactory = CoapClientFactory(
coapConfig: coapConfig,
final coapClientFactory = CoapClientFactory(
coapConfig: const CoapConfig(blocksize: 64),
);
final HttpClientFactory httpClientFactory =

final httpClientFactory =
HttpClientFactory(basicCredentialsCallback: basicCredentialsCallback);
final servient = Servient()
..addClientFactory(coapClientFactory)
..addClientFactory(httpClientFactory);

final servient = Servient(
clientFactories: [
coapClientFactory,
httpClientFactory,
],
);
final wot = await servient.start();

final thingDescription = ThingDescription(thingDescriptionJson);
Expand Down
2 changes: 1 addition & 1 deletion example/core_link_format_discovery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const propertyName = 'status';
const actionName = 'toggle';

Future<void> main(List<String> args) async {
final servient = Servient()..addClientFactory(CoapClientFactory());
final servient = Servient(clientFactories: [CoapClientFactory()]);

final wot = await servient.start();

Expand Down
11 changes: 8 additions & 3 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ Future<void> main(List<String> args) async {
HttpClientFactory(basicCredentialsCallback: basicCredentialsCallback);
final MqttClientFactory mqttClientFactory = MqttClientFactory();
final servient = Servient()
..addClientFactory(coapClientFactory)
..addClientFactory(httpClientFactory)
..addClientFactory(mqttClientFactory);
final servient = Servient(
clientFactories: [
coapClientFactory,
httpClientFactory,
mqttClientFactory,
],
);

final wot = await servient.start();

const thingDescriptionJson = '''
Expand Down
6 changes: 5 additions & 1 deletion example/http_basic_authentication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ Future<BasicCredentials?> basicCredentialsCallback(
Future<void> main(List<String> args) async {
final HttpClientFactory httpClientFactory =
HttpClientFactory(basicCredentialsCallback: basicCredentialsCallback);
final servient = Servient()..addClientFactory(httpClientFactory);
final servient = Servient(
clientFactories: [
httpClientFactory,
],
);
final wot = await servient.start();

final thingDescription = ThingDescription(thingDescriptionJson);
Expand Down
7 changes: 4 additions & 3 deletions test/binding_http/http_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,14 @@ void main() {
]) async =>
bearerCredentialsStore[uri.host];

final servient = Servient()
..addClientFactory(
final servient = Servient(
clientFactories: [
HttpClientFactory(
basicCredentialsCallback: basicCredentialsCallback,
bearerCredentialsCallback: bearerCredentialsCallback,
),
);
],
);
final wot = await servient.start();

final consumedThing = await wot.consume(parsedTd);
Expand Down
2 changes: 1 addition & 1 deletion test/core/consumed_thing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void main() {

final parsedTd = ThingDescription(thingDescriptionJson);

final servient = Servient()..addClientFactory(HttpClientFactory());
final servient = Servient(clientFactories: [HttpClientFactory()]);
final wot = await servient.start();

final uriVariables = {'value': 'SFRUUEJJTiBpcyBhd2Vzb21l'};
Expand Down

0 comments on commit 3d863e7

Please sign in to comment.