TLA Line data Source code
1 : // Copyright (c) 2026 Flipdare Pty Ltd. All rights reserved.
2 : //
3 : // This file is part of Flipdare's proprietary software and contains
4 : // confidential and copyrighted material. Unauthorised copying,
5 : // modification, distribution, or use of this file is strictly
6 : // prohibited without prior written permission from Flipdare Pty Ltd.
7 : //
8 : // This software includes third-party components licensed under MIT,
9 : // BSD, and Apache 2.0 licences. See THIRD_PARTY_NOTICES for details.
10 : //
11 :
12 : import 'package:core/admin/env.dart';
13 : import 'package:core/http/base_url.dart';
14 : import 'package:core/http/url_params.dart';
15 :
16 : class UrlEndpointFactory {
17 : final Environment env;
18 :
19 HIT 2 : UrlEndpointFactory() : env = environment;
20 :
21 6 : UrlEndpoint get firebase => UrlEndpoint(env.functionUrl, apiKey: env.flipApiKey);
22 4 : UrlEndpoint facebook(String uid) => UrlEndpoint(env.facebookUrl, uid: uid);
23 : }
24 :
25 : class UrlEndpoint {
26 : final String url;
27 : final Map<String, String>? _params;
28 :
29 : final String? endpoint;
30 : final String? uid;
31 : final String? apiKey;
32 :
33 1 : const UrlEndpoint(
34 : this.url, {
35 : this.endpoint,
36 : this.uid,
37 : this.apiKey,
38 : Map<String, String>? params,
39 : }) : _params = params;
40 :
41 5 : String? get params => (_params == null) ? null : UrlParams(_params).encoded;
42 :
43 1 : Uri get uri {
44 : String actualUrl;
45 :
46 1 : if (endpoint == null) {
47 5 : actualUrl = (uid == null) ? url : '$url/$uid';
48 : } else {
49 8 : actualUrl = (uid == null) ? '$url/$endpoint' : '$url/$endpoint/$uid';
50 : }
51 :
52 3 : return Url(actualUrl, params: _params).asUri;
53 : }
54 :
55 1 : @override
56 2 : String toString() => uri.toString();
57 : }
|