-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from humhub/f-brevo-provider
Add Brevo provider
- Loading branch information
Showing
3 changed files
with
49 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import 'dart:convert'; | ||
import 'package:http/http.dart' as http; | ||
import 'package:loggy/loggy.dart'; | ||
|
||
class MailProviderHandler { | ||
static Future<Uri?> handleUniversalLink(Uri url) async { | ||
if (_isBrevoUrl(url)) { | ||
return await _handleUniversalLinkBrevo(url); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
static bool _isBrevoUrl(Uri url) { | ||
return url.toString().contains('r.mail.inforisque.fr'); | ||
} | ||
|
||
static Future<Uri?> _handleUniversalLinkBrevo(Uri url) async { | ||
try { | ||
final response = await http.get( | ||
url, | ||
headers: {'Accept': 'application/json'}, | ||
); | ||
if (response.statusCode == 200) { | ||
final Map<String, dynamic> data = jsonDecode(response.body); | ||
return Uri.parse(data['url']); | ||
} else { | ||
logError('Failed to retrieve deep link. Status code: ${response.statusCode}'); | ||
return null; | ||
} | ||
} catch (e) { | ||
logError('Error while handling universal link: $e'); | ||
return null; | ||
} | ||
} | ||
} |