UNPKG

baasic-sdk-angularjs

Version:

AngularJS SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).

773 lines (573 loc) 24.7 kB
# baasicNotificationsService Baasic Notifications Service provides an easy way to consume Baasic Notifications REST API end-points. In order to obtain needed routes `baasicNotificationsService` uses `baasicNotificationsRouteService`. * * * ### baasicNotificationsService.publish.create() Returns a promise that is resolved once the create notification action has been performed; this action creates a new notification resource. **Example**: ```js baasicNotificationsService.publish.create({ channels: ['<channel-name', '<channel-name>'], moduleName: '<module-name>', templateName: '<template-name>', templateContext: { prop1: '<prop1-value>', prop2: '<prop2-value>' } }) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.publish.batch.create() Returns a promise that is resolved once the create notification action has been performed; this action creates new notification resources. **Example**: ```js baasicNotificationsService.publish.create([{ channels: ['<channel-name', '<channel-name>'], moduleName: '<module-name>', templateName: '<template-name>', templateContext: { prop1: '<prop1-value>', prop2: '<prop2-value>' } }]) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.users.create() Returns a promise that is resolved once the create user subscription action has been performed; this action creates a new user subscription resource. **Example**: ```js baasicNotificationsService.subscriptions.users.create({ channel: '<channel-name>', userId: '<user-id>' }) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.users.find() Returns a promise that is resolved once the find action has been performed. Success response returns a list of user subscription resources matching the given criteria. **Example**: ```js baasicNotificationsService.subscriptions.users.find({ pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', search : '<search-phrase>', channels: '<channel-name1>,<channel-name2>', userIds: '<user-id1>,<user-id2>', embed: '<embed>' }) .success(function (collection) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.users.get() Returns a promise that is resolved once the get action has been performed. Success response returns the specified user subscription resource. **Example**: ```js baasicNotificationsService.subscriptions.users.get('<subscription-id>') .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.users.remove() Returns a promise that is resolved once the remove user subscription action has been performed. This action will remove a user subscription resource from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicNotificationsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.removeParams(subscription); var uri = params['model'].links('delete').href; ``` **Example**: ```js // subscription is a resource previously fetched using get action. baasicNotificationsService.subscriptions.users.remove(subscription) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.users.update() Returns a promise that is resolved once the update user subscription action has been performed; this action updates a user subscription resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicNotificationsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.updateParams(subscription); var uri = params['model'].links('put').href; ``` **Example**: ```js // subscription is a resource previously fetched using get action. subscription.channel = '<channel-name>'; baasicNotificationsService.subscriptions.users.update(subscription) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.users.batch.create() Returns a promise that is resolved once the create user subscription action has been performed; this action creates new user subscription resources. **Example**: ```js baasicNotificationsService.subscriptions.users.batch.create([{ channel: '<channel-name>', userId: '<user-id>' }]) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.users.batch.remove() Returns a promise that is resolved once the remove action has been performed. This action will remove user subscription resources from the system if successfully completed. **Example**: ```js baasicNotificationsService.subscriptions.users.batch.remove(subscriptionIds) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.users.batch.update() Returns a promise that is resolved once the update user subscriptions action has been performed; this action updates specified user subscription resources. **Example**: ```js baasicNotificationsService.subscriptions.users.batch.update(subscriptions) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.anonymous.create() Returns a promise that is resolved once the create anonymous subscription action has been performed; this action creates a new anonymous subscription resource. **Example**: ```js baasicNotificationsService.subscriptions.anonymous.create({ channel: '<channel-name>', registrationId: '<registration-id>' }) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.anonymous.find() Returns a promise that is resolved once the find action has been performed. Success response returns a list of anonymous subscription resources matching the given criteria. **Example**: ```js baasicNotificationsService.subscriptions.anonymous.find({ pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', search : '<search-phrase>', channels: '<channel-name1>,<channel-name2>', registrationIds: '<registration-id1>,<registration-id2>', embed: '<embed>' }) .success(function (collection) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.anonymous.get() Returns a promise that is resolved once the get action has been performed. Success response returns the specified anonymous subscription resource. **Example**: ```js baasicNotificationsService.subscriptions.anonymous.get('<subscription-id>') .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.anonymous.remove() Returns a promise that is resolved once the remove anonymous subscription action has been performed. This action will remove a anonymous subscription resource from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicNotificationsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.removeParams(subscription); var uri = params['model'].links('delete').href; ``` **Example**: ```js // subscription is a resource previously fetched using get action. baasicNotificationsService.subscriptions.anonymous.remove(subscription) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.anonymous.update() Returns a promise that is resolved once the update anonymous subscription action has been performed; this action updates a anonymous subscription resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicNotificationsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.updateParams(subscription); var uri = params['model'].links('put').href; ``` **Example**: ```js // subscription is a resource previously fetched using get action. subscription.channel = '<channel-name>'; baasicNotificationsService.update(subscription) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.anonymous.batch.create() Returns a promise that is resolved once the create anonymous subscription action has been performed; this action creates new anonymous subscription resources. **Example**: ```js baasicNotificationsService.subscriptions.anonymous.batch.create([{ channel: '<channel-name>', registrationId: '<registration-id>' }]) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.anonymous.batch.remove() Returns a promise that is resolved once the remove action has been performed. This action will remove anonymous subscription resources from the system if successfully completed. **Example**: ```js baasicNotificationsService.subscriptions.anonymous.batch.remove(subscriptionIds) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.subscriptions.anonymous.batch.update() Returns a promise that is resolved once the update anonymous subscriptions action has been performed; this action updates specified anonymous subscription resources. **Example**: ```js baasicNotificationsService.subscriptions.anonymous.batch.update(subscriptions) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.users.create() Returns a promise that is resolved once the create user registration action has been performed; this action creates a new user registration resource. **Example**: ```js baasicNotificationsService.registrations.users.create({ provider: '<provider-name>', providerData: <provider-data>, userId: '<user-id>' }) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.users.find() Returns a promise that is resolved once the find action has been performed. Success response returns a list of user registrations resources matching the given criteria. **Example**: ```js baasicNotificationsService.registrations.users.find({ pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', search : '<search-phrase>', providers: '<provider-name1>,<provider-name2>', userIds: '<user-id1>,<user-id2>', embed: '<embed>' }) .success(function (collection) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.users.get() Returns a promise that is resolved once the get action has been performed. Success response returns the specified user registrations resource. **Example**: ```js baasicNotificationsService.registrations.users.get('<registration-id>') .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.users.remove() Returns a promise that is resolved once the remove user registrations action has been performed. This action will remove a user registrations resource from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicNotificationsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.removeParams(registration); var uri = params['model'].links('delete').href; ``` **Example**: ```js // registration is a resource previously fetched using get action. baasicNotificationsService.registrations.users.remove(registration) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.users.update() Returns a promise that is resolved once the update user registration action has been performed; this action updates a user registration resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicNotificationsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.updateParams(subsregistrationcription); var uri = params['model'].links('put').href; ``` **Example**: ```js // registration is a resource previously fetched using get action. registration.provider = '<provider-name>'; baasicNotificationsService.registrations.users.update(registration) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.users.batch.create() Returns a promise that is resolved once the create user registration action has been performed; this action creates new user registration resources. **Example**: ```js baasicNotificationsService.registrations.users.batch.create([{ provider: '<provider-name>', providerData: <provider-data>, userId: '<user-id>' }]) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.users.batch.remove() Returns a promise that is resolved once the remove action has been performed. This action will remove user registration resources from the system if successfully completed. **Example**: ```js baasicNotificationsService.registrations.users.batch.remove(subscriptionIds) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.users.batch.update() Returns a promise that is resolved once the update user registration action has been performed; this action updates specified user registration resources. **Example**: ```js baasicNotificationsService.registrations.users.batch.update(registrations) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.anonymous.create() Returns a promise that is resolved once the create anonymous registration action has been performed; this action creates a new anonymous registration resource. **Example**: ```js baasicNotificationsService.registrations.anonymous.create({ provider: '<provider-name>', providerdata: <provider-data>, expirationData: '<expiration-date>' }) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.anonymous.find() Returns a promise that is resolved once the find action has been performed. Success response returns a list of anonymous registration resources matching the given criteria. **Example**: ```js baasicNotificationsService.registrations.anonymous.find({ pageNumber : 1, pageSize : 10, orderBy : '<field>', orderDirection : '<asc|desc>', search : '<search-phrase>', providers: '<provider-name1>,<provider-name2>', embed: '<embed>' }) .success(function (collection) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.anonymous.get() Returns a promise that is resolved once the get action has been performed. Success response returns the specified anonymous registration resource. **Example**: ```js baasicNotificationsService.registrations.anonymous.get('<registration-id>') .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.anonymous.remove() Returns a promise that is resolved once the remove anonymous registration action has been performed. This action will remove a anonymous registration resource from the system if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicNotificationsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.removeParams(registration); var uri = params['model'].links('delete').href; ``` **Example**: ```js // registration is a resource previously fetched using get action. baasicNotificationsService.registrations.anonymous.remove(registration) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.anonymous.update() Returns a promise that is resolved once the update anonymous registration action has been performed; this action updates a anonymous registration resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicNotificationsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.updateParams(registration); var uri = params['model'].links('put').href; ``` **Example**: ```js // registration is a resource previously fetched using get action. subscription.provider = '<provider-name>'; baasicNotificationsService.update(registration) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.anonymous.batch.create() Returns a promise that is resolved once the create anonymous registration action has been performed; this action creates new anonymous registration resources. **Example**: ```js baasicNotificationsService.registrations.anonymous.batch.create([{ provider: '<provider-name>', providerData: <provider-data>, expirationDate: <expiration-date> }]) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.anonymous.batch.remove() Returns a promise that is resolved once the remove action has been performed. This action will remove anonymous registration resources from the system if successfully completed. **Example**: ```js baasicNotificationsService.registrations.anonymous.batch.remove(subscriptionIds) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.registrations.anonymous.batch.update() Returns a promise that is resolved once the update anonymous registration action has been performed; this action updates specified anonymous registration resources. **Example**: ```js baasicNotificationsService.registrations.anonymous.batch.update(registrations) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.settings.get() Returns a promise that is resolved once the get action has been performed. Success response returns the specified setting resource. **Example**: ```js baasicNotificationsService.settings.get('<provider-name>') .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.settings.update() Returns a promise that is resolved once the update settings action has been performed; this action updates a settings resource. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `baasicNotificationsRouteService` route template. Here is an example of how a route can be obtained from HAL enabled objects: ``` var params = baasicApiService.updateParams(settings); var uri = params['model'].links('put').href; ``` **Example**: ```js // settings is a resource previously fetched using get action. baasicNotificationsService.update(settings) .success(function (data) { // perform success action here }) .error(function (response, status, headers, config) { // perform error handling here }); ``` ### baasicNotificationsService.routeService() Provides direct access to `baasicNotificationsRouteService`. **Example**: ```js baasicNotificationsService.routeService.publish.create({}); ``` * * * **Notes:** - Refer to the [REST API documentation](https://github.com/Baasic/baasic-rest-api/wiki) for detailed information about available Baasic REST API end-points. - All end-point objects are transformed by the associated route service.