times_wire 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +7 -2
- data/lib/times_wire/item.rb +1 -0
- data/lib/times_wire/section.rb +24 -0
- data/lib/times_wire/version.rb +1 -1
- data/lib/times_wire.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/times_wire/test_item.rb +13 -0
- data/test/times_wire/test_section.rb +15 -0
- metadata +6 -3
data/README.rdoc
CHANGED
@@ -9,6 +9,7 @@ Times Wire is a Ruby gem for interacting with The New York Times Newswire API (h
|
|
9
9
|
|
10
10
|
== News
|
11
11
|
|
12
|
+
* Dec. 15, 2011: Version 0.7.0 released, adding support for retrieving list of sections.
|
12
13
|
* Dec. 14, 2011: Version 0.6.0 released, with support for related URLs and blog name attributes.
|
13
14
|
* Dec. 13, 2011: Version 0.5.0 released.
|
14
15
|
|
@@ -20,7 +21,7 @@ Install Times Wire as a gem:
|
|
20
21
|
|
21
22
|
For use in a Rails 3 application, put the following in your Gemfile:
|
22
23
|
|
23
|
-
gem "times_wire", "~> 0.
|
24
|
+
gem "times_wire", "~> 0.6.0"
|
24
25
|
|
25
26
|
then issue the 'bundle install' command. Times Wire has been tested under Ruby 1.8.7.
|
26
27
|
|
@@ -38,7 +39,11 @@ By default, 20 items are returned, but you may change the limit in any request:
|
|
38
39
|
|
39
40
|
@items = Item.latest('iht', 15)
|
40
41
|
|
41
|
-
Limiting the items retrieved to a section of The Times is easy, too.
|
42
|
+
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:
|
43
|
+
|
44
|
+
@sections = Section.all
|
45
|
+
|
46
|
+
A section name can then be passed as an argument to retrieve items from that section:
|
42
47
|
|
43
48
|
@items = Item.section('nyt', 'world')
|
44
49
|
|
data/lib/times_wire/item.rb
CHANGED
@@ -42,6 +42,7 @@ module TimesWire
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def self.section(source='nyt', section=section, limit=20)
|
45
|
+
section = section.gsub(' ', '+').gsub('&', '%26')
|
45
46
|
reply = Base.invoke("#{source}/#{section}/", {"limit" => limit})
|
46
47
|
results = reply['results']
|
47
48
|
@items = results.map {|r| Item.create_from_api(r)}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module TimesWire
|
2
|
+
class Section < Base
|
3
|
+
|
4
|
+
attr_reader :name
|
5
|
+
|
6
|
+
def initialize(params={})
|
7
|
+
params.each_pair do |k,v|
|
8
|
+
instance_variable_set("@#{k}", v)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.create_from_api(params={})
|
13
|
+
self.new :name => params['section'],
|
14
|
+
:display_name => params['display_name']
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.all
|
18
|
+
reply = Base.invoke("section-list", {"limit" => 20})
|
19
|
+
results = reply['results']
|
20
|
+
sections = results.map {|r| Section.create_from_api(r)}
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/times_wire/version.rb
CHANGED
data/lib/times_wire.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -57,6 +57,19 @@ class TestTimesWire::TestItem < Test::Unit::TestCase
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
# test that sections with spaces and ampersands are properly handled
|
61
|
+
context "create list of 20 items from the fashion & style section of NYT" do
|
62
|
+
setup do
|
63
|
+
@items = Item.section('nyt', 'fashion & style', 20)
|
64
|
+
end
|
65
|
+
|
66
|
+
should "return an array of objects of the Item type from the NYT Fashion & Style section" do
|
67
|
+
assert_equal(20, @items.size)
|
68
|
+
assert_kind_of(Item, @items.first)
|
69
|
+
assert_equal(["Fashion & Style"], @items.map {|i| i.section}.uniq)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
60
73
|
context "create list of items from The Caucus blog" do
|
61
74
|
setup do
|
62
75
|
@items = Item.blog_name('nyt', 'u.s.', 'The Caucus')
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class TestTimesWire::TestSection < Test::Unit::TestCase
|
2
|
+
include TimesWire
|
3
|
+
|
4
|
+
context "list all Sections" do
|
5
|
+
setup do
|
6
|
+
reply = Base.invoke("section-list", {"limit" => 20})
|
7
|
+
results = reply['results']
|
8
|
+
@sections = results.map {|r| Section.create_from_api(r)}
|
9
|
+
end
|
10
|
+
|
11
|
+
should "return objects of the Section type" do
|
12
|
+
assert_kind_of(Section, @sections.first)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
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: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 7
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Derek Willis
|
@@ -50,9 +50,11 @@ files:
|
|
50
50
|
- lib/times_wire.rb
|
51
51
|
- lib/times_wire/base.rb
|
52
52
|
- lib/times_wire/item.rb
|
53
|
+
- lib/times_wire/section.rb
|
53
54
|
- lib/times_wire/version.rb
|
54
55
|
- test/test_helper.rb
|
55
56
|
- test/times_wire/test_item.rb
|
57
|
+
- test/times_wire/test_section.rb
|
56
58
|
- times_wire.gemspec
|
57
59
|
has_rdoc: true
|
58
60
|
homepage: http://rubygems.org/gems/times_wire
|
@@ -91,3 +93,4 @@ summary: A thin client for The New York Times Newswire API
|
|
91
93
|
test_files:
|
92
94
|
- test/test_helper.rb
|
93
95
|
- test/times_wire/test_item.rb
|
96
|
+
- test/times_wire/test_section.rb
|