Created
April 5, 2020 08:29
-
-
Save arun12209/63ef51d1bd51bcf19063347200b8a86f to your computer and use it in GitHub Desktop.
Covid19_IND_TrackerController
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Covid19_IND_TrackerController { | |
@AuraEnabled | |
public static covid19DataParser fecthCovid19Data(){ | |
string baseURL='https://api.covid19india.org/data.json'; | |
HttpRequest reqest = new HttpRequest(); | |
reqest.setEndpoint(baseURL); | |
reqest.setMethod('GET'); | |
reqest.setHeader('Accept','application/json'); | |
Http h = new Http(); | |
HTTPResponse response = h.send(reqest); | |
system.debug('Response : ' +response.getBody()); | |
covid19DataParser prsr = covid19DataParser.parse(response.getBody()); | |
system.debug('Object = ' +prsr); | |
return prsr; | |
} | |
@AuraEnabled | |
public static JsonNewWrapper fetchNews(){ | |
string apiKey=''; // put your API Key (NewsAPI.org) | |
Integer day = system.today().day()-2; | |
String formDate = string.valueOf(system.today().year()+'-0'+system.today().month()+'-0'+day); | |
//string baseURL='http://newsapi.org/v2/everything?q=covid19&sources=Google News (India),BBC News,Financial Times,The Wall Street Journal,Reddit,Time,The Economist,National Geographic,Google News,Fortune,Business Insider UK,Cnn,The Times Of India,Techcrunch,The New York Times,The Washington Post,Cnbc,The Hindu,The Verge&language=en&from=2020-03-04&sortBy=publishedAt&apiKey='+apiKey; | |
string baseURL='http://newsapi.org/v2/everything?q=covid19&domains=ndtv.com,timesofindia.indiatimes.com,thehindu.com,indiatoday.in,republicworld.com,news.google.com,zeenews.india.com&language=en&from='+formDate+'&sortBy=publishedAt&apiKey='+apiKey;//+system.today().format()+ | |
HttpRequest reqest = new HttpRequest(); | |
reqest.setEndpoint(baseURL); | |
reqest.setMethod('GET'); | |
reqest.setHeader('Accept','application/json'); | |
Http h = new Http(); | |
HTTPResponse response = h.send(reqest); | |
system.debug('status: '+response.getstatusCode()); | |
system.debug('body: '+response.getBody()); | |
JsonNewWrapper jnw = JsonNewWrapper.parse(response.getBody()); | |
return jnw; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment