Advertisement
Shell_Casing

api-service

Jan 22nd, 2019
617
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Injectable } from '@angular/core';
  2. import { environment } from '../environments/environment';
  3. import { HttpClient } from '@angular/common/http';
  4.  
  5.  
  6. @Injectable({
  7.   providedIn: 'root'
  8. })
  9. export class NewsAPIService {
  10.  
  11.   private sourcesUrl = `https://newsapi.org/v2/sources?language=en&apiKey=${environment.API_KEY}`;
  12.   private headlinesUrl = `https://newsapi.org/v2/top-headlines?sources=techcrunch&apiKey=${environment.API_KEY}`;
  13.  
  14.   constructor(private http: HttpClient) { }
  15.  
  16.   initializeSources() {
  17.     return this.http.get(this.sourcesUrl);
  18.   }
  19.  
  20.   initializeHeadlines() {
  21.     return this.http.get(this.headlinesUrl);
  22.   }
  23.  
  24.   getArticlesByID(sourceId) {
  25.     return this.http.get(`https://newsapi.org/v2/top-headlines?sources=${sourceId}&apiKey=${environment.API_KEY}`);
  26.   }
  27.  
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement