-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-62: adding jwt-enabled API keys #67
base: master
Are you sure you want to change the base?
Changes from all commits
38e446d
20fcb9a
d8b4de1
f3f5bfd
30538f4
45eacc4
027c715
a77b3e3
73a3139
08f326b
7997a8c
aeb9dd7
49c999a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
example/ios/Podfile.lock | ||
example/pubspec.lock | ||
example/pubspec.lock | ||
.dart_tool/ | ||
build/ | ||
pubspec.lock |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.lahaus.iterable_flutter"> | ||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> | ||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,19 @@ import 'dart:convert'; | |
import 'package:flutter/services.dart'; | ||
|
||
typedef OpenedNotificationHandler = void Function(Map openedResult); | ||
typedef OpenedDeepLinkHandler = void Function(Map openedResult); | ||
|
||
// ignore: avoid_classes_with_only_static_members | ||
class IterableFlutter { | ||
static const MethodChannel _channel = MethodChannel('iterable_flutter'); | ||
|
||
static OpenedNotificationHandler? _onOpenedNotification; | ||
static OpenedDeepLinkHandler? _onOpenedDeepLink; | ||
|
||
static Future<void> initialize({ | ||
required String apiKey, | ||
required String pushIntegrationName, | ||
bool activeLogDebug = false, | ||
bool activeLogDebug = false | ||
}) async { | ||
await _channel.invokeMethod( | ||
'initialize', | ||
|
@@ -27,8 +29,20 @@ class IterableFlutter { | |
_channel.setMethodCallHandler(nativeMethodCallHandler); | ||
} | ||
|
||
static Future<void> setEmail(String email) async { | ||
await _channel.invokeMethod('setEmail', email); | ||
static Future<void> setEmail(String email, String jwt) async { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would make jwt nullable in order to communicate that it isn't strictly required. Some implementations either don't care about having a JWT, or just want to get something quick put together to ensure the package works. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No support for setUserId? Seems easy enough to add. |
||
await _channel.invokeMethod( | ||
'setEmail', | ||
{ | ||
'email': email, | ||
'jwt': jwt, | ||
}, | ||
); | ||
} | ||
|
||
static Future<void> handleDeepLink(url) async { | ||
print("handleDeepLink"); | ||
print(url); | ||
await _channel.invokeMethod("handleDeepLink", {'url': url}); | ||
} | ||
|
||
static Future<void> setUserId(String userId) async { | ||
|
@@ -69,14 +83,23 @@ class IterableFlutter { | |
_onOpenedNotification = handler; | ||
} | ||
|
||
static void setDeepLinkOpenedHandler(OpenedDeepLinkHandler handler) { | ||
print("calling setDeepLinkOpenedHandler "); | ||
_onOpenedDeepLink = handler; | ||
} | ||
|
||
static Future<dynamic> nativeMethodCallHandler(MethodCall methodCall) async { | ||
print("nativeMethodCallHandler maybe deep? ${methodCall.method}"); | ||
final arguments = methodCall.arguments as Map<dynamic, dynamic>; | ||
final argumentsCleaned = sanitizeArguments(arguments); | ||
|
||
switch (methodCall.method) { | ||
case "openedNotificationHandler": | ||
_onOpenedNotification?.call(argumentsCleaned); | ||
return "This data from native....."; | ||
case "deepLinkHandler": | ||
print("deepLinkHandler running... "); | ||
_onOpenedDeepLink?.call(argumentsCleaned); | ||
return "Deep link datta from handler..."; | ||
default: | ||
return "Nothing"; | ||
} | ||
|
@@ -86,7 +109,7 @@ class IterableFlutter { | |
Map<dynamic, dynamic> arguments) { | ||
final result = arguments; | ||
|
||
final data = result['additionalData']; | ||
final data = result['additionalData'] ?? {}; | ||
data.forEach((key, value) { | ||
if (value is String) { | ||
if (value[0] == '{' && value[value.length - 1] == '}') { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,9 @@ void main() { | |
const String activeLogDebug = 'activeLogDebug'; | ||
const String email = '[email protected]'; | ||
const String userId = '11111'; | ||
const String jwt = ''; | ||
const String event = 'my_event'; | ||
const String authToken = 'authToken'; | ||
const Map<String, dynamic> dataFields = {'data': 'field'}; | ||
|
||
const contentBody = {'testKey': "Test body push"}; | ||
|
@@ -64,16 +66,20 @@ void main() { | |
arguments: { | ||
apiKey: apiKey, | ||
pushIntegrationName: pushIntegrationName, | ||
activeLogDebug: false | ||
activeLogDebug: false, | ||
authToken: null | ||
}, | ||
), | ||
]); | ||
}); | ||
|
||
test('setEmail', () async { | ||
await IterableFlutter.setEmail(email); | ||
await IterableFlutter.setEmail(email, jwt); | ||
expect(calledMethod, <Matcher>[ | ||
isMethodCall('setEmail', arguments: email), | ||
isMethodCall('setEmail', arguments: { | ||
"email": email, | ||
"jwt": jwt | ||
}), | ||
]); | ||
}); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably not necessary to include in the PR and probably makes sense to change locally when you need to check logs for something.