.-----. _ .-. .-. _ `-. .-':_; : :.-.: ::_; : : .-.,-.,-.,-. .--. .--. : :: :: :.-..--. .--. : : : :: ,. ,. :' '_.'`._-.' : `' `' ;: :: ..'' '_.' :_; :_;:_;:_;:_;`.__.'`.__.' `.,`.,' :_;:_; `.__.
Times Wire is a Ruby gem for interacting with The New York Times Newswire API (developer.nytimes.com/docs/read/times_newswire_api), which provides an up-to-the-minute stream of articles and blog posts published on NYTimes.com and The International Herald-Tribune.
Dec. 14, 2011: Version 0.6.0 released, with support for related URLs and blog name attributes.
Dec. 13, 2011: Version 0.5.0 released.
Install Times Wire as a gem:
gem install times_wire
For use in a Rails 3 application, put the following in your Gemfile:
gem "times_wire", "~> 0.5.0"
then issue the 'bundle install' command. Times Wire has been tested under Ruby 1.8.7.
You'll need an API Key from The New York Times Developer Network (developer.nytimes.com/). You can set your key as an environment variable (handy for running the test suite) or set it within a script or app:
TimesWire::Base.api_key = API_KEY
Times Wire allows users to retrieve news items by source ('nyt', 'iht' or 'all'), by section (such as 'world', 'u.s.', 'sports') or by NYTimes.com blog names (“The Caucus”, “FiveThirtyEight” or “At War”, for example). Building a request is easy. To retrieve the latest items from The New York Times:
@items = Item.latest('nyt')
By default, 20 items are returned, but you may change the limit in any request:
@items = Item.latest('iht', 15)
Limiting the items retrieved to a section of The Times is easy, too. For a list of sections, please see the Newswire API documentation (developer.nytimes.com/docs/read/times_newswire_api):
@items = Item.section('nyt', 'world')
Retrieving items from a single Times blog is similar:
@items = Item.blog_name('nyt', 'u.s.', 'The Caucus')
Items from the Newswire API have mostly the same attributes, with some exceptions. Blog posts will have a “blog_name” attribute, while articles do not. Items that have facets and related_urls will return an array of those items, and items that have some multimedia elements (usually photographs) will return an array containing a hash for each multimedia element.
On the list for future additions is the ability to limit requests to a specific number of hours and to support offsets. Patches, pull requests and feature ideas welcomed.
Derek Willis, email@example.com
Copyright © 2011 Derek Willis. See LICENSE for details.