Skip to content

Commit

Permalink
refactor(dynamite_runtime)!: Remove executeRequest and executeRawRequ…
Browse files Browse the repository at this point in the history
…est methods

Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Apr 4, 2024
1 parent 207623c commit eb9e018
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 51 deletions.
2 changes: 0 additions & 2 deletions packages/dynamite/dynamite/lib/src/helpers/dart_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ extension StringUtils on String {
}

const _reservedMethodNames = [
'executeRequest',
'executeRawRequest',
'send',
'head',
'get',
Expand Down
42 changes: 0 additions & 42 deletions packages/dynamite/dynamite_runtime/lib/src/client/client.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:async';
import 'dart:typed_data';

import 'package:cookie_jar/cookie_jar.dart';
import 'package:dynamite_runtime/src/client/authentication.dart';
Expand Down Expand Up @@ -55,47 +54,6 @@ class DynamiteClient with http.BaseClient {
/// The first one matching the required authentication type will be used.
final List<DynamiteAuthentication>? authentications;

/// Makes a request against a given [path].
///
/// The query parameters of the [baseURL] are added.
/// The [path] is resolved against the path of the [baseURL].
/// All [baseHeaders] are added to the request.
Future<http.StreamedResponse> executeRequest(
String method,
String path, {
Map<String, String>? headers,
Uint8List? body,
}) {
final uri = Uri.parse('$baseURL$path');

return executeRawRequest(
method,
uri,
headers: headers,
body: body,
);
}

/// Executes a HTTP request against give full [uri].
Future<http.StreamedResponse> executeRawRequest(
String method,
Uri uri, {
Map<String, String>? headers,
Uint8List? body,
}) async {
final request = http.Request(method, uri);

if (headers != null) {
request.headers.addAll(headers);
}

if (body != null) {
request.bodyBytes = body;
}

return send(request);
}

/// Sends an HTTP request and asynchronously returns the response.
///
/// Cookies are persisted in the [cookieJar] and loaded for requests.
Expand Down
13 changes: 9 additions & 4 deletions packages/dynamite/dynamite_runtime/test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() {
);

await cookieJar.saveFromResponse(uri, [Cookie('a', 'b')]);
await client.executeRequest('GET', '');
await client.get(uri);

final cookies = await cookieJar.loadForRequest(uri);
expect(cookies, hasLength(2));
Expand All @@ -55,7 +55,7 @@ void main() {
cookieJar: cookieJar,
);

await client.executeRequest('GET', '');
await client.get(uri);
});
});

Expand Down Expand Up @@ -83,7 +83,7 @@ void main() {
},
);

await client.executeRawRequest('GET', uri);
await client.get(uri);
});

test('request overwrites base headers', () async {
Expand All @@ -109,7 +109,12 @@ void main() {
},
);

await client.executeRawRequest('GET', uri, headers: {'some-key': 'some-other-value'});
await client.get(
uri,
headers: {
'some-key': 'some-other-value',
},
);
});
});
}
3 changes: 1 addition & 2 deletions packages/neon_framework/lib/src/utils/request_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ class RequestManager {
account: account,
cacheKey: uri.toString(),
getCacheParameters: () async {
final response = await account.client.executeRawRequest(
'HEAD',
final response = await account.client.head(

Check warning on line 184 in packages/neon_framework/lib/src/utils/request_manager.dart

View check run for this annotation

Codecov / codecov/patch

packages/neon_framework/lib/src/utils/request_manager.dart#L184

Added line #L184 was not covered by tests
uri,
headers: headers,
);
Expand Down
2 changes: 1 addition & 1 deletion tool/find-untested-neon-apis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cd "$(dirname "$0")/.."

function find_apis() {
# shellcheck disable=SC2068
grep -r $@ --include "*\.dart" -e "client\([0-9]\)\?\.[^.]*.[^(]*(" -oh | sed "s/^client\([0-9]\)\?\.//" | sed "s/($//" | sed "s/Raw$//" | grep -v "_Serializer" | grep -v "send" | grep -v "_Request" | grep -v "^executeRawRequest" | sort | uniq
grep -r $@ --include "*\.dart" -e "client\([0-9]\)\?\.[^.]*.[^(]*(" -oh | sed "s/^client\([0-9]\)\?\.//" | sed "s/($//" | grep -v "_Serializer" | grep -v "send" | grep -v "head" | grep -v "_Request" | sort | uniq
}

used_apis=("$(find_apis "packages/neon_framework" "packages/neon/"*)")
Expand Down

0 comments on commit eb9e018

Please sign in to comment.