Skip to content

Commit f818651

Browse files
committed
Send app build info in request headers
1 parent cee7eef commit f818651

5 files changed

Lines changed: 55 additions & 26 deletions

File tree

ios/Podfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ PODS:
6666
- nanopb/encode (= 2.30909.0)
6767
- nanopb/decode (2.30909.0)
6868
- nanopb/encode (2.30909.0)
69+
- package_info_plus (0.4.5):
70+
- Flutter
6971
- path_provider_foundation (0.0.1):
7072
- Flutter
7173
- FlutterMacOS
@@ -83,6 +85,7 @@ DEPENDENCIES:
8385
- auth0_flutter (from `.symlinks/plugins/auth0_flutter/darwin`)
8486
- Flutter (from `Flutter`)
8587
- mobile_scanner (from `.symlinks/plugins/mobile_scanner/ios`)
88+
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
8689
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
8790
- share_plus (from `.symlinks/plugins/share_plus/ios`)
8891
- shared_preferences_foundation (from `.symlinks/plugins/shared_preferences_foundation/darwin`)
@@ -113,6 +116,8 @@ EXTERNAL SOURCES:
113116
:path: Flutter
114117
mobile_scanner:
115118
:path: ".symlinks/plugins/mobile_scanner/ios"
119+
package_info_plus:
120+
:path: ".symlinks/plugins/package_info_plus/ios"
116121
path_provider_foundation:
117122
:path: ".symlinks/plugins/path_provider_foundation/darwin"
118123
share_plus:
@@ -139,6 +144,7 @@ SPEC CHECKSUMS:
139144
MLKitVision: 8baa5f46ee3352614169b85250574fde38c36f49
140145
mobile_scanner: 38dcd8a49d7d485f632b7de65e4900010187aef2
141146
nanopb: b552cce312b6c8484180ef47159bc0f65a1f0431
147+
package_info_plus: c0502532a26c7662a62a356cebe2692ec5fe4ec4
142148
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
143149
PromisesObjC: 09985d6d70fbe7878040aa746d78236e6946d2ef
144150
share_plus: c3fef564749587fc939ef86ffb283ceac0baf9f5

lib/reusable/lovat_api/lovat_api.dart

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import 'dart:convert';
2+
import 'dart:io';
23

34
import 'package:auth0_flutter/auth0_flutter.dart';
45
import 'package:flutter/foundation.dart';
56
import 'package:http/http.dart' as http;
7+
import 'package:package_info_plus/package_info_plus.dart';
68
import 'package:scouting_dashboard_app/constants.dart';
79

810
class LovatAPI {
@@ -117,62 +119,64 @@ class LovatAPI {
117119
}
118120
}
119121

