.-----. _ .-. .-. _ `-. .-':_; : :.-.: ::_; : : .-.,-.,-.,-. .--. .--. : :: :: :.-..--. .--. : : : :: ,. ,. :' '_.'`._-.' : `' `' ;: :: ..'' '_.' :_; :_;:_;:_;:_;`.__.'`.__.' `.,`.,' :_;:_; `.__.
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. 16, 2011: Version 0.8.0 released, Item returns DateTime objects instead of Dates.
Dec. 15, 2011: Version 0.7.0 released, adding support for retrieving list of sections.
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.7.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. A list of sections supported by the News Wire API can be retrieved as follows:
@sections = Section.all
A section name can then be passed as an argument to retrieve items from that section:
@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, firstname.lastname@example.org
Copyright © 2011 The New York Times Company. See LICENSE for details.