-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Highlevel Classes to Push API (#104)
* feat: add channels api functions * feat: add Channel to Push API -Added Alias highlevel class -aded delegate highlevel clas * feat: add notification highlevel api class --------- Co-authored-by: Gbogboade Ayomide <[email protected]>
- Loading branch information
1 parent
ad5d63c
commit 37c3647
Showing
38 changed files
with
1,663 additions
and
34 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
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 @@ | ||
export 'src/get_alias_Info.dart'; |
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,28 @@ | ||
import '../../../push_restapi_dart.dart'; | ||
|
||
/// @description - fetches alias information | ||
/// @param {AliasOptions} options - options related to alias | ||
/// @returns Alias details | ||
Future<dynamic> getAliasInfo({required GetAliasInfoOptionsType options}) async { | ||
final alias = ALIAS_CHAIN_ID[options.alias.toString()]?[options.env]; | ||
|
||
final apiEndpoint = "/v1/alias/$alias/channel"; | ||
return await http.get( | ||
path: apiEndpoint, | ||
baseUrl: Api.getAPIBaseUrls(options.env), | ||
); | ||
} | ||
|
||
class GetAliasInfoOptionsType { | ||
// Properties | ||
String alias; | ||
ALIAS_CHAIN aliasChain; | ||
ENV env; | ||
|
||
// Constructor | ||
GetAliasInfoOptionsType({ | ||
required this.alias, | ||
required this.aliasChain, | ||
this.env = ENV.prod, | ||
}); | ||
} |
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,10 @@ | ||
export 'src/get_channel.dart'; | ||
export 'src/get_channels.dart'; | ||
export 'src/get_channel_notifications.dart'; | ||
export 'src/get_subscribers.dart'; | ||
export 'src/search.dart'; | ||
export 'src/signature.helpers.dart'; | ||
export 'src/subscribe.dart'; | ||
export 'src/subscribeV2.dart'; | ||
export 'src/unsubscribe.dart'; | ||
export 'src/unsubscribeV2.dart'; |
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,26 @@ | ||
import 'package:push_restapi_dart/push_restapi_dart.dart'; | ||
|
||
Future<List<String>?> getSubscribers( | ||
{required String channel, ENV? env}) async { | ||
final channelAddress = await getCAIPAddress(address: channel); | ||
final channelCAIPDetails = getCAIPDetails(channelAddress); | ||
if (channelCAIPDetails == null) { | ||
throw Exception('Invalid Channel CAIP!'); | ||
} | ||
|
||
final chainId = channelCAIPDetails.networkId; | ||
final body = { | ||
'channel': | ||
channelCAIPDetails.address, // deprecated API expects ETH address format | ||
'blockchain': chainId, | ||
'op': 'read', | ||
}; | ||
|
||
final result = await http.post( | ||
path: '/channels/_get_subscribers', | ||
data: body, | ||
baseUrl: Api.getAPIBaseUrls(env), | ||
); | ||
|
||
return result['subscribers']; | ||
} |
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,17 @@ | ||
import '../../../push_restapi_dart.dart'; | ||
|
||
Future<dynamic> getChannel({ | ||
required String channel, | ||
ENV? env, | ||
}) async { | ||
try { | ||
final channelAddress = await getCAIPAddress(address: channel); | ||
final result = await http.get( | ||
path: '/v1/channels/$channelAddress', | ||
baseUrl: Api.getAPIBaseUrls(env), | ||
); | ||
return result; | ||
} catch (e) { | ||
log('[Push SDK] - API getChannel: $e'); | ||
} | ||
} |
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,62 @@ | ||
// ignore_for_file: constant_identifier_names | ||
|
||
import '../../../push_restapi_dart.dart'; | ||
|
||
class GetChannelNotificationOptions { | ||
String channel; | ||
ENV? env; | ||
int page; | ||
int limit; | ||
NotificationType? filter; | ||
bool? raw; | ||
|
||
GetChannelNotificationOptions({ | ||
required this.channel, | ||
this.env, | ||
this.page = Pagination.INITIAL_PAGE, | ||
this.limit = Pagination.LIMIT_MAX, | ||
this.filter, | ||
this.raw, | ||
}); | ||
} | ||
|
||
Future<dynamic> getChannelNotifications( | ||
GetChannelNotificationOptions options) async { | ||
final channel = await getCAIPAddress(address: options.channel); | ||
final query = getQueryParams( | ||
options.filter != null | ||
? { | ||
"page": options.page, | ||
'limit': options.limit, | ||
'notificationType': options.filter?.value, | ||
} | ||
: { | ||
"page": options.page, | ||
'limit': options.limit, | ||
}, | ||
); | ||
final requestUrl = '/$channel/notifications?$query'; | ||
return http.get( | ||
path: requestUrl, | ||
baseUrl: Api.getAPIBaseUrls(options.env), | ||
); | ||
} | ||
|
||
enum NotificationType { | ||
BROADCAST, | ||
TARGETED, | ||
SUBSET, | ||
} | ||
|
||
extension NotificationTypeExtension on NotificationType { | ||
int get value { | ||
switch (this) { | ||
case NotificationType.BROADCAST: | ||
return 1; | ||
case NotificationType.TARGETED: | ||
return 3; | ||
case NotificationType.SUBSET: | ||
return 4; | ||
} | ||
} | ||
} |
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,28 @@ | ||
import 'package:push_restapi_dart/push_restapi_dart.dart'; | ||
|
||
class GetChannelOptions { | ||
ENV? env; | ||
int page; | ||
int limit; | ||
|
||
String? sort; | ||
String? order; | ||
|
||
GetChannelOptions({ | ||
this.env, | ||
this.page = Pagination.INITIAL_PAGE, | ||
this.limit = Pagination.LIMIT_MAX, | ||
this.order = ChannelListOrderType.DESCENDING, | ||
this.sort = ChannelListSortType.SUBSCRIBER, | ||
}); | ||
} | ||
|
||
Future<dynamic> getChannels(GetChannelOptions options) async { | ||
final requestUrl = '/v1/channels?page=${options.page}' | ||
'&limit=${options.limit}&sort=${options.sort}&order=${options.order}'; | ||
|
||
return http.get( | ||
path: requestUrl, | ||
baseUrl: Api.getAPIBaseUrls(options.env), | ||
); | ||
} |
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,13 @@ | ||
import 'package:push_restapi_dart/push_restapi_dart.dart'; | ||
|
||
Future<dynamic> getDelegates({ | ||
required String channel, | ||
ENV? env, | ||
}) async { | ||
final channelAddress = await getCAIPAddress(address: channel); | ||
final requestUrl = '/v1/channels/$channelAddress/delegates'; | ||
return http.get( | ||
path: requestUrl, | ||
baseUrl: Api.getAPIBaseUrls(env), | ||
); | ||
} |
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,56 @@ | ||
import '../../../push_restapi_dart.dart'; | ||
|
||
class GetChannelSubscribersOptionsType { | ||
String channel; // plain ETH Format only | ||
int page; | ||
int limit; | ||
int? category; | ||
bool? setting; | ||
ENV? env; | ||
bool? raw; | ||
|
||
GetChannelSubscribersOptionsType({ | ||
required this.channel, | ||
this.page = 1, | ||
this.limit = 10, | ||
this.category, | ||
this.setting, | ||
this.env, | ||
this.raw, | ||
}); | ||
} | ||
|
||
Future<dynamic> getSubscribers(GetChannelSubscribersOptionsType options) async { | ||
try { | ||
if (options.channel.isEmpty) { | ||
throw Exception('channel cannot be null or empty'); | ||
} | ||
|
||
if (options.page <= 0) { | ||
throw Exception('page must be greater than 0'); | ||
} | ||
|
||
if (options.limit <= 0) { | ||
throw Exception('limit must be greater than 0'); | ||
} | ||
if (options.limit > 30) { | ||
throw Exception('limit must be lesser than or equal to 30'); | ||
} | ||
|
||
final channelAddress = await getCAIPAddress(address: options.channel); | ||
var apiEndpoint = | ||
'/v1/channels/$channelAddress/subscribers?page=${options.page}' | ||
'&limit=${options.limit}&setting=${options.setting}'; | ||
if (options.category != null) { | ||
apiEndpoint = 'apiEndpoint&category=${options.category}'; | ||
} | ||
|
||
return http.get( | ||
path: apiEndpoint, | ||
baseUrl: Api.getAPIBaseUrls(options.env), | ||
); | ||
} catch (e) { | ||
log('[Push SDK] - API - Error - API send() -: $e'); | ||
rethrow; | ||
} | ||
} |
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,19 @@ | ||
import '../../../push_restapi_dart.dart'; | ||
|
||
Future<dynamic> search({ | ||
required String query, | ||
int page = 1, | ||
int limit = 10, | ||
ENV? env, | ||
}) async { | ||
final queryObj = { | ||
'page': page, | ||
'limit': limit, | ||
'query': query, | ||
}; | ||
var apiEndpoint = '/v1/channels/search/?${getQueryParams(queryObj)}'; | ||
return http.get( | ||
path: apiEndpoint, | ||
baseUrl: Api.getAPIBaseUrls(env), | ||
); | ||
} |
Oops, something went wrong.