Skip to content

Commit d2f475b

Browse files
author
chetanr25
committed
Get user data function
1 parent 9364fdf commit d2f475b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/src/open_prices_api_client.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:path/path.dart';
88
import 'prices/currency.dart';
99
import 'prices/maybe_error.dart';
1010
import 'prices/price.dart';
11+
import 'prices/price_user.dart';
1112
import 'prices/proof.dart';
1213
import 'prices/get_locations_parameters.dart';
1314
import 'prices/get_locations_result.dart';
@@ -63,6 +64,28 @@ class OpenPricesAPIClient {
6364
addUserAgentParameters: addUserAgentParameters,
6465
);
6566

67+
static Future<MaybeError<PriceUser>> getUserProfile(
68+
final String userId,
69+
) async {
70+
final Uri uri = OpenPricesAPIClient.getUri(
71+
path: '/api/v1/users/$userId',
72+
);
73+
74+
final http.Response response =
75+
await HttpHelper().doGetRequest(uri, uriHelper: uriHelperFoodProd);
76+
try {
77+
if (response.statusCode == 200) {
78+
final dynamic decodedResponse = HttpHelper().jsonDecodeUtf8(response);
79+
return MaybeError<PriceUser>.value(
80+
PriceUser.fromJson(decodedResponse),
81+
);
82+
}
83+
} catch (e) {
84+
//
85+
}
86+
return MaybeError<PriceUser>.responseError(response);
87+
}
88+
6689
static Future<MaybeError<GetPricesResult>> getPrices(
6790
final GetPricesParameters parameters, {
6891
final UriProductHelper uriHelper = uriHelperFoodProd,

0 commit comments

Comments
 (0)