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 :
14 : class HttpHeader {
15 : final String key;
16 : final String value;
17 :
18 : static const HttpHeader post_ = HttpHeader('Content-Type', 'application/x-www-form-urlencoded');
19 : static const HttpHeader get_ = HttpHeader('Content-Type', 'application/json');
20 HIT 5 : static HttpHeader basic_ = HttpHeader('Basic', environment.flipApiKey);
21 :
22 1 : const HttpHeader(this.key, this.value);
23 : }
24 :
25 : // !! If you make changes here, you need to rebuild the Chopper clients.
26 :
27 : class HttpHeaderFactory {
28 : final HttpHeader methodHeader;
29 : final bool isBasicAuth;
30 :
31 1 : const HttpHeaderFactory.get({this.isBasicAuth = false}) : methodHeader = HttpHeader.get_;
32 1 : const HttpHeaderFactory.post({this.isBasicAuth = false}) : methodHeader = HttpHeader.post_;
33 :
34 MIS 0 : const HttpHeaderFactory(this.methodHeader, {this.isBasicAuth = false});
35 :
36 HIT 1 : Map<String, String> create({Map<String, String>? additional}) {
37 1 : final headers = {
38 5 : methodHeader.key: methodHeader.value,
39 MIS 0 : ...?additional,
40 : };
41 :
42 HIT 1 : if (isBasicAuth) {
43 1 : final header = HttpHeader.basic_;
44 4 : headers.putIfAbsent(header.key, () => header.value);
45 : }
46 :
47 : return headers;
48 : }
49 : }
|