Giter Site home page Giter Site logo

news_api's Introduction

NewsApi

An API wrapper for News API v2

Installation

Add this line to your application's Gemfile:

gem 'news_api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install news_api

Configuration

Add setting with your API key.

NewsApi::Settings.configure do |config|
  config.api_key = 'your_api_key'
end

Usage

News API has 2 main endpoints and 1 minor endpoint.

Read more about required and available params.

Each request below returns instance of ApiStruct::Entity

NewsApi::TopHeadliners.search(country: :us, pageSize: 2)
NewsApi::Everything.search(q: 'bitcoin', pageSize: 2)
NewsApi::Sources.search

Errors handling

Each result respond on methods .failure? and .success?.

For example you have invalid API key:

NewsApi::Settings.configure do |config|
  config.api_key = 'fail_key'
end

NewsApi::Sources.search
=> #<Hashie::Mash body=#<Hashie::Mash code="apiKeyInvalid" message="Your API key is invalid or incorrect. Check your key, or go to https://newsapi.org to create a free API key." status="error"> error=true status=#<HTTP::Response::Status 401 Unauthorized>>

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/kirillshevch/news_api.

License

The gem is available as open source under the terms of the MIT License.

news_api's People

Contributors

kirillshevch avatar

Stargazers

Yusuf Yastı avatar Kushal avatar almokhtar avatar Toan Tran avatar Andrew Mason avatar Miah Raihan Mahmud Arman avatar Mamoun Saudi avatar Rein avatar Shah Zaib avatar Yaroslav Bezrukavyi avatar Alex Babakhanov avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

crowdpro3

news_api's Issues

Question about implementation

@kirillshevch I am a volunteer at a not-for-profit (breakdiving.io).

Am I correct in understanding that this gem will allow us to display news from around the world in a news feed on our site?

If so, from which sources? Where does it get the news headlines?

And how would we actually display the items? Via a .each do loop?

Thanks!
-Monroe

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.