-
Notifications
You must be signed in to change notification settings - Fork 312
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
}) 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
} | ||
|
||
return GetServerSettingsResult.fromJson(data); | ||
|
@@ -67,7 +65,7 @@ class GetServerSettingsResult { | |
}); | ||
|
||
factory GetServerSettingsResult.fromJson(Map<String, dynamic> json) => | ||
_$GetServerSettingsResultFromJson(json); | ||
_$GetServerSettingsResultFromJson(json); | ||
|
||
Map<String, dynamic> toJson() => _$GetServerSettingsResultToJson(this); | ||
} |
There was a problem hiding this comment.
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 namedapiConnection
.