diff --git a/model/CHANGELOG.md b/model/CHANGELOG.md index 50fc76c..c1ed2a4 100644 --- a/model/CHANGELOG.md +++ b/model/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.4.0 + +* Add `MockOgHrefClient.advance` for building responding content with different content type applied. + ## 3.3.4 * Restrict `MockOgHrefClient` accepted requesting `GET` and `HEAD` method. diff --git a/model/lib/src/client/mock_client.dart b/model/lib/src/client/mock_client.dart index 9e547b9..0e9e5ad 100644 --- a/model/lib/src/client/mock_client.dart +++ b/model/lib/src/client/mock_client.dart @@ -190,7 +190,7 @@ final class MockOgHrefClient extends BaseClient /// * [MockOgHrefClient.quick] : Quick builder version of [MockOgHrefClient] /// that [Uri]s are mapping with [String] content with unified /// content type. - MockOgHrefClient(Map contentLinker, + MockOgHrefClient.advance(Map contentLinker, {String errorContentType = _PLAIN_TEXT_MIME}) { if (contentLinker.keys.any((element) => !_isHttpScheme(element))) { throw ArgumentError( @@ -235,14 +235,19 @@ final class MockOgHrefClient extends BaseClient /// [contentType] which uses `text/plain` as default. /// /// For setting [contentLinker] without identical [contentType], - /// please uses [MockOgHrefClient.new] instead. - factory MockOgHrefClient.quick(Map contentLinker, - {String contentType}) = _QuickMockOgHrefClient; + /// please uses [MockOgHrefClient.advance] instead. + factory MockOgHrefClient(Map contentLinker, + {String contentType = _PLAIN_TEXT_MIME}) { + return MockOgHrefClient.advance({ + for (var MapEntry(key: url, value: body) in contentLinker.entries) + url: MockOgHrefClientContent(content: body, contentType: contentType) + }); + } /// Uses [sample files](https://github.com/rk0cc/oghref/tree/main/model/sample) to defined /// content of the simulated HTML files with hosted IP address as `127.0.0.2` with `HTTPS` /// protocol. - factory MockOgHrefClient.usesSample() => _QuickMockOgHrefClient({ + factory MockOgHrefClient.usesSample() => MockOgHrefClient({ for (int idx = 0; idx < _sampleContents.length; idx++) _sampleMockHost.resolve("${idx + 1}.html"): _sampleContents[idx] }); @@ -264,13 +269,3 @@ final class MockOgHrefClient extends BaseClient return _c.send(request).timeout(Duration(seconds: OgHrefClient.timeoutAt)); } } - -final class _QuickMockOgHrefClient extends MockOgHrefClient { - _QuickMockOgHrefClient(Map contentLinker, - {String contentType = "text/plain"}) - : super({ - for (var MapEntry(key: url, value: body) in contentLinker.entries) - url: - MockOgHrefClientContent(content: body, contentType: contentType) - }); -} diff --git a/model/pubspec.yaml b/model/pubspec.yaml index 1148d56..e5bc71b 100644 --- a/model/pubspec.yaml +++ b/model/pubspec.yaml @@ -1,6 +1,6 @@ name: oghref_model description: Object standarized definition with parser interface for constructing rich information of given URL among various metadata protocols. -version: 3.3.4 +version: 3.4.0 repository: https://github.com/rk0cc/oghref/tree/main/model issue_tracker: https://github.com/rk0cc/oghref/issues funding: