npr 0.0.0 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +13 -0
- data/{LICENSE → MIT-LICENSE} +1 -1
- data/README.md +115 -3
- data/Rakefile +6 -0
- data/gemfiles/Gemfile.rb-1.8.7 +6 -0
- data/lib/npr/api/client.rb +87 -0
- data/lib/npr/api/message.rb +38 -0
- data/lib/npr/api/query_builder.rb +222 -0
- data/lib/npr/api/response.rb +32 -0
- data/lib/npr/api.rb +7 -0
- data/lib/npr/concern/attr_typecast.rb +59 -0
- data/lib/npr/concern/relation.rb +103 -0
- data/lib/npr/concern/shallow_attributes.rb +71 -0
- data/lib/npr/concern.rb +9 -0
- data/lib/npr/configuration.rb +120 -0
- data/lib/npr/core_ext/array/wrap.rb +15 -0
- data/lib/npr/entity/audio.rb +28 -0
- data/lib/npr/entity/author.rb +22 -0
- data/lib/npr/entity/base.rb +19 -0
- data/lib/npr/entity/book.rb +21 -0
- data/lib/npr/entity/book_edition.rb +26 -0
- data/lib/npr/entity/byline.rb +18 -0
- data/lib/npr/entity/collection.rb +11 -0
- data/lib/npr/entity/crop.rb +20 -0
- data/lib/npr/entity/enlargement.rb +20 -0
- data/lib/npr/entity/formats.rb +19 -0
- data/lib/npr/entity/image.rb +33 -0
- data/lib/npr/entity/intro_text.rb +21 -0
- data/lib/npr/entity/link.rb +23 -0
- data/lib/npr/entity/list.rb +28 -0
- data/lib/npr/entity/list_text.rb +19 -0
- data/lib/npr/entity/member.rb +23 -0
- data/lib/npr/entity/member_byline.rb +17 -0
- data/lib/npr/entity/member_promo_art.rb +17 -0
- data/lib/npr/entity/mp3.rb +23 -0
- data/lib/npr/entity/organization.rb +18 -0
- data/lib/npr/entity/paragraph.rb +27 -0
- data/lib/npr/entity/permissions.rb +18 -0
- data/lib/npr/entity/program.rb +24 -0
- data/lib/npr/entity/promo_art.rb +17 -0
- data/lib/npr/entity/promo_art_book_edition.rb +18 -0
- data/lib/npr/entity/provider.rb +23 -0
- data/lib/npr/entity/pull_quote.rb +16 -0
- data/lib/npr/entity/related_link.rb +21 -0
- data/lib/npr/entity/show.rb +19 -0
- data/lib/npr/entity/story.rb +179 -0
- data/lib/npr/entity/text.rb +22 -0
- data/lib/npr/entity/title.rb +21 -0
- data/lib/npr/entity/transcript.rb +16 -0
- data/lib/npr/entity.rb +7 -0
- data/lib/npr/errors.rb +17 -0
- data/lib/npr/version.rb +1 -1
- data/lib/npr.rb +64 -3
- data/npr.gemspec +12 -2
- data/spec/fixtures/README.md +30 -0
- data/spec/fixtures/atom/01_story_full_media.atom +36 -0
- data/spec/fixtures/atom/02_story_multiple_images.atom +32 -0
- data/spec/fixtures/atom/03_no_results.atom +10 -0
- data/spec/fixtures/atom/04_invalid_id.atom +344 -0
- data/spec/fixtures/atom/05_no_api_key.atom +9 -0
- data/spec/fixtures/atom/06_story_multiple_ids.atom +59 -0
- data/spec/fixtures/fetch_formats.rb +65 -0
- data/spec/fixtures/html/01_story_full_media.html +54 -0
- data/spec/fixtures/html/02_story_multiple_images.html +55 -0
- data/spec/fixtures/html/03_no_results.html +38 -0
- data/spec/fixtures/html/04_invalid_id.html +82 -0
- data/spec/fixtures/html/05_no_api_key.html +8 -0
- data/spec/fixtures/html/06_story_multiple_ids.html +69 -0
- data/spec/fixtures/js/01_story_full_media.js +1 -0
- data/spec/fixtures/js/02_story_multiple_images.js +1 -0
- data/spec/fixtures/js/03_no_results.js +1 -0
- data/spec/fixtures/js/04_invalid_id.js +1 -0
- data/spec/fixtures/js/05_no_api_key.js +8 -0
- data/spec/fixtures/js/06_story_multiple_ids.js +1 -0
- data/spec/fixtures/json/01_story_full_media.json +1 -0
- data/spec/fixtures/json/02_story_multiple_images.json +1 -0
- data/spec/fixtures/json/03_no_results.json +1 -0
- data/spec/fixtures/json/04_invalid_id.json +1 -0
- data/spec/fixtures/json/05_no_api_key.json +1 -0
- data/spec/fixtures/json/06_story_multiple_ids.json +1 -0
- data/spec/fixtures/json/list.json +1 -0
- data/spec/fixtures/mediarss/01_story_full_media.rss +31 -0
- data/spec/fixtures/mediarss/02_story_multiple_images.rss +40 -0
- data/spec/fixtures/mediarss/03_no_results.rss +17 -0
- data/spec/fixtures/mediarss/04_invalid_id.rss +279 -0
- data/spec/fixtures/mediarss/05_no_api_key.rss +31 -0
- data/spec/fixtures/mediarss/06_story_multiple_ids.rss +65 -0
- data/spec/fixtures/nprml/01_story_full_media.xml +271 -0
- data/spec/fixtures/nprml/02_story_multiple_images.xml +165 -0
- data/spec/fixtures/nprml/03_no_results.xml +14 -0
- data/spec/fixtures/nprml/04_invalid_id.xml +1780 -0
- data/spec/fixtures/nprml/05_no_api_key.xml +9 -0
- data/spec/fixtures/nprml/06_story_multiple_ids.xml +435 -0
- data/spec/fixtures/nprml/list.xml +440 -0
- data/spec/fixtures/podcast/01_story_full_media.rss +30 -0
- data/spec/fixtures/podcast/02_story_multiple_images.rss +32 -0
- data/spec/fixtures/podcast/03_no_results.rss +19 -0
- data/spec/fixtures/podcast/04_invalid_id.rss +186 -0
- data/spec/fixtures/podcast/05_no_api_key.rss +31 -0
- data/spec/fixtures/podcast/06_story_multiple_ids.rss +43 -0
- data/spec/fixtures/rss/01_story_full_media.rss +25 -0
- data/spec/fixtures/rss/02_story_multiple_images.rss +25 -0
- data/spec/fixtures/rss/03_no_results.rss +17 -0
- data/spec/fixtures/rss/04_invalid_id.rss +137 -0
- data/spec/fixtures/rss/05_no_api_key.rss +31 -0
- data/spec/fixtures/rss/06_story_multiple_ids.rss +33 -0
- data/spec/spec_helper.rb +23 -0
- data/spec/support/config_helper.rb +64 -0
- data/spec/support/fake_response.rb +54 -0
- data/spec/support/fixture_helper.rb +23 -0
- data/spec/unit/api/client_spec.rb +42 -0
- data/spec/unit/api/message_spec.rb +68 -0
- data/spec/unit/api/query_builder_spec.rb +195 -0
- data/spec/unit/api/response_spec.rb +45 -0
- data/spec/unit/configuration_spec.rb +63 -0
- data/spec/unit/entity/audio_spec.rb +75 -0
- data/spec/unit/entity/author_spec.rb +30 -0
- data/spec/unit/entity/base_spec.rb +87 -0
- data/spec/unit/entity/book_edition_spec.rb +57 -0
- data/spec/unit/entity/book_spec.rb +31 -0
- data/spec/unit/entity/byline_spec.rb +23 -0
- data/spec/unit/entity/collection_spec.rb +39 -0
- data/spec/unit/entity/crop_spec.rb +25 -0
- data/spec/unit/entity/englargement_spec.rb +21 -0
- data/spec/unit/entity/formats_spec.rb +41 -0
- data/spec/unit/entity/image_spec.rb +82 -0
- data/spec/unit/entity/intro_text_spec.rb +25 -0
- data/spec/unit/entity/link_spec.rb +25 -0
- data/spec/unit/entity/list_spec.rb +22 -0
- data/spec/unit/entity/list_text_spec.rb +31 -0
- data/spec/unit/entity/member_byline_spec.rb +21 -0
- data/spec/unit/entity/member_promo_art_spec.rb +21 -0
- data/spec/unit/entity/member_spec.rb +59 -0
- data/spec/unit/entity/mp3_spec.rb +25 -0
- data/spec/unit/entity/organization_spec.rb +29 -0
- data/spec/unit/entity/paragraph_spec.rb +25 -0
- data/spec/unit/entity/permissions_spec.rb +56 -0
- data/spec/unit/entity/program_spec.rb +27 -0
- data/spec/unit/entity/promo_art_book_edition_spec.rb +21 -0
- data/spec/unit/entity/promo_art_spec.rb +42 -0
- data/spec/unit/entity/pull_quote_spec.rb +29 -0
- data/spec/unit/entity/related_link_spec.rb +55 -0
- data/spec/unit/entity/show_spec.rb +41 -0
- data/spec/unit/entity/story_spec.rb +154 -0
- data/spec/unit/entity/text_spec.rb +54 -0
- data/spec/unit/entity/title_spec.rb +25 -0
- data/spec/unit/entity/transcript_spec.rb +22 -0
- metadata +340 -8
@@ -0,0 +1,30 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Author do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"id": "139197905",
|
8
|
+
"num": "3",
|
9
|
+
"title": {
|
10
|
+
"$text": "Kim Stanley Robinson"
|
11
|
+
},
|
12
|
+
"link": {
|
13
|
+
"type": "api",
|
14
|
+
"$text": "http://api.npr.org/query?id=139197905&apiKey=MDA1OTI3MjQ5MDEyODUwMTE2MzM1YzNmZA004"
|
15
|
+
}
|
16
|
+
}
|
17
|
+
JSON
|
18
|
+
end
|
19
|
+
|
20
|
+
before :each do
|
21
|
+
@author = NPR::Entity::Author.new(@fixture)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "sets attributes" do
|
25
|
+
@author.id.should eq 139197905
|
26
|
+
@author.num.should eq 3
|
27
|
+
@author.title.should match /Kim/
|
28
|
+
@author.link.should be_a NPR::Entity::Link
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Base do
|
4
|
+
describe "::shallow_attribute" do
|
5
|
+
before :all do
|
6
|
+
@reset = NPR::Entity::Base.send :_shallow_attributes
|
7
|
+
NPR::Entity::Base.shallow_attribute("banjo", "kazooie")
|
8
|
+
end
|
9
|
+
|
10
|
+
after :all do
|
11
|
+
NPR::Entity::Base.send :_shallow_attributes=, @reset
|
12
|
+
end
|
13
|
+
|
14
|
+
it "assigns shallow_attributes" do
|
15
|
+
NPR::Entity::Base._shallow_attributes.should eq ["banjo", "kazooie"]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "defines accessors" do
|
19
|
+
entity = NPR::Entity::Base.new
|
20
|
+
entity.should respond_to :banjo
|
21
|
+
entity.should respond_to :kazooie
|
22
|
+
entity.should respond_to :banjo=
|
23
|
+
entity.should respond_to :kazooie=
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
#--------------------
|
28
|
+
|
29
|
+
describe "::has_many" do
|
30
|
+
before :all do
|
31
|
+
@reset = NPR::Entity::Base.send :_has_many_relations
|
32
|
+
NPR::Entity::Base.has_many("objects", :key => "object", :class_name => Object)
|
33
|
+
end
|
34
|
+
|
35
|
+
after :all do
|
36
|
+
NPR::Entity::Base.send :_has_many_relations=, @reset
|
37
|
+
end
|
38
|
+
|
39
|
+
it "assigns relations" do
|
40
|
+
NPR::Entity::Base._has_many_relations.should eq [{
|
41
|
+
:name => "objects",
|
42
|
+
:key => "object",
|
43
|
+
:class_name => Object
|
44
|
+
}]
|
45
|
+
end
|
46
|
+
|
47
|
+
it "defines accessors" do
|
48
|
+
entity = NPR::Entity::Base.new
|
49
|
+
entity.should respond_to :objects
|
50
|
+
entity.should respond_to :objects=
|
51
|
+
end
|
52
|
+
|
53
|
+
it "sets reader to array on first access" do
|
54
|
+
entity = NPR::Entity::Base.new
|
55
|
+
entity.instance_variable_get(:@objects).should eq nil
|
56
|
+
entity.objects.should eq []
|
57
|
+
entity.instance_variable_get(:@objects).should eq []
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
#--------------------
|
62
|
+
|
63
|
+
describe "::has_one" do
|
64
|
+
before :all do
|
65
|
+
@reset = NPR::Entity::Base.send :_has_one_relations
|
66
|
+
NPR::Entity::Base.has_one "object", :class_name => Object
|
67
|
+
end
|
68
|
+
|
69
|
+
after :all do
|
70
|
+
NPR::Entity::Base.send :_has_one_relations=, @reset
|
71
|
+
end
|
72
|
+
|
73
|
+
it "assigns relations" do
|
74
|
+
NPR::Entity::Base._has_one_relations.should eq [{
|
75
|
+
:name => "object",
|
76
|
+
:key => "object",
|
77
|
+
:class_name => Object
|
78
|
+
}]
|
79
|
+
end
|
80
|
+
|
81
|
+
it "defines accessor" do
|
82
|
+
entity = NPR::Entity::Base.new
|
83
|
+
entity.should respond_to :object
|
84
|
+
entity.should respond_to :object=
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::BookEdition do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"id": "153611349",
|
8
|
+
"isbn": {
|
9
|
+
"$text": "9780316098120"
|
10
|
+
},
|
11
|
+
"book": {
|
12
|
+
"id": "153611337",
|
13
|
+
"title": {
|
14
|
+
"$text": "2312"
|
15
|
+
},
|
16
|
+
"link": {
|
17
|
+
"type": "short",
|
18
|
+
"$text": "http://n.pr/LdlQZZ"
|
19
|
+
}
|
20
|
+
},
|
21
|
+
"publisher": {
|
22
|
+
"$text": "Orbit"
|
23
|
+
},
|
24
|
+
"format": {
|
25
|
+
"$text": "1"
|
26
|
+
},
|
27
|
+
"pubDate": {
|
28
|
+
"$text": "2012-05-22 00:00:00"
|
29
|
+
},
|
30
|
+
"pagination": {
|
31
|
+
"$text": "561 pages"
|
32
|
+
},
|
33
|
+
"listPrice": {
|
34
|
+
"$text": "$25.99"
|
35
|
+
}
|
36
|
+
}
|
37
|
+
JSON
|
38
|
+
end
|
39
|
+
|
40
|
+
before :each do
|
41
|
+
@book_edition = NPR::Entity::BookEdition.new(@fixture)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "sets up attributes" do
|
45
|
+
@book_edition.id.should eq 153611349
|
46
|
+
@book_edition.isbn.should be_a String
|
47
|
+
@book_edition.publisher.should eq "Orbit"
|
48
|
+
@book_edition.format_num.should eq 1
|
49
|
+
@book_edition.pubDate.should be_a Time
|
50
|
+
@book_edition.pagination.should match /561 pages/
|
51
|
+
@book_edition.listPrice.should match /25\.99/
|
52
|
+
end
|
53
|
+
|
54
|
+
it "creates relations" do
|
55
|
+
@book_edition.book.should be_a NPR::Entity::Book
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Book do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"id": "153611337",
|
8
|
+
"title": {
|
9
|
+
"$text": "2312"
|
10
|
+
},
|
11
|
+
"link": {
|
12
|
+
"type": "short",
|
13
|
+
"$text": "http://n.pr/LdlQZZ"
|
14
|
+
}
|
15
|
+
}
|
16
|
+
JSON
|
17
|
+
end
|
18
|
+
|
19
|
+
before :each do
|
20
|
+
@book = NPR::Entity::Book.new(@fixture)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "sets up attributes" do
|
24
|
+
@book.id.should eq 153611337
|
25
|
+
@book.title.should eq "2312"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "creates relations" do
|
29
|
+
@book.link.should be_a NPR::Entity::Link
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Byline do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"id": "166481173",
|
8
|
+
"name": {
|
9
|
+
"$text": "Annalee Newitz"
|
10
|
+
}
|
11
|
+
}
|
12
|
+
JSON
|
13
|
+
end
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
@byline = NPR::Entity::Byline.new(@fixture)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets up attributes" do
|
20
|
+
@byline.id.should eq 166481173
|
21
|
+
@byline.name.should match /Annalee/
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Collection do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"type": "list",
|
8
|
+
"displayType": "Book",
|
9
|
+
"id": "166481178",
|
10
|
+
"title": {
|
11
|
+
"$text": "The Year's Best SF Crosses Galaxies And Genres"
|
12
|
+
},
|
13
|
+
"introText": {},
|
14
|
+
"member": [
|
15
|
+
{
|
16
|
+
"refId": "166481250",
|
17
|
+
"num": "1",
|
18
|
+
"label": "none"
|
19
|
+
},
|
20
|
+
{
|
21
|
+
"refId": "166481791",
|
22
|
+
"num": "2",
|
23
|
+
"label": "none"
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"refId": "166482564",
|
27
|
+
"num": "3",
|
28
|
+
"label": "none"
|
29
|
+
}
|
30
|
+
]
|
31
|
+
}
|
32
|
+
JSON
|
33
|
+
end
|
34
|
+
|
35
|
+
before :each do
|
36
|
+
@collection = NPR::Entity::Collection.new(@fixture)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Crop do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"type": "enlargement",
|
8
|
+
"src": "http://media.npr.org/assets/img/2012/12/14/121208bh0224-cb0bda2d8c5ec53151388f8a5faf3ddf12580434.jpg",
|
9
|
+
"height": "2000",
|
10
|
+
"width": "3000"
|
11
|
+
}
|
12
|
+
JSON
|
13
|
+
end
|
14
|
+
|
15
|
+
before :each do
|
16
|
+
@crop = NPR::Entity::Crop.new(@fixture)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sets attributes" do
|
20
|
+
@crop.type.should eq "enlargement"
|
21
|
+
@crop.src.should match /media\.npr/
|
22
|
+
@crop.height.should eq 2000
|
23
|
+
@crop.width.should eq 3000
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Enlargement do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"src": "http://media.npr.org/assets/img/2012/12/14/121208bh0224-cb0bda2d8c5ec53151388f8a5faf3ddf12580434.jpg",
|
8
|
+
"caption": {}
|
9
|
+
}
|
10
|
+
JSON
|
11
|
+
end
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
@enlargement = NPR::Entity::Enlargement.new(@fixture)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets attributes" do
|
18
|
+
@enlargement.src.should match /media\.npr/
|
19
|
+
@enlargement.caption.should eq ""
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Formats do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"mp3": [
|
8
|
+
{
|
9
|
+
"type": "mp3",
|
10
|
+
"$text": "http://pd.npr.org/anon.npr-mp3/npr/totn/2012/12/20121214_totn_01.mp3?orgId=1&topicId=1007&ft=3&f="
|
11
|
+
},
|
12
|
+
{
|
13
|
+
"type": "m3u",
|
14
|
+
"$text": "http://api.npr.org/m3u/1167255688-5265f3.m3u?orgId=1&topicId=1007&ft=3&f="
|
15
|
+
}
|
16
|
+
],
|
17
|
+
"wm": {
|
18
|
+
"$text": "http://www.npr.org/templates/dmg/dmg_wmref_em.php?id=167255688&type=1&mtype=WM&orgId=1&topicId=1007&ft=3&f="
|
19
|
+
},
|
20
|
+
"mediastream": {
|
21
|
+
"$text": "rtmp://flash.npr.org/ondemand/mp3:anon.npr-mp3/npr/totn/2012/12/20121214_totn_01.mp3"
|
22
|
+
}
|
23
|
+
}
|
24
|
+
JSON
|
25
|
+
end
|
26
|
+
|
27
|
+
before :each do
|
28
|
+
@formats = NPR::Entity::Formats.new(@fixture)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "sets up attributes" do
|
32
|
+
@formats.wm.should match /npr\.org/
|
33
|
+
@formats.rm.should eq nil
|
34
|
+
@formats.mediastream.should match /flash/
|
35
|
+
end
|
36
|
+
|
37
|
+
it "creates relations" do
|
38
|
+
@formats.mp3s.size.should eq 2
|
39
|
+
@formats.mp3s.first.should be_a NPR::Entity::MP3
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Image do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"id": "167273389",
|
8
|
+
"type": "standard",
|
9
|
+
"width": "200",
|
10
|
+
"src": "http://media.npr.org/assets/img/2012/12/14/121208bh0224-cb0bda2d8c5ec53151388f8a5faf3ddf12580434.jpg?s=12",
|
11
|
+
"hasBorder": "false",
|
12
|
+
"title": {
|
13
|
+
"$text": "Jason Moran chats with Geri Allen on stage."
|
14
|
+
},
|
15
|
+
"caption": {
|
16
|
+
"$text": "Jason Moran chats with Geri Allen on stage."
|
17
|
+
},
|
18
|
+
"link": {
|
19
|
+
"url": ""
|
20
|
+
},
|
21
|
+
"producer": {},
|
22
|
+
"provider": {
|
23
|
+
"url": "",
|
24
|
+
"$text": "Brendan Hoffman for NPR"
|
25
|
+
},
|
26
|
+
"copyright": {},
|
27
|
+
"enlargement": {
|
28
|
+
"src": "http://media.npr.org/assets/img/2012/12/14/121208bh0224-cb0bda2d8c5ec53151388f8a5faf3ddf12580434.jpg",
|
29
|
+
"caption": {}
|
30
|
+
},
|
31
|
+
"crop": [
|
32
|
+
{
|
33
|
+
"type": "enlargement",
|
34
|
+
"src": "http://media.npr.org/assets/img/2012/12/14/121208bh0224-cb0bda2d8c5ec53151388f8a5faf3ddf12580434.jpg",
|
35
|
+
"height": "2000",
|
36
|
+
"width": "3000"
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"type": "slide",
|
40
|
+
"src": "http://media.npr.org/assets/img/2012/12/14/121208bh0224-cb0bda2d8c5ec53151388f8a5faf3ddf12580434.jpg",
|
41
|
+
"height": "2000",
|
42
|
+
"width": "3000"
|
43
|
+
}
|
44
|
+
]
|
45
|
+
}
|
46
|
+
JSON
|
47
|
+
end
|
48
|
+
|
49
|
+
before :each do
|
50
|
+
@image = NPR::Entity::Image.new(@fixture)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "sets attributes" do
|
54
|
+
@image.id.should eq 167273389
|
55
|
+
@image.type.should eq "standard"
|
56
|
+
@image.width.should eq 200
|
57
|
+
@image.src.should match /media\.npr/
|
58
|
+
@image.hasBorder.should eq false
|
59
|
+
@image.link.should eq ""
|
60
|
+
end
|
61
|
+
|
62
|
+
it "sets enlargement" do
|
63
|
+
@image.enlargement.should be_a NPR::Entity::Enlargement
|
64
|
+
end
|
65
|
+
|
66
|
+
it "sets provider" do
|
67
|
+
@image.provider.url.should eq ""
|
68
|
+
@image.provider.to_s.should match /Brendan./
|
69
|
+
end
|
70
|
+
|
71
|
+
it "sets crops" do
|
72
|
+
@image.crops.size.should eq 2
|
73
|
+
@image.crops.first.should be_a NPR::Entity::Crop
|
74
|
+
end
|
75
|
+
|
76
|
+
it "sets shallow attributes" do
|
77
|
+
@image.title.should match /Jason/
|
78
|
+
@image.caption.should match /Geri/
|
79
|
+
@image.producer.should eq ""
|
80
|
+
@image.copyright.should eq ""
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::IntroText do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"num": "5",
|
8
|
+
"$text": "<p>A sweeping space opera, <em>2312</em> is about what happens to humanity once we've truly conquered the solar system. Humans have colonized most of the planets and moons in our local volume of space, and it's the end of an interplanetary age of exploration. Political powers are consolidating their territories.</p>"
|
9
|
+
}
|
10
|
+
JSON
|
11
|
+
end
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
@intro_text = NPR::Entity::IntroText.new(@fixture)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets attributes" do
|
18
|
+
@intro_text.num.should eq 5
|
19
|
+
@intro_text.content.should match /sweeping space opera/
|
20
|
+
end
|
21
|
+
|
22
|
+
it "uses @content for to_s" do
|
23
|
+
@intro_text.to_s.should eq @intro_text.content
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Link do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"type": "html",
|
8
|
+
"$text": "http://www.npr.org/blogs/thetwo-way/2012/12/11/167019068/sitar-virtuoso-ravi-shankar-dies-at-92?ft=3&f=167019577"
|
9
|
+
}
|
10
|
+
JSON
|
11
|
+
end
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
@link = NPR::Entity::Link.new(@fixture)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets attributes" do
|
18
|
+
@link.type.should eq "html"
|
19
|
+
@link.content.should match /npr\.org/
|
20
|
+
end
|
21
|
+
|
22
|
+
it "uses @content for to_s" do
|
23
|
+
@link.to_s.should match /npr\.org/
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::List do
|
4
|
+
before :each do
|
5
|
+
response = mock_response "json/01_story_full_media.json" do
|
6
|
+
NPR::API::Client.new(:apiKey => "key").query(:id => 999)
|
7
|
+
end
|
8
|
+
|
9
|
+
@list = response.list
|
10
|
+
end
|
11
|
+
|
12
|
+
it "extracts the attributes" do
|
13
|
+
@list.title.should match /NPR/
|
14
|
+
@list.teaser.should match /NPR/
|
15
|
+
@list.miniTeaser.should match /NPR/
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sets up relations" do
|
19
|
+
@list.links.size.should eq 2
|
20
|
+
@list.stories.size.should eq 1
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::ListText do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"id": "166558361",
|
8
|
+
"tag": "p",
|
9
|
+
"paragraph": [
|
10
|
+
{
|
11
|
+
"num": "1",
|
12
|
+
"$text": "<em>Annalee Newitz writes about the intersection of science and culture.</em>"
|
13
|
+
}
|
14
|
+
]
|
15
|
+
}
|
16
|
+
JSON
|
17
|
+
end
|
18
|
+
|
19
|
+
before :each do
|
20
|
+
@list_text = NPR::Entity::ListText.new(@fixture)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "sets up attributes" do
|
24
|
+
@list_text.id.should eq 166558361
|
25
|
+
@list_text.tag.should eq "p"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "sets up relations" do
|
29
|
+
@list_text.paragraphs.first.should be_a NPR::Entity::Paragraph
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::MemberByline do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"refId": "166481286",
|
8
|
+
"num": "6"
|
9
|
+
}
|
10
|
+
JSON
|
11
|
+
end
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
@member_byline = NPR::Entity::MemberByline.new(@fixture)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets attributes" do
|
18
|
+
@member_byline.refId.should eq 166481286
|
19
|
+
@member_byline.num.should eq 6
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::MemberPromoArt do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"refId": "153611356",
|
8
|
+
"num": "1"
|
9
|
+
}
|
10
|
+
JSON
|
11
|
+
end
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
@member_promo_art = NPR::Entity::MemberPromoArt.new(@fixture)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets attributes" do
|
18
|
+
@member_promo_art.refId.should eq 153611356
|
19
|
+
@member_promo_art.num.should eq 1
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::Member do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"id": "166481250",
|
8
|
+
"promoArt": {
|
9
|
+
"refId": "153611356",
|
10
|
+
"num": "1"
|
11
|
+
},
|
12
|
+
"title": {
|
13
|
+
"num": "2",
|
14
|
+
"$text": "2312"
|
15
|
+
},
|
16
|
+
"author": {
|
17
|
+
"id": "139197905",
|
18
|
+
"num": "3",
|
19
|
+
"title": {
|
20
|
+
"$text": "Kim Stanley Robinson"
|
21
|
+
},
|
22
|
+
"link": {
|
23
|
+
"type": "api",
|
24
|
+
"$text": "http://api.npr.org/query?id=139197905&apiKey=MDA1OTI3MjQ5MDEyODUwMTE2MzM1YzNmZA004"
|
25
|
+
}
|
26
|
+
},
|
27
|
+
"bookEdition": {
|
28
|
+
"refId": "153611349",
|
29
|
+
"num": "4"
|
30
|
+
},
|
31
|
+
"introText": {
|
32
|
+
"num": "5",
|
33
|
+
"$text": "<p>A sweeping space opera, <em>2312</em> is about what happens to humanity once we've truly conquered the solar system. Humans have colonized most of the planets and moons in our local volume of space, and it's the end of an interplanetary age of exploration. Political powers are consolidating their territories.</p>"
|
34
|
+
},
|
35
|
+
"byline": {
|
36
|
+
"refId": "166481286",
|
37
|
+
"num": "6"
|
38
|
+
}
|
39
|
+
}
|
40
|
+
JSON
|
41
|
+
end
|
42
|
+
|
43
|
+
before :each do
|
44
|
+
@member = NPR::Entity::Member.new(@fixture)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "sets up attributes" do
|
48
|
+
@member.id.should eq 166481250
|
49
|
+
end
|
50
|
+
|
51
|
+
it "sets up relations" do
|
52
|
+
@member.promoArt.should be_a NPR::Entity::MemberPromoArt
|
53
|
+
@member.title.should be_a NPR::Entity::Title
|
54
|
+
@member.author.should be_a NPR::Entity::Author
|
55
|
+
@member.bookEdition.should be_a NPR::Entity::PromoArtBookEdition
|
56
|
+
@member.introText.should be_a NPR::Entity::IntroText
|
57
|
+
@member.byline.should be_a NPR::Entity::MemberByline
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe NPR::Entity::MP3 do
|
4
|
+
json_fixture do
|
5
|
+
<<-JSON
|
6
|
+
{
|
7
|
+
"type": "mp3",
|
8
|
+
"$text": "http://pd.npr.org/anon.npr-mp3/npr/totn/2012/12/20121214_totn_01.mp3?orgId=1&topicId=1007&ft=3&f="
|
9
|
+
}
|
10
|
+
JSON
|
11
|
+
end
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
@mp3 = NPR::Entity::MP3.new(@fixture)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "sets attributes" do
|
18
|
+
@mp3.type.should eq "mp3"
|
19
|
+
@mp3.content.should match /pd\.npr/
|
20
|
+
end
|
21
|
+
|
22
|
+
it "uses @content for #to_s" do
|
23
|
+
@mp3.to_s.should eq @mp3.content
|
24
|
+
end
|
25
|
+
end
|