times_wire 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +13 -0
- data/README.rdoc +61 -0
- data/lib/times_wire/item.rb +3 -1
- data/lib/times_wire/version.rb +1 -1
- data/test/times_wire/test_item.rb +11 -3
- metadata +6 -4
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2011 Derek Willis
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this library except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.rdoc
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
|
2
|
+
.-----. _ .-. .-. _
|
3
|
+
`-. .-':_; : :.-.: ::_;
|
4
|
+
: : .-.,-.,-.,-. .--. .--. : :: :: :.-..--. .--.
|
5
|
+
: : : :: ,. ,. :' '_.'`._-.' : `' `' ;: :: ..'' '_.'
|
6
|
+
:_; :_;:_;:_;:_;`.__.'`.__.' `.,`.,' :_;:_; `.__.
|
7
|
+
|
8
|
+
Times Wire is a Ruby gem for interacting with The New York Times Newswire API (http://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.
|
9
|
+
|
10
|
+
== News
|
11
|
+
|
12
|
+
* Dec. 14, 2011: Version 0.6.0 released, with support for related URLs and blog name attributes.
|
13
|
+
* Dec. 13, 2011: Version 0.5.0 released.
|
14
|
+
|
15
|
+
== Installation
|
16
|
+
|
17
|
+
Install Times Wire as a gem:
|
18
|
+
|
19
|
+
gem install times_wire
|
20
|
+
|
21
|
+
For use in a Rails 3 application, put the following in your Gemfile:
|
22
|
+
|
23
|
+
gem "times_wire", "~> 0.5.0"
|
24
|
+
|
25
|
+
then issue the 'bundle install' command. Times Wire has been tested under Ruby 1.8.7.
|
26
|
+
|
27
|
+
== Getting Started
|
28
|
+
|
29
|
+
You'll need an API Key from The New York Times Developer Network (http://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:
|
30
|
+
|
31
|
+
TimesWire::Base.api_key = API_KEY
|
32
|
+
|
33
|
+
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:
|
34
|
+
|
35
|
+
@items = Item.latest('nyt')
|
36
|
+
|
37
|
+
By default, 20 items are returned, but you may change the limit in any request:
|
38
|
+
|
39
|
+
@items = Item.latest('iht', 15)
|
40
|
+
|
41
|
+
Limiting the items retrieved to a section of The Times is easy, too. For a list of sections, please see the Newswire API documentation (http://developer.nytimes.com/docs/read/times_newswire_api):
|
42
|
+
|
43
|
+
@items = Item.section('nyt', 'world')
|
44
|
+
|
45
|
+
Retrieving items from a single Times blog is similar:
|
46
|
+
|
47
|
+
@items = Item.blog_name('nyt', 'u.s.', 'The Caucus')
|
48
|
+
|
49
|
+
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.
|
50
|
+
|
51
|
+
== Future Development
|
52
|
+
|
53
|
+
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.
|
54
|
+
|
55
|
+
== Authors
|
56
|
+
|
57
|
+
Derek Willis, dwillis@nytimes.com
|
58
|
+
|
59
|
+
== Copyright
|
60
|
+
|
61
|
+
Copyright (c) 2011 Derek Willis. See LICENSE for details.
|
data/lib/times_wire/item.rb
CHANGED
@@ -30,7 +30,9 @@ module TimesWire
|
|
30
30
|
:org_facets => params['org_facet'],
|
31
31
|
:per_facets => params['per_facet'],
|
32
32
|
:geo_facets => params['geo_facet'],
|
33
|
-
:
|
33
|
+
:blog_name => params['blog_name'],
|
34
|
+
:related_urls => params['related_urls'],
|
35
|
+
:multimedia => params['multimedia']
|
34
36
|
end
|
35
37
|
|
36
38
|
def self.latest(source="nyt", limit=20)
|
data/lib/times_wire/version.rb
CHANGED
@@ -3,14 +3,22 @@ class TestTimesWire::TestItem < Test::Unit::TestCase
|
|
3
3
|
|
4
4
|
context "create single Item" do
|
5
5
|
setup do
|
6
|
-
reply = Base.invoke('', {"url" => "http://www.nytimes.com/
|
6
|
+
reply = Base.invoke('', {"url" => "http://www.nytimes.com/2011/12/14/us/california-revenue-shortfall-to-force-cuts.html"})
|
7
7
|
@result = reply['results'].first
|
8
8
|
@item = Item.create_from_api(@result)
|
9
9
|
end
|
10
10
|
|
11
|
-
should "return an object of the Item type" do
|
11
|
+
should "return an object of the Item type" do
|
12
12
|
assert_kind_of(Item, @item)
|
13
13
|
end
|
14
|
+
|
15
|
+
should "have a byline" do
|
16
|
+
assert_equal("By JENNIFER MEDINA", @item.byline)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "have a multimedia array" do
|
20
|
+
assert_equal("Standard Thumbnail", @item.multimedia.first['format'])
|
21
|
+
end
|
14
22
|
end
|
15
23
|
|
16
24
|
context "create list of items from NYT only" do
|
@@ -51,7 +59,7 @@ class TestTimesWire::TestItem < Test::Unit::TestCase
|
|
51
59
|
|
52
60
|
context "create list of items from The Caucus blog" do
|
53
61
|
setup do
|
54
|
-
@items = Item.blog_name('nyt', '
|
62
|
+
@items = Item.blog_name('nyt', 'u.s.', 'The Caucus')
|
55
63
|
end
|
56
64
|
|
57
65
|
should "return an array of objects of the Item type from the NYT U.S. section and Caucus blog" do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: times_wire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 6
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Derek Willis
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-12-
|
18
|
+
date: 2011-12-14 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -44,6 +44,8 @@ extra_rdoc_files: []
|
|
44
44
|
files:
|
45
45
|
- .gitignore
|
46
46
|
- Gemfile
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
47
49
|
- Rakefile
|
48
50
|
- lib/times_wire.rb
|
49
51
|
- lib/times_wire/base.rb
|