Skip to content

Commit 48c9645

Browse files
committed
feat: add support for DebugLoggerLevel
wip
1 parent 0299534 commit 48c9645

9 files changed

+69
-13
lines changed

android/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ android {
5151

5252
dependencies {
5353
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0")
54-
implementation("com.spotify.confidence:confidence-sdk-android:0.3.2")
54+
implementation("com.spotify.confidence:confidence-sdk-android:0.3.5")
5555
testImplementation("org.jetbrains.kotlin:kotlin-test")
5656
testImplementation("org.mockito:mockito-core:5.1.0")
5757
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
6+
zipStoreBase=GRADLE_USER_HOME
7+
zipStorePath=wrapper/dists

android/src/main/kotlin/com/example/confidence_flutter_sdk/ConfidenceFlutterSdkPlugin.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import com.spotify.confidence.Confidence
55
import com.spotify.confidence.ConfidenceFactory
66
import com.spotify.confidence.ConfidenceValue
7+
import com.spotify.confidence.DebugLoggerLevel
78
import com.spotify.confidence.client.SdkMetadata
89
import io.flutter.embedding.engine.plugins.FlutterPlugin
910
import io.flutter.embedding.engine.plugins.activity.ActivityAware
@@ -39,11 +40,12 @@ class ConfidenceFlutterSdkPlugin: FlutterPlugin, MethodCallHandler, ActivityAwar
3940
confidence.flush()
4041
}
4142
"setup" -> {
42-
val apiKey = call.arguments as String
43+
val apiKey = call.argument<String>("apiKey") as String
44+
val debugLoggerLevel = call.argument<String>("debugLoggerLevel") as String
4345
confidence = ConfidenceFactory.create(
4446
context,
4547
apiKey,
46-
sdk = SdkMetadata("SDK_ID_FLUTTER_ANDROID_CONFIDENCE", "0.0.1")
48+
debugLoggerLevel = DebugLoggerLevel.valueOf(debugLoggerLevel)
4749
)
4850
result.success(null)
4951
}

example/lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class _MyAppState extends State<MyApp> {
3535
// Platform messages may fail, so we use a try/catch PlatformException.
3636
// We also handle the message potentially returning null.
3737
try {
38-
await _confidenceFlutterSdkPlugin.setup("API_KEY");
38+
await _confidenceFlutterSdkPlugin.setup("API_KEY", DebugLoggerLevel.DEBUG);
3939
if(await _confidenceFlutterSdkPlugin.isStorageEmpty()) {
4040
await _confidenceFlutterSdkPlugin.fetchAndActivate();
4141
} else {

example/test.sh

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cat <<EOF > ~/.pub-cache/credentials.json
2+
{
3+
"accessToken":"${PUB_ACCESS_TOKEN}",
4+
"refreshToken":"${PUB_REFRESH_TOKEN}",
5+
"tokenEndpoint":"${PUB_TOKEN_ENDPOINT}",
6+
"scopes":["https://www.googleapis.com/auth/userinfo.email","openid"],
7+
"expiration":${PUB_EXPIRATION}
8+
}
9+
EOF

ios/Classes/ConfidenceFlutterSdkPlugin.swift

+22-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,23 @@ public class ConfidenceFlutterSdkPlugin: NSObject, FlutterPlugin {
1010

1111
var confidence: Confidence? = nil
1212

13+
private func loggerLevel(from string: String) -> LoggerLevel {
14+
switch string.uppercased() {
15+
case "VERBOSE":
16+
return .TRACE
17+
case "DEBUG":
18+
return .DEBUG
19+
case "WARN":
20+
return .WARN
21+
case "ERROR":
22+
return .ERROR
23+
case "NONE":
24+
return .NONE
25+
default:
26+
return .NONE
27+
}
28+
}
29+
1330
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
1431
switch call.method {
1532
case "flush":
@@ -20,8 +37,11 @@ public class ConfidenceFlutterSdkPlugin: NSObject, FlutterPlugin {
2037
confidence.flush()
2138
break;
2239
case "setup":
23-
let apiKey = call.arguments as! String
24-
self.confidence = Confidence.Builder(clientSecret: apiKey)
40+
let arguments = call.arguments as! Dictionary<String, Any>
41+
let apiKey = arguments["apiKey"] as! String
42+
let debugLoggingLevel = arguments["debugLoggingLevel"] as! String
43+
44+
self.confidence = Confidence.Builder(clientSecret: apiKey, loggerLevel: loggerLevel(from: debugLoggingLevel))
2545
.build()
2646
result("")
2747
break;

lib/confidence_flutter_sdk.dart

+10-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class ConfidenceFlutterSdk {
3737
return ConfidenceFlutterSdkPlatform.instance.getDouble(key, defaultValue);
3838
}
3939

40-
Future<void> setup(String apiKey) async {
41-
return await ConfidenceFlutterSdkPlatform.instance.setup(apiKey);
40+
Future<void> setup(String apiKey, DebugLoggerLevel debugLoggerLevel) async {
41+
return await ConfidenceFlutterSdkPlatform.instance.setup(apiKey, debugLoggerLevel);
4242
}
4343

4444
Future<void> fetchAndActivate() async {
@@ -49,3 +49,11 @@ class ConfidenceFlutterSdk {
4949
return ConfidenceFlutterSdkPlatform.instance.activateAndFetchAsync();
5050
}
5151
}
52+
53+
enum DebugLoggerLevel {
54+
VERBOSE,
55+
DEBUG,
56+
WARN,
57+
ERROR,
58+
NONE,
59+
}

lib/confidence_flutter_sdk_method_channel.dart

+13-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
22
import 'package:flutter/services.dart';
33
import 'dart:convert';
44

5+
import 'confidence_flutter_sdk.dart';
56
import 'confidence_flutter_sdk_platform_interface.dart';
67

78
/// An implementation of [ConfidenceFlutterSdkPlatform] that uses method channels.
@@ -11,8 +12,16 @@ class MethodChannelConfidenceFlutterSdk extends ConfidenceFlutterSdkPlatform {
1112
final methodChannel = const MethodChannel('confidence_flutter_sdk');
1213

1314
@override
14-
Future<void> setup(String apiKey) async {
15-
return await methodChannel.invokeMethod<void>('setup', apiKey);
15+
Future<void> setup(String apiKey,
16+
DebugLoggerLevel debugLoggerLevelEnum) async {
17+
var debugLoggerLevel = debugLoggerLevelEnum.name;
18+
return await methodChannel.invokeMethod<void>(
19+
'setup',
20+
{
21+
'apiKey': apiKey,
22+
'debugLoggerLevel': debugLoggerLevel
23+
}
24+
);
1625
}
1726

1827
@override
@@ -57,7 +66,8 @@ class MethodChannelConfidenceFlutterSdk extends ConfidenceFlutterSdkPlatform {
5766
}
5867

5968
@override
60-
Future<Map<String, dynamic>> getObject(String key, Map<String, dynamic> defaultValue) async {
69+
Future<Map<String, dynamic>> getObject(String key,
70+
Map<String, dynamic> defaultValue) async {
6171
final wrappedDefaultValue = defaultValue.map((key, value) {
6272
return MapEntry(key, toTypedValue(value));
6373
});
@@ -107,7 +117,6 @@ class MethodChannelConfidenceFlutterSdk extends ConfidenceFlutterSdkPlatform {
107117
}
108118

109119

110-
111120
@override
112121
Future<int> getInt(String key, int defaultValue) async {
113122
final value = await methodChannel

lib/confidence_flutter_sdk_platform_interface.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
22

3+
import 'confidence_flutter_sdk.dart';
34
import 'confidence_flutter_sdk_method_channel.dart';
45

56
abstract class ConfidenceFlutterSdkPlatform extends PlatformInterface {
@@ -23,7 +24,7 @@ abstract class ConfidenceFlutterSdkPlatform extends PlatformInterface {
2324
_instance = instance;
2425
}
2526

26-
Future<void> setup(String apiKey) {
27+
Future<void> setup(String apiKey, DebugLoggerLevel debugLoggerLevel) {
2728
throw UnimplementedError('setup() has not been implemented.');
2829
}
2930

0 commit comments

Comments
 (0)