rubynpr 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. data/History.txt +4 -0
  2. data/Manifest.txt +58 -0
  3. data/README.txt +53 -0
  4. data/Rakefile +16 -0
  5. data/bin/rubynpr +0 -0
  6. data/lib/rubynpr/audio.rb +43 -0
  7. data/lib/rubynpr/byline.rb +20 -0
  8. data/lib/rubynpr/client.rb +192 -0
  9. data/lib/rubynpr/content.rb +17 -0
  10. data/lib/rubynpr/exception.rb +34 -0
  11. data/lib/rubynpr/image.rb +34 -0
  12. data/lib/rubynpr/item.rb +25 -0
  13. data/lib/rubynpr/list.rb +47 -0
  14. data/lib/rubynpr/message.rb +15 -0
  15. data/lib/rubynpr/organization.rb +22 -0
  16. data/lib/rubynpr/parent.rb +24 -0
  17. data/lib/rubynpr/product.rb +32 -0
  18. data/lib/rubynpr/pull_quote.rb +12 -0
  19. data/lib/rubynpr/related_link.rb +26 -0
  20. data/lib/rubynpr/result_parser.rb +18 -0
  21. data/lib/rubynpr/show.rb +32 -0
  22. data/lib/rubynpr/story.rb +91 -0
  23. data/lib/rubynpr/subcategory.rb +17 -0
  24. data/lib/rubynpr.rb +28 -0
  25. data/test/audio_test.rb +24 -0
  26. data/test/byline_test.rb +10 -0
  27. data/test/client_test.rb +44 -0
  28. data/test/fixtures/audio.yml +32 -0
  29. data/test/fixtures/byline.yml +6 -0
  30. data/test/fixtures/client.yml +190 -0
  31. data/test/fixtures/image.yml +10 -0
  32. data/test/fixtures/item.yml +15 -0
  33. data/test/fixtures/list.yml +78 -0
  34. data/test/fixtures/list_text.xml +3 -0
  35. data/test/fixtures/organization.yml +11 -0
  36. data/test/fixtures/parent.yml +6 -0
  37. data/test/fixtures/product.yml +9 -0
  38. data/test/fixtures/pullquote.yml +6 -0
  39. data/test/fixtures/relatedlink.yml +6 -0
  40. data/test/fixtures/show.yml +6 -0
  41. data/test/fixtures/stories.yml +522 -0
  42. data/test/fixtures/story.yml +124 -0
  43. data/test/fixtures/subcategory.yml +59 -0
  44. data/test/fixtures.rb +86 -0
  45. data/test/image_test.rb +16 -0
  46. data/test/item_test.rb +18 -0
  47. data/test/list_test.rb +17 -0
  48. data/test/organization_test.rb +16 -0
  49. data/test/parent_test.rb +13 -0
  50. data/test/product_test.rb +16 -0
  51. data/test/pullquote_test.rb +11 -0
  52. data/test/related_link_test.rb +9 -0
  53. data/test/show_test.rb +12 -0
  54. data/test/story_list_test.rb +21 -0
  55. data/test/story_test.rb +50 -0
  56. data/test/subcategory_test.rb +15 -0
  57. data/test/test_helper.rb +12 -0
  58. data/test/test_rubynpr.rb +1 -0
  59. metadata +150 -0
@@ -0,0 +1,124 @@
1
+ typical_story: >
2
+ <nprml version="0.9">
3
+ <list>
4
+ <title>Health &amp; Science</title>
5
+ <teaser><![CDATA[The latest health and science news. Updates on medicine, healthy living, nutrition, drugs, diet, and advances in technology...]]></teaser>
6
+ <miniTeaser/>
7
+ <story id="95604667">
8
+ <link type="html">http://www.npr.org/templates/story/story.php?storyId=95604667&amp;ft=3&amp;f=1007</link>
9
+ <link type="api">http://api.npr.org/query?id=95604667&amp;apiKey=MDAyMDAzMjg3MDEyMjMwMTgyODA0NWNlMg001</link>
10
+ <title>Bridging Gap Between Mental, Physical Health Care</title>
11
+ <subtitle/>
12
+ <shortTitle/>
13
+ <teaser><![CDATA[Provisions slipped into the economic bail out bill mandate that employers and insurance companies give mental health issues parity with physical health issues...]]></teaser>
14
+ <miniTeaser><![CDATA[A new law says that insurance companies must give parity to mental and physical health issues.]]></miniTeaser>
15
+ <slug>Health Care</slug>
16
+ <thumbnail/>
17
+ <storyDate>Fri, 10 Oct 2008 10:00:00 -0400</storyDate>
18
+ <pubDate>Fri, 10 Oct 2008 13:20:00 -0400</pubDate>
19
+ <lastModifiedDate>Fri, 10 Oct 2008 15:39:19 -0400</lastModifiedDate>
20
+ <show>
21
+ <program id="5" code="TOTN">Talk of the Nation</program>
22
+ <showDate>Fri, 10 Oct 2008 15:39:19 -0400</showDate>
23
+ <segNum>5</segNum>
24
+ </show>
25
+ <keywords/>
26
+ <priorityKeywords/>
27
+ <organization orgId="1">
28
+ <name>National Public Radio</name>
29
+ <website type="Home Page">http://www.npr.org/</website>
30
+ </organization>
31
+ <audio id="95608227" type="primary">
32
+ <title/>
33
+ <duration>748</duration>
34
+ <format>
35
+ <mp3>http://api.npr.org/m3u/195608227-30ec0e.m3u&amp;ft=3&amp;f=1007</mp3>
36
+ <wm>http://www.npr.org/templates/dmg/dmg_wmref_em.php?id=95608227&amp;type=1&amp;mtype=WM&amp;ft=3&amp;f=1007</wm>
37
+ <rm>http://www.npr.org/templates/dmg/dmg_rpm.rpm?id=95608227&amp;type=1&amp;mtype=RM&amp;ft=3&amp;f=1007</rm>
38
+ </format>
39
+ <rightsHolder/>
40
+ </audio>
41
+ <image id="90300103" type="standard" width="200" src="http://media.npr.org/politics/election2008/dems/obama/obama_promo.jpg" hasBorder="true">
42
+ <title>Photo gallery of Illinois Sen. Barack Obama</title>
43
+ <caption/>
44
+ <link url="http://www.npr.org/news/images/2008/may/08/obama_slideshow/index.html"/>
45
+ <producer/>
46
+ <provider url=""/>
47
+ <copyright/>
48
+ </image>
49
+ <image id="11830103" type="standard" width="200" src="http://media.npr.org/politics/election2008/dems/obama_bio.gif" hasBorder="true">
50
+ <title>At a Glance: Barack Obama</title>
51
+ <caption/>
52
+ <link url=""/>
53
+ <producer/>
54
+ <provider url=""/>
55
+ <copyright/>
56
+ </image>
57
+ <image id="90333838" type="standard" width="200" src="http://media.npr.org/news/graphics/2008/may/funding_spending200.jpg" hasBorder="true">
58
+ <title>The Pace of the Money Race chart</title>
59
+ <caption>Chart the pace of the presidential race.</caption>
60
+ <link url="http://www.npr.org/buckets/politics/election2008/money_race.html"/>
61
+ <producer>Lindsay Mangum, NPR</producer>
62
+ <provider url=""/>
63
+ <copyright/>
64
+ </image>
65
+ <relatedLink id="96072990" type="internal">
66
+ <caption><![CDATA[Why Can't The Presidential Polls Just Get Along?]]></caption>
67
+ <link type="html">http://www.npr.org/watchingwashington/2008/10/why_cant_the_presidential_poll.html&amp;ft=3&amp;f=96048563</link>
68
+ </relatedLink>
69
+ <parent id="1066" type="topic">
70
+ <title>Your Health</title>
71
+ <link type="html">http://www.npr.org/templates/topics/topic.php?topicId=1066&amp;ft=3&amp;f=1007</link>
72
+ <link type="api">http://api.npr.org/query?id=1066&amp;apiKey=MDAyMDAzMjg3MDEyMjMwMTgyODA0NWNlMg001</link>
73
+ </parent>
74
+ <parent id="1027" type="primaryTopic">
75
+ <title>Health Care</title>
76
+ <link type="html">http://www.npr.org/templates/topics/topic.php?topicId=1027&amp;ft=3&amp;f=1007</link>
77
+ <link type="api">http://api.npr.org/query?id=1027&amp;apiKey=MDAyMDAzMjg3MDEyMjMwMTgyODA0NWNlMg001</link>
78
+ </parent>
79
+ <parent id="1007" type="topic">
80
+ <title>Health &amp; Science</title>
81
+ <link type="html">http://www.npr.org/templates/topics/topic.php?topicId=1007&amp;ft=3&amp;f=1007</link>
82
+ <link type="api">http://api.npr.org/query?id=1007&amp;apiKey=MDAyMDAzMjg3MDEyMjMwMTgyODA0NWNlMg001</link>
83
+ </parent>
84
+ <parent id="1006" type="topic">
85
+ <title>Business</title>
86
+ <link type="html">http://www.npr.org/templates/topics/topic.php?topicId=1006&amp;ft=3&amp;f=1007</link>
87
+ <link type="api">http://api.npr.org/query?id=1006&amp;apiKey=MDAyMDAzMjg3MDEyMjMwMTgyODA0NWNlMg001</link>
88
+ </parent>
89
+ <container id="95605164">
90
+ <title>Related NPR Stories</title><introText/><link refId="95605169" num="1"/><link refId="95605171" num="2"/>
91
+ <link refId="95605173" num="3"/><link refId="95605173" num="4"/>
92
+ </container>
93
+ <text>
94
+ <paragraph num="1"><![CDATA[Provisions slipped into the economic bailout bill mandate that employers and insurance companies...]]></paragraph>
95
+ <paragraph num="2"><![CDATA[William C. Moyers is the vice president of external affairs at the Hazelden Foundation...]]></paragraph>
96
+ </text>
97
+ <textWithHtml>
98
+ <paragraph num="1"><![CDATA[Provisions slipped into the economic bailout bill mandate that employers and insurance companies...]]></paragraph>
99
+ <paragraph num="2"><![CDATA[William C. Moyers is the vice president of external affairs at the Hazelden Foundation...]]></paragraph>
100
+ </textWithHtml>
101
+ <product id="95605177" type="Book">
102
+ <title>Broken</title>
103
+ <author>William C. Moyers</author>
104
+ <upc>0670037893</upc>
105
+ <publisher/>
106
+ <publishYear>0</publishYear>
107
+ <purchaseLink vendor="Amazon">http://www.amazon.com/exec/obidos/ASIN/1592855512/npr-5-20</purchaseLink>
108
+ </product>
109
+ </story>
110
+ </list>
111
+ </nprml>
112
+
113
+ with_no_fields: >
114
+ <nprml version="0.9">
115
+ <list>
116
+ <title>Stories from NPR</title>
117
+ <teaser><![CDATA[Assorted stories from NPR]]></teaser>
118
+ <miniTeaser><![CDATA[Custom NPR News Feed API. Visit http://www.npr.org/templates/apidoc/index.php for more information.]]></miniTeaser>
119
+ <story id="96105723">
120
+ <link type="html">http://www.npr.org/templates/story/story.php?storyId=96105723&amp;ft=3&amp;f=96105723</link>
121
+ <link type="api">http://api.npr.org/query?id=96105723&amp;apiKey=MDAyMDAzMjg3MDEyMjQ1Mjg4OTkxZjcyOQ001</link>
122
+ </story>
123
+ </list>
124
+ </nprml>
@@ -0,0 +1,59 @@
1
+ with_one_item: >
2
+ <subcategory name="Politics & Society">
3
+ <item id="1930201" num="25" type="column">
4
+ <slug/>
5
+ <title>Political Junkie</title>
6
+ <additionalInfo>
7
+ Ken Rudin's Political Junkie column appears every Wednesday. It includes readers' questions about politics past and present.
8
+ </additionalInfo>
9
+ </item>
10
+ </subcategory>
11
+
12
+ with_multiple_items: >
13
+ <subcategory name="Books">
14
+ <item id="4467346" num="2" type="column">
15
+ <slug/>
16
+ <title>Book Reviews</title>
17
+ <additionalInfo>
18
+ Book reviews of the best new fiction and nonfiction books by NPR's Alan Cheuse, Maureen Corrigan, and Karen Grigsby Bates.
19
+ </additionalInfo>
20
+ </item>
21
+ <item id="10448909" num="3" type="column">
22
+ <slug>Summer Books 2008</slug>
23
+ <title>Book Tour</title>
24
+ <additionalInfo>
25
+ Book Tour is a Web feature and podcast. Each week, we present leading contemporary authors of both fiction and nonfiction as they read from and discuss their current work.
26
+ </additionalInfo>
27
+ </item>
28
+ <item id="91752774" num="4" type="column">
29
+ <slug>Summer Books 2008</slug>
30
+ <title>Books We Like</title>
31
+ <additionalInfo>
32
+ There are books, and then there are "Books We Like." Each week in Books We Like, our critics review their top picks for new fiction and nonfiction.
33
+ </additionalInfo>
34
+ </item>
35
+ <item id="4464351" num="5" type="column">
36
+ <slug/>
37
+ <title>Poet on Call</title>
38
+ <additionalInfo>
39
+ Poet and novelist Andrei Codrescu offers a wry twist on news culture in his commentaries for NPR.
40
+ </additionalInfo>
41
+ </item>
42
+ <item id="90796087" num="6" type="column">
43
+ <slug>Summer Books 2008</slug>
44
+ <title>Three Books...</title>
45
+ <additionalInfo>
46
+ Why three? We live in a three-dimensional world, colored with hues that break down into a trio of primary colors. Our souls (according to Plato) and our psyches (according to Freud) are trilithic. Three is a number that allows for conversation, completion, understanding. And so "Three Books..." invites writers to recommend three great reads on a single theme.
47
+ </additionalInfo>
48
+ </item>
49
+ <item id="5432412" num="7" type="column">
50
+ <slug>Summer Books 2008</slug>
51
+ <title>You Must Read This</title>
52
+ <additionalInfo>
53
+ Each week "You Must Read This" presents conversations with writers about the books they love to read and recommend.
54
+ </additionalInfo>
55
+ </item>
56
+ </subcategory>
57
+
58
+ subcategory_with_no_items: >
59
+ <subcategory name="Food"/>
data/test/fixtures.rb ADDED
@@ -0,0 +1,86 @@
1
+ # (Borrowed from Marcel Molina's aws-s3 gem.)
2
+ # When this file is loaded, for each fixture file, a module is created within the Fixtures module
3
+ # with the same name as the fixture file. For each fixture in that fixture file, a singleton method is
4
+ # added to the module with the name of the given fixture, returning the value of the fixture.
5
+ #
6
+ # For example:
7
+ #
8
+ # A fixture in <tt>story.yml</tt> named <tt>story_with_byline</tt> with value <tt><foo>hi!</foo></tt>
9
+ # would be made available like so:
10
+ #
11
+ # Fixtures::Client.bad_api_key_response
12
+ # => "<foo>bad!</foo>"
13
+ #
14
+ # Alternatively you can treat the fixture module like a hash
15
+ #
16
+ # Fixtures::Client[:bad_api_key_response]
17
+ # => "<foo>bad!</foo>"
18
+ #
19
+ # You can find out all available fixtures by calling
20
+ #
21
+ # Fixtures.fixtures
22
+ # => ["Client", "Story"]
23
+ #
24
+ # And all the fixtures contained in a given fixture by calling
25
+ #
26
+ # Fixtures::Client.fixtures
27
+ # => ["bad_api_key_response", "npr_system_error", "deactivated_api_key_res"]
28
+ #
29
+ require 'yaml'
30
+
31
+ module Fixtures
32
+ class << self
33
+ def create_fixtures
34
+ files.each do |file|
35
+ create_fixture_for(file)
36
+ end
37
+ end
38
+
39
+ def create_fixture_for(file)
40
+ fixtures = YAML.load_file(path(file))
41
+ fixture_module = Module.new
42
+
43
+ fixtures.each do |name, value|
44
+ fixture_module.module_eval(<<-EVAL, __FILE__, __LINE__)
45
+ def #{name}
46
+ #{value.inspect}
47
+ end
48
+ module_function :#{name}
49
+ EVAL
50
+ end
51
+
52
+ fixture_module.module_eval(<<-EVAL, __FILE__, __LINE__)
53
+ module_function
54
+
55
+ def fixtures
56
+ #{fixtures.keys.sort.inspect}
57
+ end
58
+
59
+ def [](name)
60
+ send(name) if fixtures.include?(name.to_s)
61
+ end
62
+ EVAL
63
+
64
+ const_set(module_name(file), fixture_module)
65
+ end
66
+
67
+ def fixtures
68
+ constants.sort
69
+ end
70
+
71
+ private
72
+ def files
73
+ Dir.glob(File.dirname(__FILE__) + '/fixtures/*.yml').map {|fixture| File.basename(fixture)}
74
+ end
75
+
76
+ def module_name(file_name)
77
+ File.basename(file_name, '.*').capitalize
78
+ end
79
+
80
+ def path(file_name)
81
+ File.join(File.dirname(__FILE__), 'fixtures', file_name)
82
+ end
83
+ end
84
+
85
+ create_fixtures
86
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class ImageFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_image
5
+ image = Image.new(Hpricot.XML(Fixtures::Image.typical_image).at('image'))
6
+ assert_equal '92343313', image.id
7
+ assert_equal 'standard', image.type
8
+ assert_equal 'Summer Books Main Page', image.title
9
+ assert_equal 'http://media.npr.org/books/summer/2008/promo_165X40.jpg', image.source
10
+ assert_equal '', image.caption
11
+ assert_equal '', image.producer
12
+ assert_equal '', image.copyright
13
+ assert_equal 'false', image.border
14
+ assert_equal 'http://www.npr.org/templates/story/story.php?storyId=90589316', image.link
15
+ end
16
+ end
data/test/item_test.rb ADDED
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class ItemFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_item_without_slug
5
+ item = Item.new(Hpricot.XML(Fixtures::Item.item_without_slug).at('item'))
6
+ assert_equal '4499275', item.id
7
+ assert_equal '10', item.number
8
+ assert_equal 'column', item.type
9
+ assert_equal '', item.slug
10
+ assert_equal 'Sweetness And Light', item.title
11
+ assert_equal "Frank Deford's weekly commentary on sports appears Wednesdays on NPR.org.", item.additional_info
12
+ end
13
+
14
+ def test_should_create_item_with_slug
15
+ item = Item.new(Hpricot.XML(Fixtures::Item.item_with_slug).at('item'))
16
+ assert_equal 'NPR People', item.slug
17
+ end
18
+ end
data/test/list_test.rb ADDED
@@ -0,0 +1,17 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class ListFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_list_without_subcategories
5
+ list = TopicList.new(Hpricot.XML(Fixtures::List.without_subcategories).at('list'))
6
+ assert_equal 'All Topics', list.title
7
+ assert_equal '3002', list.type_id
8
+ assert_equal '3002', list.id
9
+ assert_equal false, list.has_subcategories
10
+ end
11
+
12
+ def test_should_create_list_with_subcategories
13
+ list = TopicList.new(Hpricot.XML(Fixtures::List.with_subcategories).at('list'))
14
+ assert_equal true, list.has_subcategories
15
+ assert_equal 2, list.subcategories.size
16
+ end
17
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class OrganizationFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_organization_with_abbreviation
5
+ org = Organization.new(Hpricot.XML(Fixtures::Organization.org_with_abbreviation).at('organization'))
6
+ assert_equal 'National Public Radio', org.name
7
+ assert_equal '1', org.id
8
+ assert_equal 'NPR', org.abbr
9
+ assert_equal 'http://www.npr.org', org.website
10
+ end
11
+
12
+ def test_should_create_organization_without_abbreviation
13
+ org = Organization.new(Hpricot.XML(Fixtures::Organization.org_without_abbreviation).at('organization'))
14
+ assert_nil org.abbr
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class ParentFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_parent
5
+ parent = Parent.new(Hpricot.XML(Fixtures::Parent.typical_parent).at('parent'))
6
+ assert_equal '1027', parent.id
7
+ assert_equal 'primaryTopic', parent.type
8
+ assert_equal 'Health Care', parent.title
9
+ assert_kind_of Hash, parent.link
10
+ assert_equal 'http://api.npr.org/query?id=1027&amp;apiKey=MDAyMDAzMjg3MDEyMjMwMTgyODA0NWNlMg001', parent.link[:api]
11
+ assert_equal 'http://www.npr.org/templates/topics/topic.php?topicId=1027&amp;ft=3&amp;f=1007', parent.link[:html]
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class ProductFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_product_as_book
5
+ product = Product.new(Hpricot.XML(Fixtures::Product.book).at('product'))
6
+ assert_equal '94639520', product.id
7
+ assert_equal 'Book', product.type
8
+ assert_equal 'Ordinary People', product.title
9
+ assert_equal 'Judith Guest', product.author
10
+ assert_equal '', product.publisher
11
+ assert_equal '0', product.year
12
+ assert_equal '0140065172', product.upc
13
+ assert_equal 'Amazon', product.link[:vendor]
14
+ assert_equal 'http://www.amazon.com/exec/obidos/ASIN/0140065172/npr-5-20', product.link[:uri]
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class PullQuoteFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_pullquote
5
+ pullquote = PullQuote.new(Hpricot.XML(Fixtures::Pullquote.typical_pullquote).at('pullQuote'))
6
+ assert_equal '95611389', pullquote.id
7
+ assert_equal 'Robert Stone', pullquote.person
8
+ assert_equal 'Both [McCain and Obama] in their way are tough guys, and their code is inherent in Robert Jordan. ... Hemingway kind of created the idea of the anti-fascist hero.',
9
+ pullquote.text
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class RelatedLinksFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_related_link
5
+ rel_link = RelatedLink.new(Hpricot.XML(Fixtures::Relatedlink.typical_link).at('relatedLink'))
6
+ assert_equal 'Bernanke Hints At Rate Cuts', rel_link.caption
7
+ assert_equal 'http://www.npr.org/templates/story/story.php?storyId=95484248&amp;ft=3&amp;f=1006', rel_link.uri[:html]
8
+ end
9
+ end
data/test/show_test.rb ADDED
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class ShowTest < Test::Unit::TestCase
4
+ def test_should_create_typical_show
5
+ show = Show.new(Hpricot.XML(Fixtures::Show.typical_show))
6
+ assert_equal '5', show.segment
7
+ assert_equal 'Talk of the Nation', show.program[:name]
8
+ assert_equal '5', show.program[:id]
9
+ assert_equal 'TOTN', show.program[:code]
10
+ assert_equal DateTime.new(2008, 10, 10, 15, 39, 19, DateTime.now.offset), show.date
11
+ end
12
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class StoryListFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_story_list_with_three_stories
5
+ stories = StoryList.new(Hpricot.XML(Fixtures::Stories.story_result_listing))
6
+ assert_equal 5, stories.list.length
7
+ assert_equal 'Business', stories.title
8
+ assert_equal '', stories.mini_teaser
9
+ assert_equal 'Find the latest business news with reports on Wall Street, interest rates, banking, companies, and U.S. and world financial markets. Subscribe to the Business Story of the Day podcast.',
10
+ stories.teaser
11
+ end
12
+
13
+ def test_should_create_story_list_with_one_story
14
+ stories = StoryList.new(Hpricot.XML(Fixtures::Story.typical_story))
15
+ assert_equal 1, stories.list.length
16
+ assert_equal 'Health &amp; Science', stories.title
17
+ assert_equal 'The latest health and science news. Updates on medicine, healthy living, nutrition, drugs, diet, and advances in technology...',
18
+ stories.teaser
19
+ assert_equal '', stories.mini_teaser
20
+ end
21
+ end
@@ -0,0 +1,50 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class StoryFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_story_with_all_fields
5
+ story = Story.new(Hpricot.XML(Fixtures::Story.typical_story).at('story'))
6
+ assert_equal '95604667', story.id
7
+ assert_equal 'Bridging Gap Between Mental, Physical Health Care', story.title
8
+ assert_equal '', story.subtitle
9
+ assert_equal 'Health Care', story.slug
10
+ assert_equal 'Provisions slipped into the economic bail out bill mandate that employers and insurance companies give mental health issues parity with physical health issues...', \
11
+ story.teaser
12
+ assert_equal 'A new law says that insurance companies must give parity to mental and physical health issues.', story.mini_teaser
13
+ assert_equal 'http://api.npr.org/query?id=95604667&amp;apiKey=MDAyMDAzMjg3MDEyMjMwMTgyODA0NWNlMg001', story.link[:api]
14
+ assert_equal 'http://www.npr.org/templates/story/story.php?storyId=95604667&amp;ft=3&amp;f=1007', story.link[:html]
15
+ assert_equal DateTime.new(2008, 10, 10, 13, 20, 0, DateTime.now.offset), story.publication_date
16
+ assert_equal DateTime.new(2008, 10, 10, 10, 0, 0, DateTime.now.offset), story.story_date
17
+ assert_equal DateTime.new(2008, 10, 10, 15, 39, 19, DateTime.now.offset), story.last_modified
18
+ assert_kind_of Organization, story.organization
19
+ assert_kind_of Show, story.show
20
+ assert_kind_of Audio, story.audio
21
+ assert_kind_of Array, story.parents
22
+ assert_kind_of Array, story.products
23
+ assert_kind_of Array, story.related_links
24
+ assert_equal 2, story.plain_text.length
25
+ assert_equal 2, story.html_text.length
26
+ end
27
+
28
+ def test_should_create_story_with_no_fields
29
+ story = Story.new(Hpricot.XML(Fixtures::Story.with_no_fields).at('story'))
30
+ assert_equal('96105723', story.id)
31
+ assert_equal 'http://www.npr.org/templates/story/story.php?storyId=96105723&amp;ft=3&amp;f=96105723', story.link[:html]
32
+ assert_equal 'http://api.npr.org/query?id=96105723&amp;apiKey=MDAyMDAzMjg3MDEyMjQ1Mjg4OTkxZjcyOQ001', story.link[:api]
33
+ assert_nil story.title
34
+ assert_nil story.slug
35
+ assert_nil story.subtitle
36
+ assert_nil story.teaser
37
+ assert_nil story.mini_teaser
38
+ assert_nil story.publication_date
39
+ assert_nil story.story_date
40
+ assert_nil story.last_modified
41
+ assert_nil story.organization
42
+ assert_nil story.show
43
+ assert_nil story.audio
44
+ assert_nil story.parents
45
+ assert_nil story.products
46
+ assert_nil story.related_links
47
+ assert_nil story.plain_text
48
+ assert_nil story.html_text
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/test_rubynpr.rb'
2
+
3
+ class SubcategoryFromNPRMLTest < Test::Unit::TestCase
4
+ def test_should_create_subcategory_with_one_item
5
+ subcategory = Subcategory.new(Hpricot.XML(Fixtures::Subcategory.with_one_item).at('subcategory'))
6
+ assert_equal 1, subcategory.items.length
7
+ assert_equal 'Politics & Society', subcategory.name
8
+ end
9
+
10
+ def test_should_create_subcategory_with_multiple_items
11
+ subcategory = Subcategory.new(Hpricot.XML(Fixtures::Subcategory.with_multiple_items).at('subcategory'))
12
+ assert_equal 6, subcategory.items.length
13
+ assert_equal 'Books', subcategory.name
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ require 'test/unit'
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
+
5
+ require File.dirname(__FILE__) + '/fixtures'
6
+ require 'rubynpr'
7
+ require 'rubygems'
8
+ require 'mocha'
9
+
10
+ class Test::Unit::TestCase
11
+ include NPR
12
+ end
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'