120-
Future<http.Response?> get(String path, {Map<String, String>? query}) async {
122+
Future<Map<String, String>> _getHeaders() async {
121123
final token = await getAccessToken();
124+
PackageInfo packageInfo = await PackageInfo.fromPlatform();
122125

126+
return {
127+
if (token != null) 'Authorization': 'Bearer $token',
128+
'X-Operating-System': Platform.operatingSystem,
129+
'X-App-Version': packageInfo.version,
130+
'X-Build-Number': packageInfo.buildNumber,
131+
};
132+
}
133+
134+
Future<http.Response?> get(String path, {Map<String, String>? query}) async {
123135
final uri = Uri.parse(baseUrl + path).replace(queryParameters: query);
124136

125-
return await http.get(uri, headers: {
126-
if (token != null) 'Authorization': 'Bearer $token',
127-
});
137+
return await http.get(uri, headers: await _getHeaders());
128138
}
129139

130140
Future<http.Response?> post(
131141
String path, {
132142
Map<String, dynamic>? body,
133143
Map<String, String>? query,
134144
}) async {
135-
final token = await getAccessToken();
136-
137145
final uri = Uri.parse(baseUrl + path).replace(queryParameters: query);
138146

139-
return await http
140-
.post(uri, body: body != null ? jsonEncode(body) : null, headers: {
141-
'Content-Type': 'application/json',
142-
if (token != null) 'Authorization': 'Bearer $token',
143-
});
147+
return await http.post(
148+
uri,
149+
body: body != null ? jsonEncode(body) : null,
150+
headers: await _getHeaders(),
151+
);
144152
}
145153

146154
Future<http.Response?> put(
147155
String path, {
148156
Map<String, dynamic>? body,
149157
Map<String, String>? query,
150158
}) async {
151-
final token = await getAccessToken();
152-
153159
final uri = Uri.parse(baseUrl + path).replace(queryParameters: query);
154160

155-
return await http
156-
.put(uri, body: body != null ? jsonEncode(body) : null, headers: {
157-
'Content-Type': 'application/json',
158-
if (token != null) 'Authorization': 'Bearer $token',
159-
});
161+
return await http.put(
162+
uri,
163+
body: body != null ? jsonEncode(body) : null,
164+
headers: await _getHeaders(),
165+
);
160166
}
161167

162168
Future<http.Response?> delete(
163169
String path, {
164170
Map<String, dynamic>? body,
165171
Map<String, String>? query,
166172
}) async {
167-
final token = await getAccessToken();
168-
169173
final uri = Uri.parse(baseUrl + path).replace(queryParameters: query);
170174

171-
return await http
172-
.delete(uri, body: body != null ? jsonEncode(body) : null, headers: {
173-
'Content-Type': 'application/json',
174-
if (token != null) 'Authorization': 'Bearer $token',
175-
});
175+
return await http.delete(
176+
uri,
177+
body: body != null ? jsonEncode(body) : null,
178+
headers: await _getHeaders(),
179+
);
176180
}
177181
}
178182

@@ -185,6 +189,6 @@ class LovatAPIException implements Exception {
185189
String toString() => message;
186190
}
187191

188-
const kProductionBaseUrl = "https://lovat-server-staging.up.railway.app";
192+
const kProductionBaseUrl = "https://api.lovat.app";
189193

190194
final lovatAPI = LovatAPI(kProductionBaseUrl);

macos/Flutter/GeneratedPluginRegistrant.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Foundation
77

88
import auth0_flutter
99
import mobile_scanner
10+
import package_info_plus
1011
import path_provider_foundation
1112
import share_plus
1213
import shared_preferences_foundation
@@ -15,6 +16,7 @@ import url_launcher_macos
1516
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
1617
Auth0FlutterPlugin.register(with: registry.registrar(forPlugin: "Auth0FlutterPlugin"))
1718
MobileScannerPlugin.register(with: registry.registrar(forPlugin: "MobileScannerPlugin"))
19+
FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin"))
1820
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
1921
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
2022
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))

pubspec.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,22 @@ packages:
319319
url: "https://pub.dev"
320320
source: hosted
321321
version: "3.5.7"
322+
package_info_plus:
323+
dependency: "direct main"
324+
description:
325+
name: package_info_plus
326+
sha256: f69da0d3189a4b4ceaeb1a3defb0f329b3b352517f52bed4290f83d4f06bc08d
327+
url: "https://pub.dev"
328+
source: hosted
329+
version: "9.0.0"
330+
package_info_plus_platform_interface:
331+
dependency: transitive
332+
description:
333+
name: package_info_plus_platform_interface
334+
sha256: "202a487f08836a592a6bd4f901ac69b3a8f146af552bbd14407b6b41e1c3f086"
335+
url: "https://pub.dev"
336+
source: hosted
337+
version: "3.2.1"
322338
path:
323339
dependency: transitive
324340
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dependencies:
5454
url_launcher: ^6.2.1
5555
share_plus: ^7.2.2
5656
csv: ^6.0.0
57+
package_info_plus: ^9.0.0
5758

5859
dev_dependencies:
5960
flutter_test:

0 commit comments

Comments
 (0)