npr 0.1.2 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -5
- data/CHANGELOG.md +17 -4
- data/README.md +1 -16
- data/lib/npr/api/client.rb +14 -10
- data/lib/npr/api/query_builder.rb +1 -5
- data/lib/npr/api/response.rb +1 -1
- data/lib/npr/entity/crop.rb +0 -1
- data/lib/npr/entity/enlargement.rb +0 -2
- data/lib/npr/entity/formats.rb +1 -1
- data/lib/npr/entity/image.rb +30 -8
- data/lib/npr/entity/intro_text.rb +1 -1
- data/lib/npr/entity/link.rb +1 -1
- data/lib/npr/entity/mp3.rb +1 -1
- data/lib/npr/entity/name.rb +1 -1
- data/lib/npr/entity/paragraph.rb +1 -1
- data/lib/npr/entity/program.rb +1 -1
- data/lib/npr/entity/provider.rb +1 -1
- data/lib/npr/entity/story.rb +17 -10
- data/lib/npr/entity/text.rb +19 -0
- data/lib/npr/entity/title.rb +1 -1
- data/lib/npr/errors.rb +6 -6
- data/lib/npr/version.rb +1 -1
- data/npr.gemspec +19 -19
- data/spec/fixtures/json/01_story_full_media.json +520 -1
- data/spec/fixtures/json/02_story_multiple_images.json +561 -1
- data/spec/fixtures/json/03_no_results.json +36 -1
- data/spec/fixtures/json/04_invalid_id.json +3791 -1
- data/spec/fixtures/json/05_no_api_key.json +15 -1
- data/spec/fixtures/json/06_story_multiple_ids.json +1190 -1
- data/spec/support/fake_response.rb +6 -5
- data/spec/unit/api/client_spec.rb +35 -12
- data/spec/unit/entity/image_spec.rb +10 -0
- data/spec/unit/entity/story_spec.rb +1 -1
- data/spec/unit/entity/text_spec.rb +8 -0
- metadata +9 -4
- data/gemfiles/Gemfile.rb-1.8.7 +0 -6
@@ -29,10 +29,11 @@ module FakeResponse
|
|
29
29
|
# response body to the contents of the requested file.
|
30
30
|
def respond_with(filename, options)
|
31
31
|
content_type = options[:content_type] || "application/json"
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
{
|
32
|
+
uri = options.delete(:uri) || %r{^#{NPR::Configuration::API_ROOT}}
|
33
|
+
|
34
|
+
FakeWeb.register_uri(:get, uri,
|
35
|
+
{
|
36
|
+
:body => load_fixture(filename),
|
36
37
|
:content_type => content_type
|
37
38
|
}.merge(options))
|
38
39
|
end
|
@@ -47,7 +48,7 @@ module FakeResponse
|
|
47
48
|
#---------------------
|
48
49
|
# Select a random response fixture
|
49
50
|
def random_filename
|
50
|
-
filename = Dir["#{FIXTURE_ROOT}/**/*story
|
51
|
+
filename = Dir["#{FIXTURE_ROOT}/**/*story*.*"].sample
|
51
52
|
puts "Responding with #{filename}"
|
52
53
|
filename
|
53
54
|
end
|
@@ -8,6 +8,17 @@ describe NPR::API::Client do
|
|
8
8
|
client.params.keys.should_not include :apiKey
|
9
9
|
end
|
10
10
|
|
11
|
+
it "sets @url on initialize" do
|
12
|
+
client = NPR::API::Client.new(:url => "http://api.publish2.com")
|
13
|
+
client.url.should eq "http://api.publish2.com"
|
14
|
+
client.params.keys.should_not include :url
|
15
|
+
end
|
16
|
+
|
17
|
+
it "falls back to default NPR API root if URL not passed in" do
|
18
|
+
client = NPR::API::Client.new
|
19
|
+
client.url.should eq NPR::Configuration::API_ROOT
|
20
|
+
end
|
21
|
+
|
11
22
|
it "uses global config" do
|
12
23
|
NPR.config.sort = "super sort"
|
13
24
|
client = NPR::API::Client.new
|
@@ -24,19 +35,31 @@ describe NPR::API::Client do
|
|
24
35
|
#-----------------
|
25
36
|
|
26
37
|
describe "#query" do
|
27
|
-
it
|
28
|
-
|
29
|
-
|
38
|
+
it 'uses the passed-in path if available' do
|
39
|
+
respond_with("json/01_story_full_media.json", :uri => %r|api\.publish2\.com/list/stories|)
|
40
|
+
|
41
|
+
client = NPR::API::Client.new(:apiKey => "key", :url => "http://api.publish2.com")
|
42
|
+
|
43
|
+
# If this fails, it should be caught by FakeWeb.allow_net_connect = false
|
44
|
+
response = client.query(:path => "/list/stories")
|
45
|
+
# But just incase...
|
46
|
+
response.instance_variable_get(:@_response).env[:url].to_s.should match %r|api\.publish2\.com/list/stories|
|
30
47
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
48
|
+
|
49
|
+
it 'returns an API::Response when the API call is a success' do
|
50
|
+
respond_with("json/01_story_full_media.json", :uri => %r|api\.npr\.org|)
|
51
|
+
client = NPR::API::Client.new(:apiKey => "key")
|
52
|
+
|
53
|
+
client.query(:path => "/list/stories").should be_a NPR::API::Response
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'raises NPR::ServerError when the response is not a success' do
|
57
|
+
FakeWeb.register_uri(:get, %r|api\.npr\.org|, :status => ["400", "Bad Request"], :body => nil)
|
58
|
+
client = NPR::API::Client.new(:apiKey => "key")
|
59
|
+
|
60
|
+
lambda {
|
61
|
+
client.query(:path => "/list/stories")
|
62
|
+
}.should raise_error NPR::APIError
|
35
63
|
end
|
36
|
-
|
37
|
-
context "json" do
|
38
|
-
it "returns a result in hash format" do
|
39
|
-
end
|
40
|
-
end
|
41
64
|
end
|
42
65
|
end
|
@@ -84,4 +84,14 @@ describe NPR::Entity::Image do
|
|
84
84
|
@image.primary?.should eq false
|
85
85
|
@image.standard?.should eq true
|
86
86
|
end
|
87
|
+
|
88
|
+
it 'finds the crop by its type' do
|
89
|
+
crop = @image.crop("enlargement")
|
90
|
+
crop.should be_a NPR::Entity::Crop
|
91
|
+
crop.type.should eq 'enlargement'
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'returns nil for crop if the type does not exist' do
|
95
|
+
@image.crop("doesntexist").should eq nil
|
96
|
+
end
|
87
97
|
end
|
@@ -182,7 +182,7 @@ describe NPR::Entity::Story do
|
|
182
182
|
end
|
183
183
|
|
184
184
|
it "finds the link for the passed-in type if it exists" do
|
185
|
-
@story.link_for("html").should
|
185
|
+
@story.link_for("html").should match /^http:\/\//
|
186
186
|
end
|
187
187
|
|
188
188
|
it "is nil if the type isn't present" do
|
@@ -51,4 +51,12 @@ describe NPR::Entity::Text do
|
|
51
51
|
s.should match /Amtrak trains\.$/
|
52
52
|
s.should match /\n/
|
53
53
|
end
|
54
|
+
|
55
|
+
it "wraps each paragraph in p tags for #to_html" do
|
56
|
+
s = @text.to_html
|
57
|
+
s.should match /\A\<p\>/
|
58
|
+
s.should match /\<\/p\>\n\z/
|
59
|
+
s.should match /^\<p\>/
|
60
|
+
s.should match /\<\/p\>$/
|
61
|
+
end
|
54
62
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: npr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
@@ -122,7 +122,6 @@ files:
|
|
122
122
|
- MIT-LICENSE
|
123
123
|
- README.md
|
124
124
|
- Rakefile
|
125
|
-
- gemfiles/Gemfile.rb-1.8.7
|
126
125
|
- lib/npr.rb
|
127
126
|
- lib/npr/api.rb
|
128
127
|
- lib/npr/api/client.rb
|
@@ -281,15 +280,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
281
280
|
- - ! '>='
|
282
281
|
- !ruby/object:Gem::Version
|
283
282
|
version: '0'
|
283
|
+
segments:
|
284
|
+
- 0
|
285
|
+
hash: 1451142622533907369
|
284
286
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
285
287
|
none: false
|
286
288
|
requirements:
|
287
289
|
- - ! '>='
|
288
290
|
- !ruby/object:Gem::Version
|
289
291
|
version: '0'
|
292
|
+
segments:
|
293
|
+
- 0
|
294
|
+
hash: 1451142622533907369
|
290
295
|
requirements: []
|
291
296
|
rubyforge_project:
|
292
|
-
rubygems_version: 1.8.
|
297
|
+
rubygems_version: 1.8.25
|
293
298
|
signing_key:
|
294
299
|
specification_version: 3
|
295
300
|
summary: A Ruby client for the NPR API
|