Skip to content

VinnieVendemia/news_api_ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NEWS API Wrapper

Ruby Wrapper for grabbing data from newsapi. Grab sources and articles quickly and easily.

Install

Add

	gem 'news_api_ruby'

to your Gemfile, or,

	gem install news_api_ruby

Usage

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.

Source

Get all available sources using

sources = NewsApi::Source.all

This 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'

Article

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'

Tests

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

Contributing

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.

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages