Socket
Book a DemoInstallSign in
Socket

news_api

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

news_api

0.1.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

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

Top headlines

NewsApi::TopHeadliners.search(country: :us, pageSize: 2)

Everything

NewsApi::Everything.search(q: 'bitcoin', pageSize: 2)

Sources

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.

FAQs

Package last updated on 04 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.