Skip to content

Parameterize the ApiConnection in getServerSettings. #103

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/api/route/realm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ part 'realm.g.dart';
// See thread, and the zulip-mobile code and chat thread it links to:
// https://github.com/zulip/zulip-flutter/pull/55#discussion_r1160267577
Future<GetServerSettingsResult> getServerSettings({
required Uri realmUrl,
required ApiConnection apiConnection,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This interface should align with the other functions in this directory that do a similar job of providing a binding to an API endpoint: a positional parameter named connection, rather than a named parameter named apiConnection.

}) async {
final Map<String, dynamic> data;
// TODO make this function testable by taking ApiConnection from caller
final connection = ApiConnection.live(realmUrl: realmUrl);
try {
data = await connection.get('server_settings', null);
data = await apiConnection.get('server_settings', null);
} finally {
connection.close();
apiConnection.close();
Comment on lines 24 to +25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The responsibility for closing the connection should stay with the same code that's opening it. So when this function starts getting the ApiConnection from its caller, this part should move to the caller too.

For similar code to compare to, see the other API-endpoint bindings in other files of this lib/api/route/ directory.

}

return GetServerSettingsResult.fromJson(data);
Expand Down Expand Up @@ -67,7 +65,7 @@ class GetServerSettingsResult {
});

factory GetServerSettingsResult.fromJson(Map<String, dynamic> json) =>
_$GetServerSettingsResultFromJson(json);
_$GetServerSettingsResultFromJson(json);

Map<String, dynamic> toJson() => _$GetServerSettingsResultToJson(this);
}
Loading