npr 1.2.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ### Version 2.0.0 (2013-11-08)
2
+ ##### Additions
3
+ * Added `NPR::Entity::Stream`.
4
+ * Added `empty?` method to `NPR::Entity::Formats`. Since `audio.formats` isn't
5
+ actually an Enumerable, this method is defined to make it easy to check if
6
+ any formats have been provided for this audio. This is a good way to check
7
+ if the audio is actually available yet.
8
+
9
+ ##### Changes
10
+ * `Audio#stream` now returns an `NPR::Entity::Stream` object. This will break
11
+ your code if you were doing something like `if audio.stream == true`.
12
+ To fix it, you can just use: `if audio.stream.active?`.
13
+ * Changed the `offset` method on `QueryBuilder` to set `startNum` to
14
+ `offset + 1`. Previously, if you said `.offset(1)`, you would actually still
15
+ get the first result, because it was passing its value directly to the
16
+ `startNum` parameter, which is confusing. Now you can say `.offset(1)` and
17
+ the results will actually be offset by 1 object. This behavior is to mimic
18
+ ActiveRecord a little more closely.
19
+
20
+ ##### Deprecations
21
+ * None
22
+
23
+
1
24
  ### Version 1.2.0 (2013-08-05)
2
25
  ##### Additions
3
26
  * Added support for the `parent` node.
data/README.md CHANGED
@@ -115,8 +115,6 @@ for all of the options.
115
115
 
116
116
  ## Contributing
117
117
 
118
- 1. Fork it
119
- 2. Create your feature branch (`git checkout -b my-new-feature`)
120
- 3. Commit your changes (`git commit -am 'Added some feature'`)
121
- 4. Push to the branch (`git push origin my-new-feature`)
122
- 5. Create new Pull Request
118
+ Please send PR's for any new features or bug fixes!
119
+
120
+ Run tests with `bundle exec rake test`.
@@ -33,10 +33,10 @@ module NPR
33
33
  end
34
34
 
35
35
  params = conditions || {}
36
- params[:sort] = @builder[:order] if @builder[:order]
37
- params[:numResults] = @builder[:limit] if @builder[:limit]
38
- params[:startNum] = @builder[:offset] if @builder[:offset]
39
- params.merge!(@builder[:extra]) if @builder[:extra]
36
+ params[:sort] = @builder[:order] if @builder[:order]
37
+ params[:numResults] = @builder[:limit] if @builder[:limit]
38
+ params[:startNum] = @builder[:offset] + 1 if @builder[:offset]
39
+ params.merge!(@builder[:extra]) if @builder[:extra]
40
40
 
41
41
  params
42
42
  end
@@ -4,21 +4,18 @@
4
4
  module NPR
5
5
  module Entity
6
6
  class Audio < Base
7
- attr_accessor :id, :type, :stream
7
+ attr_accessor :id, :type
8
8
  shallow_attribute "title", "duration", "description", "rightsHolder"
9
9
  has_one "permissions", :class_name => NPR::Entity::Permissions
10
10
  has_one "formats", :key => "format", :class_name => NPR::Entity::Formats
11
+ has_one "stream", :class_name => NPR::Entity::Stream
11
12
 
12
13
  #-------------------
13
- # +stream+ returns true if "active" is set to "true"
14
+
14
15
  def initialize(json)
15
16
  @id = json["id"].to_i
16
17
  @type = json["type"]
17
18
 
18
- if json["stream"]
19
- @stream = json["stream"]["active"] == "true"
20
- end
21
-
22
19
  create_relations(json)
23
20
  extract_shallow_attributes(json)
24
21
  end
@@ -14,6 +14,13 @@ module NPR
14
14
  extract_shallow_attributes(json)
15
15
  create_relations(json)
16
16
  end
17
+
18
+ def empty?
19
+ mp3s.empty? &&
20
+ !wm &&
21
+ !rm &&
22
+ !mediastream
23
+ end
17
24
  end # Formats
18
25
  end # Entity
19
26
  end # NPR
@@ -103,7 +103,7 @@ module NPR
103
103
 
104
104
  #------------------
