Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import { HttpClient } from '@angular/common/http';
- import { HttpHeaders } from '@angular/common/http';
- import { BehaviorSubject, Observable, throwError } from 'rxjs';
- import { catchError, tap } from 'rxjs/operators';
- import { map } from 'rxjs/operators';
- import { ImportantesModel } from '../models/blog.models';
- @Injectable({
- providedIn: 'root'
- })
- export class BlogService {
- //private URL = 'http://127.0.0.1:8000';
- private URL = 'https://bo.ganaplay.com';
- private configCountrySubject = new BehaviorSubject<any>(null);
- private promise:any;
- setPromise(promise: Promise<any>): void {
- console.log(promise)
- this.promise = promise;
- }
- getPromise(): Promise<any> {
- return this.promise;
- }
- importantes = new ImportantesModel();
- configcountry:any;
- flag:any;
- constructor(private http: HttpClient) {
- }
- getImportantes():Observable<any> {
- return this.http.get<any>(`${this.URL}/blog/important/`)
- .pipe( map(data => {
- return data;
- }));
- }
- getHomeNews():Observable<any> {
- return this.http.get<any>(`${this.URL}/blog/noticias/`)
- .pipe( map(data => {
- return data;
- }));
- }
- getRecientes():Observable<any> {
- return this.http.get<any>(`${this.URL}/blog/recientes/`)
- .pipe( map(data => {
- return data;
- }));
- }
- getPost(url:string):Observable<any> {
- const dat = {
- slug: url
- }
- return this.http.post<any>(`${this.URL}/blog/post/`, dat)
- .pipe( map(data => {
- return data;
- }));
- }
- handleError(error: { message: any; }){
- return throwError(error.message || "Error del servidor");
- }
- setConfigCountry(configCountry: any): void { //nueva config
- this.configCountrySubject.next(configCountry);
- }
- getConfigCountry(): Observable<any> { //nueva config
- return this.configCountrySubject.asObservable();
- }
- setCountry(): Observable<string> { //nueva config
- return this.http.get('https://cloudflare.com/cdn-cgi/trace', { responseType: 'text' })
- .pipe(
- map((response: string) => {
- const lines = response.split('\n');
- const countryLine = lines.find(line => line.startsWith('loc='));
- const country = countryLine ? countryLine.split('=')[1] : 'Unknown';
- return country;
- }),
- tap(country => {
- if (country === 'CO') {
- const configCountry = {
- 'url': 'https://ganaplay.ec/',
- 'rs': {
- 'fb': 'https://www.facebook.com/GanaPlayGT',
- 'ins': 'https://www.instagram.com/ganaplaygt/',
- 'ytb': '',
- 'tw': '',
- 'ldn': 'https://www.linkedin.com/company/ganaplay/',
- },
- 'tel': '35785083',
- 'email': '[email protected]',
- 'dir': '13 calle 3-43 Zona 10, ciudad de Guatemala Guatemala',
- 'geodir': '14.5993325,-90.5132449'
- };
- this.configcountry=configCountry;
- this.setConfigCountry(configCountry);
- }
- })
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment