Ruby Wrapper for grabbing data from newsapi. Grab sources and articles quickly and easily.
Add
gem 'news_api_ruby'
to your Gemfile, or,
gem install news_api_ruby
There are only 2 endpoints for the newsapi. 'sources' and 'article'. The gem has broken these endpoints into 2 classes to make it easier to request for both.
Get all available sources using
sources = NewsApi::Source.allThis will return a list of all available sources, wrapped up in a nice Source object. The source object has access to a number of different fields, for example:
source = sources.first
source.category # => general
source.country # => us
source.description # => The AP delivers in-depth coverage on the international, politics, lifestyle, business, and entertainment news.
source.id # => 'associated-press'NOTE: In order to query for an Article, you must first obtain an api key from newsapi.org.
Initialize your key as an environment variable
ENV['API_KEY'] = 'YOUR_KEY'Then, utilize a source to query for all articles for that given source
articles = NewsApi::Article.all s.first
article = articles.first
article.author # => 'John Doe'
article.description # => 'John writes a pretty cool ruby gem'This gem uses rspec for testing. To run the unit tests:
$ bundle exec rspec
There are also a few tests that can be run that make live requests to the API. To run these tests, include your api key:
$ API_KEY=YOUR_API_KEY bundle exec rspec
Please ensure ALL tests are passing before submitting a PR
Please submit bug/feature requests on the github issue page. Of course, pull requests are welcome as well!
This codebase meets rubocop standards (with some exceptions). If contributing, please ensure your PR meets these.
MIT