105
105
 
106
- shallow_attribute(
106
+ shallow_attribute \
107
107
  "title",
108
108
  "partnerId",
109
109
  "subtitle",
@@ -117,7 +117,6 @@ module NPR
117
117
  "keywords",
118
118
  "priorityKeywords",
119
119
  "fullText"
120
- )
121
120
 
122
121
  #-------------------------
123
122
 
@@ -0,0 +1,16 @@
1
+ ##
2
+ # NPR::Entity::Stream
3
+ module NPR
4
+ module Entity
5
+ class Stream < Base
6
+ attr_accessor :active
7
+ alias_method :active?, :active
8
+
9
+ #-------------------
10
+
11
+ def initialize(json)
12
+ @active = json["active"] == "true"
13
+ end
14
+ end # Name
15
+ end # Entity
16
+ end # NPR
data/lib/npr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module NPR
2
- VERSION = "1.2.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/npr.rb CHANGED
@@ -58,6 +58,7 @@ require "npr/entity/promo_art"
58
58
  require "npr/entity/mp3"
59
59
  require "npr/entity/formats"
60
60
  require "npr/entity/permissions"
61
+ require "npr/entity/stream"
61
62
  require "npr/entity/audio"
62
63
  require "npr/entity/book"
63
64
  require "npr/entity/book_edition"
data/npr.gemspec CHANGED
@@ -6,17 +6,21 @@ Gem::Specification.new do |s|
6
6
  s.version = NPR::VERSION
7
7
  s.authors = ["Bryan Ricker"]
8
8
  s.email = ["bricker@scpr.org"]
9
- s.description = %q{NPR (npr.org) is a news organization. This gem helps you pull NPR content with a nice Ruby DSL.}
9
+ s.description = "NPR (npr.org) is a news organization. " \
10
+ "This gem helps you pull NPR content with a nice Ruby DSL."
10
11
  s.summary = %q{A Ruby client for the NPR API}
11
12
  s.homepage = "http://github.com/bricker/npr"
12
13
 
13
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f|
15
+ File.basename(f)
16
+ }
17
+
14
18
  s.files = `git ls-files`.split("\n")
15
19
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
20
  s.require_paths = ["lib"]
17
-
21
+
18
22
  s.licenses = ['MIT']
19
-
23
+
20
24
  s.add_dependency 'faraday', '>= 0.8.0'
21
25
  s.add_dependency 'faraday_middleware', '>= 0.9.0'
22
26
 
@@ -7,33 +7,33 @@ module ConfigHelper
7
7
  end
8
8
 
9
9
  #------------------
10
-
10
+
11
11
  def config(options)
12
12
  @_config_reset = NPR.config
13
13
  NPR.config.merge(options)
14
14
  end
15
15
 
16
16
  #------------------
17
-
17
+
18
18
  def reset_config
19
19
  NPR.instance_variable_set(:@config, @_config_reset)
20
20
  end
21
-
21
+
22
22
  #------------------
23
-
23
+
24
24
  def config!(options)
25
25
  config = NPR::Configuration.new(options)
26
26
  NPR.instance_variable_set(:@config, config)
27
27
  end
28
-
28
+
29
29
  #------------------
30
-
30
+
31
31
  def clear_config
32
32
  NPR.instance_variable_set(:@config, nil)
33
33
  end
34
-
34
+
35
35
  #------------------
36
-
36
+
37
37
  module ClassMethods
38
38
  # Merge the options into whatever the config
39
39
  # currently is, and reset it to its previous
@@ -42,12 +42,12 @@ module ConfigHelper
42
42
  before :all do
43
43
  config(options)
44
44
  end
45
-
45
+
46
46
  after :all do
47
47
  reset_config
48
48
  end
49
49
  end
50
-
50
+
51
51
  #--------------------
52
52
  # Set the config to ONLY the provided options,
53
53
  # and set to nil after.
@@ -55,7 +55,7 @@ module ConfigHelper
55
55
  before :all do
56
56
  config!(options)
57
57
  end
58
-
58
+
59
59
  after :all do
60
60
  reset_config
