alferesw

Servicio

Dec 10th, 2023 (edited)
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | Software | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { HttpClient } from '@angular/common/http';
  3. import { HttpHeaders } from '@angular/common/http';
  4. import { BehaviorSubject, Observable, throwError } from 'rxjs';
  5. import { catchError, tap } from 'rxjs/operators';
  6. import { map } from 'rxjs/operators';
  7. import { ImportantesModel } from '../models/blog.models';
  8.  
  9.  
  10.  
  11. @Injectable({
  12. providedIn: 'root'
  13. })
  14. export class BlogService {
  15.  
  16. //private URL = 'http://127.0.0.1:8000';
  17. private URL = 'https://bo.ganaplay.com';
  18. private configCountrySubject = new BehaviorSubject<any>(null);
  19.  
  20. private promise:any;
  21.  
  22. setPromise(promise: Promise<any>): void {
  23. console.log(promise)
  24. this.promise = promise;
  25. }
  26.  
  27. getPromise(): Promise<any> {
  28. return this.promise;
  29. }
  30.  
  31. importantes = new ImportantesModel();
  32. configcountry:any;
  33. flag:any;
  34.  
  35. constructor(private http: HttpClient) {
  36.  
  37.  
  38.  
  39. }
  40.  
  41.  
  42. getImportantes():Observable<any> {
  43. return this.http.get<any>(`${this.URL}/blog/important/`)
  44. .pipe( map(data => {
  45. return data;
  46. }));
  47. }
  48.  
  49. getHomeNews():Observable<any> {
  50. return this.http.get<any>(`${this.URL}/blog/noticias/`)
  51. .pipe( map(data => {
  52. return data;
  53. }));
  54. }
  55.  
  56. getRecientes():Observable<any> {
  57. return this.http.get<any>(`${this.URL}/blog/recientes/`)
  58. .pipe( map(data => {
  59. return data;
  60. }));
  61. }
  62.  
  63.  
  64. getPost(url:string):Observable<any> {
  65.  
  66. const dat = {
  67. slug: url
  68. }
  69.  
  70. return this.http.post<any>(`${this.URL}/blog/post/`, dat)
  71. .pipe( map(data => {
  72. return data;
  73. }));
  74. }
  75.  
  76.  
  77.  
  78. handleError(error: { message: any; }){
  79. return throwError(error.message || "Error del servidor");
  80. }
  81.  
  82.  
  83.  
  84.  
  85. setConfigCountry(configCountry: any): void { //nueva config
  86. this.configCountrySubject.next(configCountry);
  87. }
  88.  
  89. getConfigCountry(): Observable<any> { //nueva config
  90. return this.configCountrySubject.asObservable();
  91. }
  92.  
  93. setCountry(): Observable<string> { //nueva config
  94. return this.http.get('https://cloudflare.com/cdn-cgi/trace', { responseType: 'text' })
  95. .pipe(
  96. map((response: string) => {
  97. const lines = response.split('\n');
  98. const countryLine = lines.find(line => line.startsWith('loc='));
  99. const country = countryLine ? countryLine.split('=')[1] : 'Unknown';
  100. return country;
  101. }),
  102. tap(country => {
  103. if (country === 'CO') {
  104. const configCountry = {
  105. 'url': 'https://ganaplay.ec/',
  106. 'rs': {
  107. 'fb': 'https://www.facebook.com/GanaPlayGT',
  108. 'ins': 'https://www.instagram.com/ganaplaygt/',
  109. 'ytb': '',
  110. 'tw': '',
  111. 'ldn': 'https://www.linkedin.com/company/ganaplay/',
  112. },
  113. 'tel': '35785083',
  114. 'email': '[email protected]',
  115. 'dir': '13 calle 3-43 Zona 10, ciudad de Guatemala Guatemala',
  116. 'geodir': '14.5993325,-90.5132449'
  117. };
  118. this.configcountry=configCountry;
  119. this.setConfigCountry(configCountry);
  120. }
  121. })
  122. );
  123. }
  124.  
  125. }
  126.  
  127.  
Advertisement
Add Comment
Please, Sign In to add comment