Skip to content

Instantly share code, notes, and snippets.

@arun12209
Created April 5, 2020 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun12209/63ef51d1bd51bcf19063347200b8a86f to your computer and use it in GitHub Desktop.
Save arun12209/63ef51d1bd51bcf19063347200b8a86f to your computer and use it in GitHub Desktop.
Covid19_IND_TrackerController
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