61
61
  end
@@ -6,7 +6,7 @@
6
6
  module FakeResponse
7
7
  #---------------------
8
8
  # Takes the filename to respond with,
9
- # and (optionally) any options to be passed to
9
+ # and (optionally) any options to be passed to
10
10
  # +FakeWeb.register_uri+.
11
11
  #
12
12
  # If no block is given, the registry will not be cleaned
@@ -17,34 +17,34 @@ module FakeResponse
17
17
  #
18
18
  def mock_response(filename, options={}, &block)
19
19
  respond_with(filename, options)
20
-
20
+
21
21
  response = yield
22
22
  FakeWeb.clean_registry
23
-
23
+
24
24
  response
25
25
  end
26
26
 
27
27
  #---------------------
28
- # Register the NPR root with FakeWeb, and set its
28
+ # Register the NPR root with FakeWeb, and set its
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
32
  uri = options.delete(:uri) || %r{^#{NPR::Configuration::API_ROOT}}
33
33
 
34
- FakeWeb.register_uri(:get, uri,
35
- {
34
+ FakeWeb.register_uri(:get, uri,
35
+ {
36
36
  :body => load_fixture(filename),
37
37
  :content_type => content_type
38
38
  }.merge(options))
39
39
  end
40
-
40
+
41
41
  #---------------------
42
42
  # Read a fixure file
43
43
  def load_fixture(filename)
44
44
  file = filename == :random ? random_filename : filename
45
45
  File.read(File.join FIXTURE_ROOT, file)
46
46
  end
47
-
47
+
48
48
  #---------------------
49
49
  # Select a random response fixture
50
50
  def random_filename
@@ -7,14 +7,14 @@ module FixtureHelper
7
7
  def self.included(base)
8
8
  base.extend ClassMethods
9
9
  end
10
-
10
+
11
11
  module ClassMethods
12
12
  def json_fixture(&block)
13
13
  before :all do
14
14
  @json = yield
15
15
  @fixture = JSON.parse(@json)
16
16
  end
17
-
17
+
18
18
  after :all do
19
19
  @json, @fixture = nil, nil
20
20
  end
@@ -12,7 +12,7 @@ describe NPR::API::QueryBuilder do
12
12
  :id => 5 ,
13
13
  :sort => "date descending",
14
14
  :numResults => 10,
15
- :startNum => 100
15
+ :startNum => 101
16
16
  ]
17
17
  end
18
18
 
@@ -173,6 +173,11 @@ describe NPR::API::QueryBuilder do
173
173
  it "returns itself" do
174
174
  @builder.offset(0).should eq @builder
175
175
  end
176
+
177
+ it "sets the startNum to value + 1" do
178
+ @builder.offset(100)
179
+ @builder.to_params[:startNum].should eq 101
180
+ end
176
181
  end
177
182
 
178
183
  #----------------------
@@ -66,7 +66,7 @@ describe NPR::Entity::Audio do
66
66
  end
67
67
 
68
68
  it "sets stream" do
69
- @audio.stream.should eq false
69
+ @audio.stream.should be_a NPR::Entity::Stream
70
70
  end
71
71
 
72
72
  it "sets format" do
@@ -38,4 +38,9 @@ describe NPR::Entity::Formats do
38
38
  @formats.mp3s.size.should eq 2
39
39
  @formats.mp3s.first.should be_a NPR::Entity::MP3
40
40
  end
41
+
42
+ it 'blank? is true if JSON was empty' do
43
+ formats = NPR::Entity::Formats.new(JSON.parse("{}"))
44
+ formats.empty?.should eq true
45
+ end
41
46
  end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe NPR::Entity::Name do
4
+ json_fixture do
5
+ <<-JSON
6
+ {
7
+ "active": "true"
8
+ }
9
+ JSON
10
+ end
11
+
12
+ before :each do
13
+ @stream = NPR::Entity::Stream.new(@fixture)
14
+ end
15
+
16
+ it "sets attributes" do
17
+ @stream.active.should eq true
18
+ @stream.active?.should eq true
19
+ end
20
+ 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: 1.2.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-05 00:00:00.000000000 Z
12
+ date: 2013-11-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70249174674460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: 0.8.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: 0.8.0
24
+ version_requirements: *70249174674460
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: faraday_middleware
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70249174673960 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,15 +32,10 @@ dependencies:
37
32
  version: 0.9.0
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: 0.9.0
35
+ version_requirements: *70249174673960
46
36
  - !ruby/object:Gem::Dependency
47
37
  name: bundler
48
- requirement: !ruby/object:Gem::Requirement
38
+ requirement: &70249174660180 !ruby/object:Gem::Requirement
49
39
  none: false
50
40
  requirements:
51
41
  - - ! '>='
@@ -53,15 +43,10 @@ dependencies:
53
43
  version: 1.0.0
54
44
  type: :development
55
45
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: 1.0.0
46
+ version_requirements: *70249174660180
62
47
  - !ruby/object:Gem::Dependency
63
48
  name: rake
64
- requirement: !ruby/object:Gem::Requirement
49
+ requirement: &70249174659800 !ruby/object:Gem::Requirement
65
50
  none: false
66
51
  requirements:
67
52
  - - ! '>='
@@ -69,15 +54,10 @@ dependencies:
69
54
  version: '0'
70
55
  type: :development
71
56
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
57
+ version_requirements: *70249174659800
78
58
  - !ruby/object:Gem::Dependency
79
59
  name: rspec
80
- requirement: !ruby/object:Gem::Requirement
60
+ requirement: &70249174659340 !ruby/object:Gem::Requirement
81
61
  none: false
82
62
  requirements:
83
63
  - - ! '>='
@@ -85,15 +65,10 @@ dependencies:
85
65
  version: '0'
86
66
  type: :development
87
67
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
68
+ version_requirements: *70249174659340
94
69
  - !ruby/object:Gem::Dependency
95
70
  name: fakeweb
96
- requirement: !ruby/object:Gem::Requirement
71
+ requirement: &70249174658920 !ruby/object:Gem::Requirement
97
72
  none: false
98
73
  requirements:
99
74
  - - ! '>='
@@ -101,12 +76,7 @@ dependencies:
101
76
  version: '0'
102
77
  type: :development
103
78
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
79
+ version_requirements: *70249174658920
110
80
  description: NPR (npr.org) is a news organization. This gem helps you pull NPR content
111
81
  with a nice Ruby DSL.
112
82
  email:
@@ -169,6 +139,7 @@ files:
169
139
  - lib/npr/entity/related_link.rb
170
140
  - lib/npr/entity/show.rb
171
141
  - lib/npr/entity/story.rb
142
+ - lib/npr/entity/stream.rb
172
143
  - lib/npr/entity/text.rb
173
144
  - lib/npr/entity/title.rb
174
145
  - lib/npr/entity/transcript.rb
@@ -269,6 +240,7 @@ files:
269
240
  - spec/unit/entity/related_link_spec.rb
270
241
  - spec/unit/entity/show_spec.rb
271
242
  - spec/unit/entity/story_spec.rb
243
+ - spec/unit/entity/stream_spec.rb
272
244
  - spec/unit/entity/text_spec.rb
273
245
  - spec/unit/entity/title_spec.rb
274
246
  - spec/unit/entity/transcript_spec.rb
@@ -293,7 +265,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
293
265
  version: '0'
294
266
  requirements: []
295
267
  rubyforge_project:
296
- rubygems_version: 1.8.25
268
+ rubygems_version: 1.8.11
297
269
  signing_key:
298
270
  specification_version: 3
299
271
  summary: A Ruby client for the NPR API
@@ -392,7 +364,7 @@ test_files:
392
364
  - spec/unit/entity/related_link_spec.rb
393
365
  - spec/unit/entity/show_spec.rb
394
366
  - spec/unit/entity/story_spec.rb
367
+ - spec/unit/entity/stream_spec.rb
395
368
  - spec/unit/entity/text_spec.rb
396
369
  - spec/unit/entity/title_spec.rb
397
370
  - spec/unit/entity/transcript_spec.rb
398
- has_rdoc: