npr 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/.travis.yml +13 -0
  2. data/{LICENSE → MIT-LICENSE} +1 -1
  3. data/README.md +115 -3
  4. data/Rakefile +6 -0
  5. data/gemfiles/Gemfile.rb-1.8.7 +6 -0
  6. data/lib/npr/api/client.rb +87 -0
  7. data/lib/npr/api/message.rb +38 -0
  8. data/lib/npr/api/query_builder.rb +222 -0
  9. data/lib/npr/api/response.rb +32 -0
  10. data/lib/npr/api.rb +7 -0
  11. data/lib/npr/concern/attr_typecast.rb +59 -0
  12. data/lib/npr/concern/relation.rb +103 -0
  13. data/lib/npr/concern/shallow_attributes.rb +71 -0
  14. data/lib/npr/concern.rb +9 -0
  15. data/lib/npr/configuration.rb +120 -0
  16. data/lib/npr/core_ext/array/wrap.rb +15 -0
  17. data/lib/npr/entity/audio.rb +28 -0
  18. data/lib/npr/entity/author.rb +22 -0
  19. data/lib/npr/entity/base.rb +19 -0
  20. data/lib/npr/entity/book.rb +21 -0
  21. data/lib/npr/entity/book_edition.rb +26 -0
  22. data/lib/npr/entity/byline.rb +18 -0
  23. data/lib/npr/entity/collection.rb +11 -0
  24. data/lib/npr/entity/crop.rb +20 -0
  25. data/lib/npr/entity/enlargement.rb +20 -0
  26. data/lib/npr/entity/formats.rb +19 -0
  27. data/lib/npr/entity/image.rb +33 -0
  28. data/lib/npr/entity/intro_text.rb +21 -0
  29. data/lib/npr/entity/link.rb +23 -0
  30. data/lib/npr/entity/list.rb +28 -0
  31. data/lib/npr/entity/list_text.rb +19 -0
  32. data/lib/npr/entity/member.rb +23 -0
  33. data/lib/npr/entity/member_byline.rb +17 -0
  34. data/lib/npr/entity/member_promo_art.rb +17 -0
  35. data/lib/npr/entity/mp3.rb +23 -0
  36. data/lib/npr/entity/organization.rb +18 -0
  37. data/lib/npr/entity/paragraph.rb +27 -0
  38. data/lib/npr/entity/permissions.rb +18 -0
  39. data/lib/npr/entity/program.rb +24 -0
  40. data/lib/npr/entity/promo_art.rb +17 -0
  41. data/lib/npr/entity/promo_art_book_edition.rb +18 -0
  42. data/lib/npr/entity/provider.rb +23 -0
  43. data/lib/npr/entity/pull_quote.rb +16 -0
  44. data/lib/npr/entity/related_link.rb +21 -0
  45. data/lib/npr/entity/show.rb +19 -0
  46. data/lib/npr/entity/story.rb +179 -0
  47. data/lib/npr/entity/text.rb +22 -0
  48. data/lib/npr/entity/title.rb +21 -0
  49. data/lib/npr/entity/transcript.rb +16 -0
  50. data/lib/npr/entity.rb +7 -0
  51. data/lib/npr/errors.rb +17 -0
  52. data/lib/npr/version.rb +1 -1
  53. data/lib/npr.rb +64 -3
  54. data/npr.gemspec +12 -2
  55. data/spec/fixtures/README.md +30 -0
  56. data/spec/fixtures/atom/01_story_full_media.atom +36 -0
  57. data/spec/fixtures/atom/02_story_multiple_images.atom +32 -0
  58. data/spec/fixtures/atom/03_no_results.atom +10 -0
  59. data/spec/fixtures/atom/04_invalid_id.atom +344 -0
  60. data/spec/fixtures/atom/05_no_api_key.atom +9 -0
  61. data/spec/fixtures/atom/06_story_multiple_ids.atom +59 -0
  62. data/spec/fixtures/fetch_formats.rb +65 -0
  63. data/spec/fixtures/html/01_story_full_media.html +54 -0
  64. data/spec/fixtures/html/02_story_multiple_images.html +55 -0
  65. data/spec/fixtures/html/03_no_results.html +38 -0
  66. data/spec/fixtures/html/04_invalid_id.html +82 -0
  67. data/spec/fixtures/html/05_no_api_key.html +8 -0
  68. data/spec/fixtures/html/06_story_multiple_ids.html +69 -0
  69. data/spec/fixtures/js/01_story_full_media.js +1 -0
  70. data/spec/fixtures/js/02_story_multiple_images.js +1 -0
  71. data/spec/fixtures/js/03_no_results.js +1 -0
  72. data/spec/fixtures/js/04_invalid_id.js +1 -0
  73. data/spec/fixtures/js/05_no_api_key.js +8 -0
  74. data/spec/fixtures/js/06_story_multiple_ids.js +1 -0
  75. data/spec/fixtures/json/01_story_full_media.json +1 -0
  76. data/spec/fixtures/json/02_story_multiple_images.json +1 -0
  77. data/spec/fixtures/json/03_no_results.json +1 -0
  78. data/spec/fixtures/json/04_invalid_id.json +1 -0
  79. data/spec/fixtures/json/05_no_api_key.json +1 -0
  80. data/spec/fixtures/json/06_story_multiple_ids.json +1 -0
  81. data/spec/fixtures/json/list.json +1 -0
  82. data/spec/fixtures/mediarss/01_story_full_media.rss +31 -0
  83. data/spec/fixtures/mediarss/02_story_multiple_images.rss +40 -0
  84. data/spec/fixtures/mediarss/03_no_results.rss +17 -0
  85. data/spec/fixtures/mediarss/04_invalid_id.rss +279 -0
  86. data/spec/fixtures/mediarss/05_no_api_key.rss +31 -0
  87. data/spec/fixtures/mediarss/06_story_multiple_ids.rss +65 -0
  88. data/spec/fixtures/nprml/01_story_full_media.xml +271 -0
  89. data/spec/fixtures/nprml/02_story_multiple_images.xml +165 -0
  90. data/spec/fixtures/nprml/03_no_results.xml +14 -0
  91. data/spec/fixtures/nprml/04_invalid_id.xml +1780 -0
  92. data/spec/fixtures/nprml/05_no_api_key.xml +9 -0
  93. data/spec/fixtures/nprml/06_story_multiple_ids.xml +435 -0
  94. data/spec/fixtures/nprml/list.xml +440 -0
  95. data/spec/fixtures/podcast/01_story_full_media.rss +30 -0
  96. data/spec/fixtures/podcast/02_story_multiple_images.rss +32 -0
  97. data/spec/fixtures/podcast/03_no_results.rss +19 -0
  98. data/spec/fixtures/podcast/04_invalid_id.rss +186 -0
  99. data/spec/fixtures/podcast/05_no_api_key.rss +31 -0
  100. data/spec/fixtures/podcast/06_story_multiple_ids.rss +43 -0
  101. data/spec/fixtures/rss/01_story_full_media.rss +25 -0
  102. data/spec/fixtures/rss/02_story_multiple_images.rss +25 -0
  103. data/spec/fixtures/rss/03_no_results.rss +17 -0
  104. data/spec/fixtures/rss/04_invalid_id.rss +137 -0
  105. data/spec/fixtures/rss/05_no_api_key.rss +31 -0
  106. data/spec/fixtures/rss/06_story_multiple_ids.rss +33 -0
  107. data/spec/spec_helper.rb +23 -0
  108. data/spec/support/config_helper.rb +64 -0
  109. data/spec/support/fake_response.rb +54 -0
  110. data/spec/support/fixture_helper.rb +23 -0
  111. data/spec/unit/api/client_spec.rb +42 -0
  112. data/spec/unit/api/message_spec.rb +68 -0
  113. data/spec/unit/api/query_builder_spec.rb +195 -0
  114. data/spec/unit/api/response_spec.rb +45 -0
  115. data/spec/unit/configuration_spec.rb +63 -0
  116. data/spec/unit/entity/audio_spec.rb +75 -0
  117. data/spec/unit/entity/author_spec.rb +30 -0
  118. data/spec/unit/entity/base_spec.rb +87 -0
  119. data/spec/unit/entity/book_edition_spec.rb +57 -0
  120. data/spec/unit/entity/book_spec.rb +31 -0
  121. data/spec/unit/entity/byline_spec.rb +23 -0
  122. data/spec/unit/entity/collection_spec.rb +39 -0
  123. data/spec/unit/entity/crop_spec.rb +25 -0
  124. data/spec/unit/entity/englargement_spec.rb +21 -0
  125. data/spec/unit/entity/formats_spec.rb +41 -0
  126. data/spec/unit/entity/image_spec.rb +82 -0
  127. data/spec/unit/entity/intro_text_spec.rb +25 -0
  128. data/spec/unit/entity/link_spec.rb +25 -0
  129. data/spec/unit/entity/list_spec.rb +22 -0
  130. data/spec/unit/entity/list_text_spec.rb +31 -0
  131. data/spec/unit/entity/member_byline_spec.rb +21 -0
  132. data/spec/unit/entity/member_promo_art_spec.rb +21 -0
  133. data/spec/unit/entity/member_spec.rb +59 -0
  134. data/spec/unit/entity/mp3_spec.rb +25 -0
  135. data/spec/unit/entity/organization_spec.rb +29 -0
  136. data/spec/unit/entity/paragraph_spec.rb +25 -0
  137. data/spec/unit/entity/permissions_spec.rb +56 -0
  138. data/spec/unit/entity/program_spec.rb +27 -0
  139. data/spec/unit/entity/promo_art_book_edition_spec.rb +21 -0
  140. data/spec/unit/entity/promo_art_spec.rb +42 -0
  141. data/spec/unit/entity/pull_quote_spec.rb +29 -0
  142. data/spec/unit/entity/related_link_spec.rb +55 -0
  143. data/spec/unit/entity/show_spec.rb +41 -0
  144. data/spec/unit/entity/story_spec.rb +154 -0
  145. data/spec/unit/entity/text_spec.rb +54 -0
  146. data/spec/unit/entity/title_spec.rb +25 -0
  147. data/spec/unit/entity/transcript_spec.rb +22 -0
  148. metadata +340 -8
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::Organization do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "orgId": "1",
8
+ "orgAbbr": "NPR",
9
+ "name": {
10
+ "$text": "National Public Radio"
11
+ },
12
+ "website": {
13
+ "$text": "http://www.npr.org/"
14
+ }
15
+ }
16
+ JSON
17
+ end
18
+
19
+ before :each do
20
+ @organization = NPR::Entity::Organization.new(@fixture)
21
+ end
22
+
23
+ it "sets up attributes" do
24
+ @organization.name.should match /National/
25
+ @organization.website.should match /npr\.org/
26
+ @organization.orgId.should eq 1
27
+ @organization.orgAbbr.should eq "NPR"
28
+ end
29
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::Paragraph do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "num": "1",
8
+ "$text": "Louisiana music has such a hold on music lovers around the world that nearly every popular artist borrows from it. Or replicates it. Or, some might say, steals from it."
9
+ }
10
+ JSON
11
+ end
12
+
13
+ before :each do
14
+ @paragraph = NPR::Entity::Paragraph.new(@fixture)
15
+ end
16
+
17
+ it "sets up attributes" do
18
+ @paragraph.num.should eq 1
19
+ @paragraph.content.should match /Louisiana/
20
+ end
21
+
22
+ it "uses @content for to_s" do
23
+ @paragraph.to_s.should match /Louisiana/
24
+ end
25
+ end
@@ -0,0 +1,56 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::Permissions do
4
+ describe "with all permissions sent" do
5
+ json_fixture do
6
+ <<-JSON
7
+ {
8
+ "download": {
9
+ "allow": "true"
10
+ },
11
+ "stream": {
12
+ "allow": "true"
13
+ },
14
+ "embed": {
15
+ "allow": "true"
16
+ }
17
+ }
18
+ JSON
19
+ end
20
+
21
+ before :each do
22
+ @permissions = NPR::Entity::Permissions.new(@fixture)
23
+ end
24
+
25
+ it "sets the permissions" do
26
+ @permissions.download.should eq true
27
+ @permissions.stream.should eq true
28
+ @permissions.embed.should eq true
29
+ end
30
+ end
31
+
32
+ #-------------------
33
+
34
+ describe "something is missing" do
35
+ json_fixture do
36
+ <<-JSON
37
+ {
38
+ "download": {
39
+ "allow": "true"
40
+ },
41
+ "stream": {
42
+ "allow": "true"
43
+ }
44
+ }
45
+ JSON
46
+ end
47
+
48
+ before :each do
49
+ @permissions = NPR::Entity::Permissions.new(@fixture)
50
+ end
51
+
52
+ it "sets the permissions" do
53
+ @permissions.embed.should eq nil
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,27 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::Program do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "id": "3",
8
+ "code": "ME",
9
+ "$text": "Morning Edition"
10
+ }
11
+ JSON
12
+ end
13
+
14
+ before :each do
15
+ @program = NPR::Entity::Program.new(@fixture)
16
+ end
17
+
18
+ it "sets up attributes" do
19
+ @program.id.should be_a Integer
20
+ @program.code.should eq "ME"
21
+ @program.content.should eq "Morning Edition"
22
+ end
23
+
24
+ it "uses @content for to_s" do
25
+ @program.to_s.should eq "Morning Edition"
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::PromoArtBookEdition do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "refId": "153611349",
8
+ "num": "4"
9
+ }
10
+ JSON
11
+ end
12
+
13
+ before :each do
14
+ @promo_art_book_edition = NPR::Entity::PromoArtBookEdition.new(@fixture)
15
+ end
16
+
17
+ it "sets attributes" do
18
+ @promo_art_book_edition.refId.should eq 153611349
19
+ @promo_art_book_edition.num.should eq 4
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::PromoArt do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "id": "153610419",
8
+ "type": "standard",
9
+ "width": "200",
10
+ "src": "http://media.npr.org/assets/bakertaylor/covers/a/after-the-apocalypse/9781931520294_custom-14e34b3b9f4a523765c08be02c4e1530607aa0e0.jpg?s=12",
11
+ "bookEditionId": "153610403",
12
+ "hasBorder": "false",
13
+ "title": {
14
+ "$text": "After the Apocalypse"
15
+ },
16
+ "caption": {},
17
+ "link": {
18
+ "url": ""
19
+ },
20
+ "producer": {},
21
+ "provider": {
22
+ "url": ""
23
+ },
24
+ "copyright": {
25
+ "$text": "2011"
26
+ },
27
+ "crop": [
28
+ {
29
+ "type": "custom",
30
+ "src": "http://media.npr.org/assets/bakertaylor/covers/a/after-the-apocalypse/9781931520294_custom-14e34b3b9f4a523765c08be02c4e1530607aa0e0.jpg",
31
+ "height": "600",
32
+ "width": "388"
33
+ }
34
+ ]
35
+ }
36
+ JSON
37
+ end
38
+
39
+ before :each do
40
+ @promo_art = NPR::Entity::PromoArt.new(@fixture)
41
+ end
42
+ end
@@ -0,0 +1,29 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::PullQuote do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "id": "162081891",
8
+ "text": {
9
+ "$text": "Unstructured time outdoors is becoming a thing of the past."
10
+ },
11
+ "person": {
12
+ "$text": "Chelsea Benson"
13
+ },
14
+ "date": {}
15
+ }
16
+ JSON
17
+ end
18
+
19
+ before :each do
20
+ @pull_quote = NPR::Entity::PullQuote.new(@fixture)
21
+ end
22
+
23
+ it "sets up attributes" do
24
+ @pull_quote.id.should be_a Integer
25
+ @pull_quote.text.should match /Unstructured/
26
+ @pull_quote.person.should match /Chelsea/
27
+ @pull_quote.date.should eq nil # no date information
28
+ end
29
+ end
@@ -0,0 +1,55 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::RelatedLink do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "id": "167020072",
8
+ "type": "internal",
9
+ "caption": {
10
+ "$text": " Ravi Shankar At 90: The Man And His Music"
11
+ },
12
+ "link": [
13
+ {
14
+ "type": "html",
15
+ "$text": "http://www.npr.org/2010/04/06/125507150/ravi-shankar-at-90-the-man-and-his-music?ft=3&f=167019577"
16
+ },
17
+ {
18
+ "type": "api",
19
+ "$text": "http://api.npr.org/query?id=125507150&apiKey=MDA1OTI3MjQ5MDEyODUwMTE2MzM1YzNmZA004"
20
+ }
21
+ ]
22
+ }
23
+ JSON
24
+ end
25
+
26
+ #----------------------------
27
+
28
+ describe "relations" do
29
+ it "has links" do
30
+ related_link = NPR::Entity::RelatedLink.new(@fixture)
31
+ related_link.links.size.should eq 2
32
+ related_link.links.first.should be_a NPR::Entity::Link
33
+ end
34
+ end
35
+
36
+ #----------------------------
37
+
38
+ describe "attributes" do
39
+ before :each do
40
+ @related_link = NPR::Entity::RelatedLink.new(@fixture)
41
+ end
42
+
43
+ it "has a caption" do
44
+ @related_link.caption.should match /Ravi Shankar/
45
+ end
46
+
47
+ it "has a type" do
48
+ @related_link.type.should eq "internal"
49
+ end
50
+
51
+ it "has an id" do
52
+ @related_link.id.should be_a Integer
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,41 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::Show do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "program": {
8
+ "id": "3",
9
+ "code": "ME",
10
+ "$text": "Morning Edition"
11
+ },
12
+ "showDate": {
13
+ "$text": "Wed, 12 Dec 2012 04:00:00 -0500"
14
+ },
15
+ "segNum": {
16
+ "$text": "4"
17
+ }
18
+ }
19
+ JSON
20
+ end
21
+
22
+ before :each do
23
+ @show = NPR::Entity::Show.new(@fixture)
24
+ end
25
+
26
+ it "has a program" do
27
+ @show.program.code.should eq "ME"
28
+ end
29
+
30
+ it "doesn't make a program if it's not present in the json" do
31
+ other_fixture = @fixture.dup
32
+ other_fixture.delete("program")
33
+ show = NPR::Entity::Show.new(other_fixture)
34
+ show.program.should eq nil
35
+ end
36
+
37
+ it "sets up attributes" do
38
+ @show.showDate.should be_a Time
39
+ @show.segNum.should be_a Integer
40
+ end
41
+ end
@@ -0,0 +1,154 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::Story do
4
+ config!(:apiKey => "key")
5
+
6
+ #--------------------------
7
+
8
+ describe "relations" do
9
+ before :each do
10
+ @story = mock_response "json/01_story_full_media.json" do
11
+ NPR::Story.find(999)
12
+ end
13
+ end
14
+
15
+ it "sets up relations" do
16
+ @story.images.first.should be_a NPR::Entity::Image
17
+ @story.bylines.first.should be_a NPR::Entity::Byline
18
+ @story.organizations.first.should be_a NPR::Entity::Organization
19
+ @story.links.first.should be_a NPR::Entity::Link
20
+ @story.related_links.first.should be_a NPR::Entity::RelatedLink
21
+ @story.shows.first.should be_a NPR::Entity::Show
22
+
23
+ # The fixture doesn't have these attributes
24
+ # TODO Get a fixtute with these attributes
25
+ @story.pull_quotes.should eq []
26
+ @story.members.should eq []
27
+ @story.promo_arts.should eq []
28
+ @story.list_texts.should eq []
29
+ @story.book_editions.should eq []
30
+
31
+ @story.transcript.should eq nil
32
+ end
33
+ end
34
+
35
+ #--------------------------
36
+
37
+ describe "attributes" do
38
+ before :each do
39
+ @story = mock_response "json/01_story_full_media.json" do
40
+ NPR::Story.find(999)
41
+ end
42
+ end
43
+
44
+ it "Sets up attributes" do
45
+ @story.title.should match /Ravi Shankar/
46
+ @story.partnerId.should be_a Integer
47
+ @story.subtitle.should be_a String
48
+ @story.shortTitle.should be_a String
49
+ @story.miniTeaser.should match /sitar/
50
+ @story.slug.should match /Record/
51
+ @story.storyDate.should be_a Time
52
+ @story.pubDate.should be_a Time
53
+ @story.lastModifiedDate.should be_a Time
54
+ @story.keywords.should be_a String
55
+ @story.priorityKeywords.should be_a String
56
+ @story.fullText.should match /Ravi Shankar/
57
+ end
58
+ end
59
+
60
+ describe "::find" do
61
+ it "instantiates a new story" do
62
+ story = mock_response "json/01_story_full_media.json" do
63
+ NPR::Entity::Story.find(167019577)
64
+ end
65
+
66
+ story.should be_a NPR::Entity::Story
67
+ end
68
+
69
+ it "typecasts the attributes that need it" do
70
+ story = mock_response "json/01_story_full_media.json" do
71
+ NPR::Entity::Story.find(167019577)
72
+ end
73
+
74
+ story.id.should be_a Fixnum
75
+ story.pubDate.should be_a Time
76
+ end
77
+
78
+ context "with multiple ids" do
79
+ it "only returns the first story" do
80
+ story = mock_response "json/06_story_multiple_ids.json" do
81
+ NPR::Entity::Story.find("167055503,166956822")
82
+ end
83
+
84
+ story.should be_a NPR::Entity::Story
85
+ end
86
+ end
87
+
88
+ context "with messages in the response" do
89
+ it "returns the messages" do
90
+ response = mock_response "json/04_invalid_id.json" do
91
+ NPR::Entity::Story.find(000)
92
+ end
93
+
94
+ response.should be_a Array
95
+ response.first.should be_a NPR::API::Message
96
+ end
97
+ end
98
+ end
99
+
100
+ #--------------------
101
+
102
+ describe "::find_by_id" do
103
+ context "with messages in the response" do
104
+ it "returns nil" do
105
+ response = mock_response "json/04_invalid_id.json" do
106
+ NPR::Entity::Story.find_by_id(000)
107
+ end
108
+
109
+ response.should eq nil
110
+ end
111
+ end
112
+ end
113
+
114
+ #--------------------
115
+
116
+ describe "::where" do
117
+ it "creates a new QueryBuilder object and runs #where on it" do
118
+ args = { :id => 9999 }
119
+ query = NPR::Entity::Story.where(args)
120
+ query._klass.should eq NPR::Entity::Story
121
+ query.builder[:conditions].should eq args
122
+ end
123
+ end
124
+
125
+ #--------------------
126
+
127
+ describe "::order" do
128
+ it "creates a new QueryBuilder object and runs #order on it" do
129
+ args = "date descending"
130
+ query = NPR::Entity::Story.order(args)
131
+ query.builder[:order].should eq args
132
+ end
133
+ end
134
+
135
+ #--------------------
136
+
137
+ describe "::limit" do
138
+ it "creates a new QueryBuilder object and runs #limit on it" do
139
+ args = 10
140
+ query = NPR::Entity::Story.limit(args)
141
+ query.builder[:limit].should eq args
142
+ end
143
+ end
144
+
145
+ #--------------------
146
+
147
+ describe "::offset" do
148
+ it "creates a new QueryBuilder object and runs #offset on it" do
149
+ args = 100
150
+ query = NPR::Entity::Story.offset(args)
151
+ query.builder[:offset].should eq args
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,54 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::Text do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "paragraph": [
8
+ {
9
+ "num": "1",
10
+ "$text": "As occurs after seemingly every mass killing that involves firearms, the shootings in a suburban Denver movie theater last week have renewed calls for tougher gun control laws."
11
+ },
12
+ {
13
+ "num": "2",
14
+ "$text": "Just as predictably, those calls have led to pushback by gun-rights advocates who accuse those calling for stricter legislation of trying to exploit the tragedy to restrict Americans' Second Amendment rights."
15
+ },
16
+ {
17
+ "num": "3",
18
+ "$text": "Worth noting is that neither of the two major-party candidates running for the White House has engaged in any current gun control debate."
19
+ },
20
+ {
21
+ "num": "4",
22
+ "$text": "Why that should be is no mystery. For both President Obama, the Democratic standard-bearer, and Mitt Romney, the all-but-official Republican presidential nominee, there's little upside less than four months before Election Day to doing so."
23
+ },
24
+ {
25
+ "num": "5",
26
+ "$text": "Robert J. Spitzer, a political scientist at the State University of New York, Cortland, has written extensively on the nexus of gun control and politics as well as the American presidency. He explained in an interview with It's All Politics:"
27
+ },
28
+ {
29
+ "num": "6"
30
+ },
31
+ {
32
+ "num": "7",
33
+ "$text": "First of all, the Democrats for several years have been backing away from the gun issue. There are always a few exceptions, [Rep.] Carolyn McCarthy [D-N.Y.], people like that. And even though in his background Obama supported stronger gun laws when he was in the Senate and in the state House in Illinois, he clearly made a decision comparable to his political party to sidestep the gun issue. He even signed into law two pro-gun measures - one to allow people to carry guns in national parks and another to allow guns onto Amtrak trains."
34
+ }
35
+ ]
36
+ }
37
+ JSON
38
+ end
39
+
40
+ before :each do
41
+ @text = NPR::Entity::Text.new(@fixture)
42
+ end
43
+
44
+ it "has paragraphs" do
45
+ @text.paragraphs.size.should eq 7
46
+ end
47
+
48
+ it "joins all paragraphs together with to_s" do
49
+ s = @text.to_s
50
+ s.should match /^As occurs/
51
+ s.should match /Amtrak trains\.$/
52
+ s.should match /\n/
53
+ end
54
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::Title do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "num": "2",
8
+ "$text": "2312"
9
+ }
10
+ JSON
11
+ end
12
+
13
+ before :each do
14
+ @title = NPR::Entity::Title.new(@fixture)
15
+ end
16
+
17
+ it "sets attributes" do
18
+ @title.num.should eq 2
19
+ @title.content.should eq "2312"
20
+ end
21
+
22
+ it "uses @content for to_s" do
23
+ @title.to_s.should eq @title.content
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::Transcript do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "link": {
8
+ "type": "api",
9
+ "$text": "http://api.npr.org/transcript?id=166480907&apiKey=MDA1OTI3MjQ5MDEyODUwMTE2MzM1YzNmZA004"
10
+ }
11
+ }
12
+ JSON
13
+ end
14
+
15
+ before :each do
16
+ @transcript = NPR::Entity::Transcript.new(@fixture)
17
+ end
18
+
19
+ it "creates relations" do
20
+ @transcript.link.should be_a NPR::Entity::Link
21
+ end
22
+ end