npr 0.1.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
- FakeWeb.register_uri(:get,
34
- %r{^#{NPR::Configuration::API_ROOT}},
35
- { :body => load_fixture(filename),
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*.rb"].sample
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 "raises NotConfiguredError if apiKey is blank" do
28
- client = NPR::API::Client.new
29
- lambda { client.query }.should raise_error NPR::NotConfiguredError
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
- context "nprml" do
33
- it "returns a result in hash format" do
34
- end
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 be_a NPR::Entity::Link
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: 0.1.2
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: 2012-12-30 00:00:00.000000000 Z
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.24
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
@@ -1,6 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in npr.gemspec
4
- gemspec :path => "../"
5
-
6
- gem 'json', '~> 1.7.5'