Skip to content

Commit

Permalink
feat: expose client properties (#12)
Browse files Browse the repository at this point in the history
To be able to identify the server and the user's own reviews.
  • Loading branch information
jpnurmi committed Jun 2, 2023
1 parent 4da820b commit c05ede5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
30 changes: 14 additions & 16 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ import 'review.dart';

class OdrsClient {
OdrsClient({
required Uri url,
required String userHash,
required String distro,
required this.url,
required this.userHash,
required this.distro,
HttpClient? client,
}) : _client = client ?? _createClient(url),
_url = url,
_userHash = userHash,
_distro = distro;
}) : _client = client ?? _createClient(url);

final HttpClient _client;
final Uri _url;
final String _userHash;
final String _distro;

final Uri url;
final String userHash;
final String distro;

static HttpClient _createClient(Uri url) {
final client = HttpClient();
Expand Down Expand Up @@ -56,11 +54,11 @@ class OdrsClient {
String? version,
}) {
final json = {
'user_hash': _userHash,
'user_hash': userHash,
'app_id': appId,
if (compatIds != null) 'compat_ids': compatIds,
'locale': locale ?? Platform.localeName,
'distro': _distro,
'distro': distro,
'limit': limit,
'start': start,
'version': version ?? 0,
Expand Down Expand Up @@ -95,7 +93,7 @@ class OdrsClient {
final json = {
'app_id': review.appId,
'review_id': review.reviewId,
'user_hash': _userHash,
'user_hash': userHash,
'user_skey': review.userSkey,
};
return _request('POST', '1.0/reviews/api/$vote', body: json);
Expand All @@ -112,10 +110,10 @@ class OdrsClient {
required String description,
}) {
final json = {
'user_hash': _userHash,
'user_hash': userHash,
'app_id': appId,
'locale': locale ?? Platform.localeName,
'distro': _distro,
'distro': distro,
'version': version,
'user_display': userDisplay,
'summary': summary,
Expand All @@ -134,7 +132,7 @@ class OdrsClient {
}) async {
final request = await _client.openUrl(
method,
_url.resolve(path).replace(queryParameters: queryParameters),
url.resolve(path).replace(queryParameters: queryParameters),
);
request.headers.contentType = ContentType.json;
for (final header in headers.entries) {
Expand Down
7 changes: 7 additions & 0 deletions test/odrs_client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ import 'odrs_client_test.mocks.dart';
void main() {
final localhost = Uri.https('localhost:8080');

test('client properties', () async {
final client = OdrsClient(url: localhost, userHash: 'foo', distro: 'bar');
expect(client.url, equals(localhost));
expect(client.userHash, equals('foo'));
expect(client.distro, equals('bar'));
});

test('get ratings', () async {
final http = MockHttpClient();
final url = localhost.resolve('/1.0/reviews/api/ratings');
Expand Down

0 comments on commit c05ede5

Please sign in to comment.