From 4df15f557b9d3fe144be64023b1a9333f6868ec5 Mon Sep 17 00:00:00 2001 From: kj1352 Date: Wed, 14 Apr 2021 16:58:40 +0530 Subject: [PATCH] Get request added platform clause to check if running natively or not --- src/app/home-details/home-details.page.ts | 25 +++++++++++--- src/app/home/home.page.ts | 35 +++++++++++++------ src/app/services/news.service.ts | 42 +++++++++++++++++++---- 3 files changed, 80 insertions(+), 22 deletions(-) diff --git a/src/app/home-details/home-details.page.ts b/src/app/home-details/home-details.page.ts index 6c3db96..8efae49 100644 --- a/src/app/home-details/home-details.page.ts +++ b/src/app/home-details/home-details.page.ts @@ -5,6 +5,7 @@ import { DomSanitizer } from '@angular/platform-browser'; import { NewsService, IMAGE_BASE_URL } from '../services/news.service'; import { ToastService } from '../services/toast.service'; import { SocialSharing } from '@ionic-native/social-sharing/ngx'; +import { Platform } from '@ionic/angular'; @Component({ selector: 'app-home-details', @@ -22,7 +23,8 @@ export class HomeDetailsPage implements OnInit { private dom:DomSanitizer, private newsService: NewsService, private toastService: ToastService, - private socialSharing: SocialSharing + private socialSharing: SocialSharing, + private platform: Platform ) { } getUrl(url) { @@ -48,7 +50,12 @@ export class HomeDetailsPage implements OnInit { if (type === 'news') { this.newsService.getArticleDetails(alias_title).then((data: any) => { - this.newsDetails = JSON.parse(data.data)['content'].data; + + if (this.platform.is('android') || this.platform.is('capacitor')) { + this.newsDetails = JSON.parse(data.data)['content'].data; + } else { + this.newsDetails = data.content.data; + } }, (err) => { console.log(err); @@ -59,7 +66,12 @@ export class HomeDetailsPage implements OnInit { if (type === 'videos') { this.newsService.getVideoDetails(alias_title).then((data: any) => { - this.newsDetails = JSON.parse(data.data)['content'].data; + + if (this.platform.is('android') || this.platform.is('capacitor')) { + this.newsDetails = JSON.parse(data.data)['content'].data; + } else { + this.newsDetails = data.content.data; + } }, (err) => { console.log(err); @@ -70,7 +82,12 @@ export class HomeDetailsPage implements OnInit { if (type === 'gallery') { this.newsService.getGalleryDetails(alias_title).then((data: any) => { - this.newsDetails = JSON.parse(data.data)['content'].data; + + if (this.platform.is('android') || this.platform.is('capacitor')) { + this.newsDetails = JSON.parse(data.data)['content'].data; + } else { + this.newsDetails = data.content.data; + } }, (err) => { console.log(err); diff --git a/src/app/home/home.page.ts b/src/app/home/home.page.ts index 4cccb28..59be16a 100644 --- a/src/app/home/home.page.ts +++ b/src/app/home/home.page.ts @@ -4,8 +4,8 @@ import { Router } from '@angular/router'; import { NewsService, IMAGE_BASE_URL } from '../services/news.service'; import { ToastService } from '../services/toast.service'; import { DomSanitizer } from '@angular/platform-browser'; -import { Uptime } from '@ionic-native/uptime/ngx'; import { SocialSharing } from '@ionic-native/social-sharing/ngx'; +import { Platform } from '@ionic/angular'; @Component({ selector: 'app-home', @@ -41,8 +41,8 @@ export class HomePage implements OnInit { private newsService: NewsService, private toastService: ToastService, private dom: DomSanitizer, - private uptime: Uptime, - private socialSharing: SocialSharing + private socialSharing: SocialSharing, + private platform: Platform ) { } transformYourHtml(htmlTextWithStyle) { @@ -54,27 +54,40 @@ export class HomePage implements OnInit { } ngOnInit() { - - this.uptime.getUptime(true) - .then(uptime => this.myuptime = uptime) - .catch(error => console.log(error)); - this.newsService.getArticles().then((data: any) => { // alert(JSON.stringify()); - this.newsData = JSON.parse(data.data)['content'].items; + + if (this.platform.is('android') || this.platform.is('capacitor')) { + this.newsData = JSON.parse(data.data)['content'].items; + } else { + this.newsData = data.content.items; + } + }, (err) => { console.log(err); this.toastService.presentToastWithOptions("Failed to get News data", "danger"); }); this.newsService.getVideos().then((data: any) => { - this.videoData = JSON.parse(data.data)['content'].items; + + if (this.platform.is('android') || this.platform.is('capacitor')) { + this.videoData = JSON.parse(data.data)['content'].items; + } else { + this.videoData = data.content.items; + } + }, (err) => { this.toastService.presentToastWithOptions("Failed to get Videos data", "danger"); }); this.newsService.getGalleries().then((data: any) => { - this.galleryData = JSON.parse(data.data)['content'].items; + + if (this.platform.is('android') || this.platform.is('capacitor')) { + this.galleryData = JSON.parse(data.data)['content'].items; + } else { + this.galleryData = data.content.items; + } + }, (err) => { console.log(err); this.toastService.presentToastWithOptions("Failed to get Gallery data", "danger"); diff --git a/src/app/services/news.service.ts b/src/app/services/news.service.ts index e0c9d77..bc4b135 100644 --- a/src/app/services/news.service.ts +++ b/src/app/services/news.service.ts @@ -1,5 +1,7 @@ import { Injectable } from '@angular/core'; import { HTTP } from '@ionic-native/http/ngx'; +import { HttpClient } from '@angular/common/http'; +import { Platform } from '@ionic/angular'; export const IMAGE_BASE_URL: string = 'https://www.punjabkingsipl.in/static-assets/waf-images/'; @@ -8,30 +10,56 @@ export const IMAGE_BASE_URL: string = 'https://www.punjabkingsipl.in/static-asse }) export class NewsService { constructor( - private http: HTTP + private http: HTTP, + private httpClient: HttpClient, + private platform: Platform ) { } getArticles() { - return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=4&otherent=1,8021&pgnum=1&inum=10&pgsize=10', {}, {}); + if (this.platform.is('android') || this.platform.is('capacitor')) { + return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=4&otherent=1,8021&pgnum=1&inum=10&pgsize=10', {}, {}); + } else { + return this.httpClient.get('https://www.punjabkingsipl.in/api/listing?entities=4&otherent=1,8021&pgnum=1&inum=10&pgsize=10').toPromise(); + } } getArticleDetails(title_alias_from_listing_api: string) { - return this.http.get('https://www.punjabkingsipl.in/api/article/' + title_alias_from_listing_api + '?is_app=1', {}, {}); + if (this.platform.is('android') || this.platform.is('capacitor')) { + return this.http.get('https://www.punjabkingsipl.in/api/article/' + title_alias_from_listing_api + '?is_app=1', {}, {}); + } else { + return this.httpClient.get('https://www.punjabkingsipl.in/api/article/' + title_alias_from_listing_api + '?is_app=1').toPromise(); + } } getVideos() { - return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=3,4&otherent=&pgnum=1&inum=10&pgsize=10', {}, {}); + if (this.platform.is('android') || this.platform.is('capacitor')) { + return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=3,4&otherent=&pgnum=1&inum=10&pgsize=10', {}, {}); + } else { + return this.httpClient.get('https://www.punjabkingsipl.in/api/listing?entities=3,4&otherent=&pgnum=1&inum=10&pgsize=10').toPromise(); + } } getVideoDetails(title_alias_from_listing_api: string) { - return this.http.get('https://www.punjabkingsipl.in/api/video/' + title_alias_from_listing_api, {}, {}); + if (this.platform.is('android') || this.platform.is('capacitor')) { + return this.http.get('https://www.punjabkingsipl.in/api/video/' + title_alias_from_listing_api, {}, {}); + } else { + return this.httpClient.get('https://www.punjabkingsipl.in/api/video/' + title_alias_from_listing_api).toPromise(); + } } getGalleries() { - return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=2,4&otherent=&pgnum=1&inum=10&pgsize=10', {}, {}); + if (this.platform.is('android') || this.platform.is('capacitor')) { + return this.http.get('https://www.punjabkingsipl.in/api/listing?entities=2,4&otherent=&pgnum=1&inum=10&pgsize=10', {}, {}); + } else { + return this.httpClient.get('https://www.punjabkingsipl.in/api/listing?entities=2,4&otherent=&pgnum=1&inum=10&pgsize=10').toPromise(); + } } getGalleryDetails(title_alias_from_listing_api: string) { - return this.http.get('https://www.punjabkingsipl.in/api/photo/' + title_alias_from_listing_api, {}, {}); + if (this.platform.is('android') || this.platform.is('capacitor')) { + return this.http.get('https://www.punjabkingsipl.in/api/photo/' + title_alias_from_listing_api, {}, {}); + } else { + return this.httpClient.get('https://www.punjabkingsipl.in/api/photo/' + title_alias_from_listing_api).toPromise(); + } } }