0.0.6 • Published 6 years ago

@katsuba/newsapi v0.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@katsuba/newsapi

A unofficial modern browser interface for NewsAPI.

Get breaking news headlines, and search for articles from over 30,000 news sources and blogs with news API. Powered by NewsAPI.org.

Install

npm i @katsuba/newsapi

Test

Comming soon...

Example

import { 
    NewsApi, 
    Countries, 
    ArticleResponse 
} from '@katsuba/newsapi';

const api = new NewsAPi('apiKey');

api.topHeadlines({country: Countries.US})
    .then((res: ArticleResponse) => console.log(res))

Example for Angular 6

Live demo

Repo

// app.module.ts
import { NewsApi } from '@katsuba/newsapi';

@NgModule({
  providers: [
    {provide: NewsApi, useFactory: () => new NewsApi(environment.news.apiKey)}
  ]
})
export class AppModule {
}

//news-api.service.ts
import { Injectable } from '@angular/core';
import { Observable, Subscriber } from 'rxjs';
import { ArticleResponse, EverythingPayload, NewsApi } from '@katsuba/newsapi';

@Injectable({
  providedIn: 'root'
})
export class NewsApiService {
  constructor(private newsApi: NewsApi) {
  }

  public everything(payload: EverythingPayload): Observable<ArticleResponse> {
    return Observable.create((subscriber: Subscriber<ArticleResponse>) => {
      this.newsApi.everything(payload).then(
        res => {
          subscriber.next(res);
          subscriber.complete();
        },
        error => subscriber.error(error)
      );
    });
  }
}
0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago

0.0.0

6 years ago