UNPKG

@cause-911/social-network

Version:

Run `npm install @cause-911/social-network --save` to add this library to your project

2 lines 7.66 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("rxjs"),require("@angular/common/http"),require("rxjs/operators"),require("@cause-911/core")):"function"==typeof define&&define.amd?define("@cause-911/social-network",["exports","@angular/core","rxjs","@angular/common/http","rxjs/operators","@cause-911/core"],t):t(((e=e||self)["cause-911"]=e["cause-911"]||{},e["cause-911"]["social-network"]={}),e.ng.core,e.rxjs,e.ng.common.http,e.rxjs.operators,e.core$1)}(this,function(e,t,r,n,o,i){"use strict";var c=function(){function e(){}return e.prototype.get=function(e){return r.Observable.create(function(t){var r=document.createElement("script");r.type="text/javascript",r.src=e,r.onload=function(){t.next({script:e,status:"loaded"}),t.complete()},r.onerror=function(e){t.error(e),t.complete()},document.getElementsByTagName("head")[0].appendChild(r)})},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[]},e.ngInjectableDef=t.ɵɵdefineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(),a=function(){function e(e,t){var r=this;this.isLoaded=!1,this.isInitialize=!1,this.httpClient=new n.HttpClient(e),t.get("https://connect.facebook.net/en_US/sdk.js").subscribe(function(e){r.isLoaded=!0},function(e){r.error=e})}return e.prototype.initialize=function(e,t){var n=this;return void 0===t&&(t="v6.0"),this.appId=e,this.version=t,r.Observable.create(function(e){n.error?e.error(n.error):n.isLoaded?e.next(!0):e.error(new Error("Facebook SDK is not loaded")),e.complete()}).pipe(o.map(function(){return n.initializeSDK()}),o.retryWhen(function(e){return e.pipe(o.delay(200),o.take(25))}),o.catchError(function(e){return r.of(e)}))},e.prototype.findManageablePage=function(){var e=this;return r.Observable.create(function(t){var r=e.validateSDK();r&&t.error(r),e.getAuthentification().subscribe(function(r){r&&r.userID?e.listAccessiblePage(r.userID).subscribe(function(e){t.next(e),t.complete()},function(e){t.error(e)}):t.error(new Error("No user are connected to Facebook"))},function(e){t.error(e)})})},e.prototype.askToManagePage=function(){var e=this;return r.Observable.create(function(t){var r=e.validateSDK();r&&t.error(r),e.askTokenWithScope("manage_pages, publish_pages").subscribe(function(r){r.userID?e.listAccessiblePage(r.userID).subscribe(function(e){t.next(e),t.complete()},function(e){t.error(e)}):t.error(r)},function(e){t.error(e)})})},e.prototype.publishToPage=function(e,t,r,n){var i=this;void 0===n&&(n=null);var c={message:r,access_token:t};return n?this.postUnpublishedPhotos(e,t,n).pipe(o.catchError(function(t){return i.httpClient.post("https://graph.facebook.com/"+e+"/feed",c)}),o.map(function(t){return t.forEach(function(e,t){c["attached_media["+t+"]"]={media_fbid:e}}),i.httpClient.post("https://graph.facebook.com/"+e+"/feed",c)})):this.httpClient.post("https://graph.facebook.com/"+e+"/feed",c)},e.prototype.postUnpublishedPhotos=function(e,t,n){var i=this,c=[];return n.forEach(function(r){var n=i.httpClient.post("https://graph.facebook.com/"+e+"/photos",{url:r,caption:"",published:!1,access_token:t}).pipe(o.map(function(e){return e.id}));c.push(n)}),r.forkJoin(c)},e.prototype.listAccessiblePage=function(e){return r.Observable.create(function(t){FB.api("/"+e+"/accounts",function(e){e&&!e.error?e.data instanceof Error?t.error(e.data):(t.next(e.data),t.complete()):t.error(e)})})},e.prototype.askTokenWithScope=function(e){return r.Observable.create(function(t){FB.login(function(e){e.authResponse?(t.next(e.authResponse),t.complete()):t.error(new Error("User cancelled login or did not fully authorize"))},{scope:e})})},e.prototype.getAuthentification=function(){return r.Observable.create(function(e){var t=setTimeout(function(){e.error("Facebook SDK can't be used")},2e3);FB.getLoginStatus(function(r){clearTimeout(t),"connected"===r.status?e.next(r.authResponse):e.next({}),e.complete()})})},e.prototype.initializeSDK=function(){FB.init({appId:this.appId,cookie:!0,xfbml:!0,version:this.version}),this.isInitialize=!0},e.prototype.validateSDK=function(){return"https:"!==location.protocol?new Error("You can only use the Facebook SDK on HTTPS"):!this.isInitialize&&new Error("You need to initialize the service")},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:n.HttpBackend},{type:c}]},e.ngInjectableDef=t.ɵɵdefineInjectable({factory:function(){return new e(t.ɵɵinject(n.HttpBackend),t.ɵɵinject(c))},token:e,providedIn:"root"}),e}(),s=function(){function e(e,t){var r=this;this.httpClient=e,this.isLoaded=!1,this.isInitialize=!1,t.get("https://platform.twitter.com/widgets.js").subscribe(function(e){r.isLoaded=!0},function(e){r.error=e})}return e.prototype.initialize=function(e){var t=this;return this.appId=e,r.Observable.create(function(e){t.error?e.error(t.error):t.isLoaded?e.next(!0):e.error(new Error("Twitter SDK is not loaded")),e.complete()}).pipe(o.map(function(){return t.initializeSDK()}),o.retryWhen(function(e){return e.pipe(o.delay(200),o.take(25))}),o.catchError(function(e){return r.of(e)}))},e.prototype.findManageablePage=function(){var e=this,t=this.validateSDK();return t?r.of(t):r.Observable.create(function(t){e.getAuthentification().subscribe(function(r){r&&r.userID?e.listAccessiblePage(r.userID).subscribe(function(e){t.next(e),t.complete()},function(e){t.error(e)}):t.error(new Error("No user are connected to Facebook"))},function(e){t.error(e)})})},e.prototype.askToManagePage=function(){var e=this,t=this.validateSDK();return t?r.of(t):r.Observable.create(function(t){e.getAuthentification().subscribe(function(){e.askTokenWithScope("manage_pages, publish_pages").subscribe(function(r){e.listAccessiblePage(r.userID).subscribe(function(e){t.next(e),t.complete()},function(e){t.error(e)})},function(e){t.error(e)})},function(e){t.error(e)})})},e.prototype.publishToPage=function(e,t,r){return this.httpClient.post("https://graph.facebook.com/"+e+"/feed",{message:r,access_token:t})},e.prototype.listAccessiblePage=function(e){return r.Observable.create(function(e){})},e.prototype.askTokenWithScope=function(e){return r.Observable.create(function(e){})},e.prototype.getAuthentification=function(){return r.Observable.create(function(e){})},e.prototype.initializeSDK=function(){var e=this;twttr.ready(function(){e.isInitialize=!0})},e.prototype.validateSDK=function(){return!this.isInitialize&&new Error("You need to initialize the service")},e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[{type:n.HttpClient},{type:c}]},e.ngInjectableDef=t.ɵɵdefineInjectable({factory:function(){return new e(t.ɵɵinject(n.HttpClient),t.ɵɵinject(c))},token:e,providedIn:"root"}),e}(),u=function(){function e(){}return e.decorators=[{type:t.Injectable,args:[{providedIn:"root"}]}],e.ctorParameters=function(){return[]},e.ngInjectableDef=t.ɵɵdefineInjectable({factory:function(){return new e},token:e,providedIn:"root"}),e}(),p=function(){function e(){}return e.prototype.ngOnInit=function(){},e.decorators=[{type:t.Component,args:[{selector:"cause-social-network",template:"<div>{{'core.noGenericComponentOnThisLibrary' | translate}}</div>"}]}],e.ctorParameters=function(){return[]},e}(),f=function(){function e(){}return e.decorators=[{type:t.NgModule,args:[{declarations:[p],exports:[p],imports:[i.CauseCoreModule]}]}],e}();e.FacebookService=a,e.SocialNetworkComponent=p,e.SocialNetworkModule=f,e.SocialNetworkService=u,e.TwitterService=s,e.ɵa=c,Object.defineProperty(e,"__esModule",{value:!0})}); //# sourceMappingURL=cause-911-social-network.umd.min.js.map