npr 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. data/.travis.yml +1 -4
  2. data/CHANGELOG.md +27 -1
  3. data/README.md +5 -10
  4. data/lib/npr/api/client.rb +6 -6
  5. data/lib/npr/api/message.rb +5 -5
  6. data/lib/npr/api/query_builder.rb +22 -23
  7. data/lib/npr/api/response.rb +7 -7
  8. data/lib/npr/concern/attr_typecast.rb +11 -13
  9. data/lib/npr/concern/links_association.rb +26 -0
  10. data/lib/npr/concern/relation.rb +17 -17
  11. data/lib/npr/concern/shallow_attributes.rb +12 -12
  12. data/lib/npr/configuration.rb +27 -27
  13. data/lib/npr/entity/audio.rb +3 -4
  14. data/lib/npr/entity/author.rb +3 -3
  15. data/lib/npr/entity/base.rb +1 -1
  16. data/lib/npr/entity/book.rb +2 -2
  17. data/lib/npr/entity/book_edition.rb +5 -5
  18. data/lib/npr/entity/byline.rb +4 -3
  19. data/lib/npr/entity/crop.rb +2 -2
  20. data/lib/npr/entity/enlargement.rb +2 -2
  21. data/lib/npr/entity/external_asset.rb +27 -0
  22. data/lib/npr/entity/formats.rb +2 -2
  23. data/lib/npr/entity/image.rb +4 -4
  24. data/lib/npr/entity/intro_text.rb +4 -4
  25. data/lib/npr/entity/link.rb +3 -3
  26. data/lib/npr/entity/list.rb +2 -4
  27. data/lib/npr/entity/list_text.rb +2 -2
  28. data/lib/npr/entity/member.rb +1 -1
  29. data/lib/npr/entity/member_byline.rb +2 -2
  30. data/lib/npr/entity/member_promo_art.rb +2 -2
  31. data/lib/npr/entity/mp3.rb +4 -4
  32. data/lib/npr/entity/name.rb +4 -4
  33. data/lib/npr/entity/organization.rb +2 -2
  34. data/lib/npr/entity/paragraph.rb +2 -2
  35. data/lib/npr/entity/parent.rb +23 -0
  36. data/lib/npr/entity/permissions.rb +14 -1
  37. data/lib/npr/entity/program.rb +7 -5
  38. data/lib/npr/entity/promo_art.rb +2 -2
  39. data/lib/npr/entity/promo_art_book_edition.rb +2 -3
  40. data/lib/npr/entity/provider.rb +4 -4
  41. data/lib/npr/entity/pull_quote.rb +1 -1
  42. data/lib/npr/entity/related_link.rb +4 -4
  43. data/lib/npr/entity/show.rb +3 -3
  44. data/lib/npr/entity/story.rb +42 -72
  45. data/lib/npr/entity/text.rb +7 -7
  46. data/lib/npr/entity/title.rb +4 -4
  47. data/lib/npr/entity/transcript.rb +2 -2
  48. data/lib/npr/errors.rb +1 -1
  49. data/lib/npr/version.rb +1 -1
  50. data/lib/npr.rb +3 -0
  51. data/spec/fixtures/fetch_formats.rb +4 -4
  52. data/spec/spec_helper.rb +1 -1
  53. data/spec/unit/api/client_spec.rb +4 -4
  54. data/spec/unit/api/message_spec.rb +9 -9
  55. data/spec/unit/api/query_builder_spec.rb +39 -39
  56. data/spec/unit/api/response_spec.rb +8 -8
  57. data/spec/unit/configuration_spec.rb +14 -14
  58. data/spec/unit/entity/audio_spec.rb +6 -6
  59. data/spec/unit/entity/author_spec.rb +3 -3
  60. data/spec/unit/entity/base_spec.rb +19 -19
  61. data/spec/unit/entity/book_edition_spec.rb +4 -4
  62. data/spec/unit/entity/book_spec.rb +2 -2
  63. data/spec/unit/entity/byline_spec.rb +3 -3
  64. data/spec/unit/entity/collection_spec.rb +1 -1
  65. data/spec/unit/entity/crop_spec.rb +2 -2
  66. data/spec/unit/entity/englargement_spec.rb +2 -2
  67. data/spec/unit/entity/external_assset_spec.rb +39 -0
  68. data/spec/unit/entity/formats_spec.rb +4 -4
  69. data/spec/unit/entity/image_spec.rb +7 -7
  70. data/spec/unit/entity/intro_text_spec.rb +3 -3
  71. data/spec/unit/entity/link_spec.rb +3 -3
  72. data/spec/unit/entity/list_spec.rb +3 -3
  73. data/spec/unit/entity/list_text_spec.rb +3 -3
  74. data/spec/unit/entity/member_byline_spec.rb +2 -2
  75. data/spec/unit/entity/member_promo_art_spec.rb +2 -2
  76. data/spec/unit/entity/member_spec.rb +4 -4
  77. data/spec/unit/entity/mp3_spec.rb +4 -4
  78. data/spec/unit/entity/name_spec.rb +3 -3
  79. data/spec/unit/entity/organization_spec.rb +2 -2
  80. data/spec/unit/entity/paragraph_spec.rb +3 -3
  81. data/spec/unit/entity/parent_spec.rb +39 -0
  82. data/spec/unit/entity/permissions_spec.rb +16 -6
  83. data/spec/unit/entity/program_spec.rb +7 -3
  84. data/spec/unit/entity/promo_art_book_edition_spec.rb +2 -2
  85. data/spec/unit/entity/promo_art_spec.rb +2 -2
  86. data/spec/unit/entity/pull_quote_spec.rb +2 -2
  87. data/spec/unit/entity/related_link_spec.rb +7 -7
  88. data/spec/unit/entity/show_spec.rb +3 -3
  89. data/spec/unit/entity/story_spec.rb +35 -36
  90. data/spec/unit/entity/text_spec.rb +4 -4
  91. data/spec/unit/entity/title_spec.rb +3 -3
  92. data/spec/unit/entity/transcript_spec.rb +2 -2
  93. metadata +10 -8
@@ -7,9 +7,9 @@ module NPR
7
7
  class << self
8
8
  #-------------------------
9
9
  # Find a story based on ID
10
- #
10
+ #
11
11
  # This method is meant to be a quick, easy
12
- # way to find a story just by its ID.
12
+ # way to find a story just by its ID.
13
13
  #
14
14
  # If you need more control over what gets
15
15
  # fetched and how, use NPR::Client directly,
@@ -17,8 +17,8 @@ module NPR
17
17
  # +order+, etc.)
18
18
  #
19
19
  # It is not possible to pass options into this
20
- # method. Therefore, you *must* globally
21
- # configure at least the apiKey using
20
+ # method. Therefore, you *must* globally
21
+ # configure at least the apiKey using
22
22
  # +NPR.configure+.
23
23
  #
24
24
  # Example:
@@ -27,20 +27,20 @@ module NPR
27
27
  #
28
28
  def find(id)
29
29
  response = query_by_id(id)
30
-
30
+
31
31
  if !response.messages.empty?
32
32
  response.messages
33
33
  else
34
34
  response.list.stories.first
35
35
  end
36
36
  end
37
-
37
+
38
38
  #-------------------------
39
39
  # Same as above, but returns +nil+ if a single story isn't
40
40
  # returned.
41
41
  def find_by_id(id)
42
42
  response = query_by_id(id)
43
-
43
+
44
44
  if !response.messages.empty?
45
45
  nil
46
46
  else
@@ -54,18 +54,18 @@ module NPR
54
54
  # QueryBuilder and proxies to its corresponding method on
55
55
  # Query Builder class.
56
56
  #
57
- # We could use ActiveSupport's delegation for this, but
57
+ # We could use ActiveSupport's delegation for this, but
58
58
  # this is simple enough.
59
59
  NPR::API::QueryBuilder::CLASS_BUILDER_METHODS.each do |method|
60
60
  define_method method do |args|
61
61
  NPR::API::QueryBuilder.new(self).send(method, args)
62
62
  end
63
63
  end
64
-
64
+
65
65
  #-------------------------
66
-
66
+
67
67
  private
68
-
68
+
69
69
  def query_by_id(id)
70
70
  client.query(:id => id)
71
71
  end
@@ -79,38 +79,30 @@ module NPR
79
79
  end
80
80
 
81
81
  #-------------------------
82
- # Association accessors
83
-
84
- # Attributes that we are using as-is
85
- # Use strings so that we don't have to
86
- # convert between Strings and Symbols.
87
- ATTR_AS_IS = [
88
- "thumbnail",
89
- "parent",
90
- "container"
91
- ]
92
- attr_accessor *ATTR_AS_IS
93
- attr_accessor :id, :text, :textWithHtml
94
-
82
+
83
+ attr_accessor :id, :text, :textWithHtml, :thumbnail, :container
84
+
95
85
  #------------------
96
-
97
- has_many "images", :key => "image", :class_name => NPR::Entity::Image
98
- has_many "bylines", :key => "byline", :class_name => NPR::Entity::Byline
99
- has_many "audio", :key => "audio", :class_name => NPR::Entity::Audio
100
- has_many "organizations", :key => "organization", :class_name => NPR::Entity::Organization
101
- has_many "links", :key => "link", :class_name => NPR::Entity::Link
102
- has_many "related_links", :key => "relatedLink", :class_name => NPR::Entity::RelatedLink
103
- has_many "pull_quotes", :key => "pullQuote", :class_name => NPR::Entity::PullQuote
104
- has_many "shows", :key => "show", :class_name => NPR::Entity::Show
105
- has_many "members", :key => "member", :class_name => NPR::Entity::Member
106
- has_many "list_texts", :key => "listText", :class_name => NPR::Entity::ListText
107
- has_many "promo_arts", :key => "promoArt", :class_name => NPR::Entity::PromoArt
108
- has_many "book_editions", :key => "bookEdition", :class_name => NPR::Entity::BookEdition
109
-
86
+
87
+ include NPR::Concern::LinksAssociation
88
+ has_many "audio", :key => "audio", :class_name => NPR::Entity::Audio
89
+ has_many "book_editions", :key => "bookEdition", :class_name => NPR::Entity::BookEdition
90
+ has_many "bylines", :key => "byline", :class_name => NPR::Entity::Byline
91
+ has_many "external_assets", :key => "externalAsset", :class_name => NPR::Entity::ExternalAsset
92
+ has_many "images", :key => "image", :class_name => NPR::Entity::Image
93
+ has_many "list_texts", :key => "listText", :class_name => NPR::Entity::ListText
94
+ has_many "members", :key => "member", :class_name => NPR::Entity::Member
95
+ has_many "organizations", :key => "organization", :class_name => NPR::Entity::Organization
96
+ has_many "parents", :key => "parent", :class_name => NPR::Entity::Parent
97
+ has_many "promo_arts", :key => "promoArt", :class_name => NPR::Entity::PromoArt
98
+ has_many "pull_quotes", :key => "pullQuote", :class_name => NPR::Entity::PullQuote
99
+ has_many "related_links", :key => "relatedLink", :class_name => NPR::Entity::RelatedLink
100
+ has_many "shows", :key => "show", :class_name => NPR::Entity::Show
101
+
110
102
  has_one "transcript", :class_name => NPR::Entity::Transcript
111
103
 
112
104
  #------------------
113
-
105
+
114
106
  shallow_attribute(
115
107
  "title",
116
108
  "partnerId",
@@ -126,22 +118,22 @@ module NPR
126
118
  "priorityKeywords",
127
119
  "fullText"
128
120
  )
129
-
121
+
130
122
  #-------------------------
131
123
 
132
124
  def initialize(json)
133
125
  @_json = json
134
126
  @id = @_json["id"].to_i
135
-
127
+
136
128
  build_text
137
129
  extract_shallow_attributes(@_json)
138
130
  create_relations(@_json)
139
131
  end
140
-
132
+
141
133
  #-------------------------
142
- # The primary image.
143
- #
144
- # Looks at the "type" attribute on
134
+ # The primary image.
135
+ #
136
+ # Looks at the "type" attribute on
145
137
  # an image and finds any with type "primary". If none
146
138
  # are found, then return the first image of any type.
147
139
  #
@@ -151,35 +143,18 @@ module NPR
151
143
  primary || self.images.first
152
144
  end
153
145
  end
154
-
155
- #-------------------------
156
- # Find links of the passed in type.
157
- #
158
- # Example:
159
- #
160
- # story.link_for("html") #=> http://npr.org/...
161
- # story.link_for("nothing") #=> nil
162
- #
163
- # Returns an the content of that link if found,
164
- # or nil if not found.
165
- #
166
- def link_for(type)
167
- if link = self.links.find { |link| link.type == type }
168
- link.to_s
169
- end
170
- end
171
146
 
172
147
  #-------------------------
173
-
148
+
174
149
  private
175
-
150
+
176
151
  #-------------------------
177
-
152
+
178
153
  def build_text
179
154
  if @_json["text"]
180
155
  @text = NPR::Entity::Text.new(@_json["text"])
181
156
  end
182
-
157
+
183
158
  if @_json["textWithHtml"]
184
159
  @textWithHtml = NPR::Entity::Text.new(@_json["textWithHtml"])
185
160
  end
@@ -188,13 +163,8 @@ module NPR
188
163
  end # Entity
189
164
 
190
165
  #-------------------------
191
- # Alias
192
- # This is a shorthand so that users of this library
166
+ # A shorthand so that users of this library
193
167
  # can work with just NPR::Story, but allowing us to
194
168
  # keep everything organized properly.
195
- #
196
- # The other classes under Entity aren't part of the
197
- # library's public API, so they don't need to be
198
- # aliased.
199
169
  Story = NPR::Entity::Story
200
170
  end # NPR
@@ -7,22 +7,22 @@ module NPR
7
7
  has_many "paragraphs", :key => "paragraph", :class_name => NPR::Entity::Paragraph
8
8
 
9
9
  #-----------------
10
-
10
+
11
11
  def initialize(json)
12
12
  create_relations(json)
13
13
  end
14
-
14
+
15
15
  #-----------------
16
-
16
+
17
17
  def to_s
18
18
  @paragraphs.map(&:to_s).join("\n")
19
19
  end
20
-
20
+
21
21
  #-----------------
22
- # Turn this text node into an embeddable
22
+ # Turn this text node into an embeddable
23
23
  # block of HTML.
24
24
  #
25
- # This is useful if the fullText attribute
25
+ # This is useful if the fullText attribute
26
26
  # is missing on an NPR Story. It will not
27
27
  # be as robust as a full HTML body from
28
28
  # NPR, but it will work in most cases.
@@ -33,7 +33,7 @@ module NPR
33
33
  @paragraphs.each do |paragraph|
34
34
  result << "<p>" + paragraph.to_s + "</p>\n"
35
35
  end
36
-
36
+
37
37
  result
38
38
  end
39
39
  end # Text
@@ -5,14 +5,14 @@ module NPR
5
5
  module Entity
6
6
  class Title < Base
7
7
  attr_accessor :num, :content
8
-
8
+
9
9
  def initialize(json)
10
10
  @num = json["num"].to_i
11
- @content = json["$text"]
11
+ @content = json["$text"]
12
12
  end
13
-
13
+
14
14
  #--------------------
15
-
15
+
16
16
  def to_s
17
17
  @content.to_s
18
18
  end
@@ -5,9 +5,9 @@ module NPR
5
5
  module Entity
6
6
  class Transcript < Base
7
7
  has_one "link", :class_name => NPR::Entity::Link
8
-
8
+
9
9
  #-------------------
10
-
10
+
11
11
  def initialize(json)
12
12
  create_relations(json)
13
13
  end
data/lib/npr/errors.rb CHANGED
@@ -13,5 +13,5 @@ module NPR
13
13
  end
14
14
 
15
15
  class NotConfiguredError < ClientError
16
- end
16
+ end
17
17
  end # NPR
data/lib/npr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module NPR
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/lib/npr.rb CHANGED
@@ -19,6 +19,7 @@ require "npr/concern"
19
19
  require "npr/concern/attr_typecast"
20
20
  require "npr/concern/shallow_attributes"
21
21
  require "npr/concern/relation"
22
+ require "npr/concern/links_association"
22
23
 
23
24
  #------------------
24
25
  # API handlers
@@ -46,11 +47,13 @@ require "npr/entity/intro_text"
46
47
  require "npr/entity/member_byline"
47
48
  require "npr/entity/promo_art_book_edition"
48
49
  require "npr/entity/member"
50
+ require "npr/entity/parent"
49
51
  require "npr/entity/collection"
50
52
  require "npr/entity/provider"
51
53
  require "npr/entity/enlargement"
52
54
  require "npr/entity/crop"
53
55
  require "npr/entity/image"
56
+ require "npr/entity/external_asset"
54
57
  require "npr/entity/promo_art"
55
58
  require "npr/entity/mp3"
56
59
  require "npr/entity/formats"
@@ -21,7 +21,7 @@ options = {}
21
21
 
22
22
  OptionParser.new do |opts|
23
23
  opts.banner = "Usage: ruby fetch_formats.rb [ARGS]"
24
-
24
+
25
25
  opts.on('-k', '--key KEY', 'Your NPR API Key') do |key|
26
26
  options[:key] = key
27
27
  end
@@ -51,15 +51,15 @@ ext_map = {
51
51
  # The fun stuff
52
52
  ext_map.keys.each do |output|
53
53
  puts "Fetching #{output}..."
54
-
54
+
55
55
  uri = URI.parse("http://api.npr.org/query?apiKey=#{options[:key]}&id=#{options[:id]}&output=#{output}")
56
56
  response = Net::HTTP.get_response(uri).body
57
-
57
+
58
58
  # Remove API Key from responses
59
59
  if !options[:key].empty? && !options[:key].nil?
60
60
  response.gsub!(/#{options[:key]}/, "API_KEY")
61
61
  end
62
-
62
+
63
63
  file = "#{output}/#{options[:filename]}.#{ext_map[output]}"
64
64
  File.open(file, "w") { |f| f.puts response }
65
65
  end
data/spec/spec_helper.rb CHANGED
@@ -16,7 +16,7 @@ RSpec.configure do |config|
16
16
  config.include FakeResponse
17
17
  config.include ConfigHelper
18
18
  config.include FixtureHelper
19
-
19
+
20
20
  config.before do
21
21
  FakeWeb.clean_registry
22
22
  end
@@ -7,7 +7,7 @@ describe NPR::API::Client do
7
7
  client.instance_variable_get(:@apiKey).should eq "key"
8
8
  client.params.keys.should_not include :apiKey
9
9
  end
10
-
10
+
11
11
  it "sets @url on initialize" do
12
12
  client = NPR::API::Client.new(:url => "http://api.publish2.com")
13
13
  client.url.should eq "http://api.publish2.com"
@@ -24,16 +24,16 @@ describe NPR::API::Client do
24
24
  client = NPR::API::Client.new
25
25
  client.params[:sort].should eq "super sort"
26
26
  end
27
-
27
+
28
28
  it "passed-in params take precedence over global config" do
29
29
  NPR.config.sort = "global sort"
30
30
  client = NPR::API::Client.new(:sort => "local sort")
31
31
  client.params[:sort].should eq "local sort"
32
32
  end
33
33
  end
34
-
34
+
35
35
  #-----------------
36
-
36
+
37
37
  describe "#query" do
38
38
  it 'uses the passed-in path if available' do
39
39
  respond_with("json/01_story_full_media.json", :uri => %r|api\.publish2\.com/list/stories|)
@@ -16,31 +16,31 @@ describe NPR::API::Message do
16
16
  }
17
17
  JSON
18
18
  end
19
-
19
+
20
20
  before :each do
21
21
  @message = NPR::API::Message.new(@fixture)
22
22
  end
23
-
23
+
24
24
  it "sets level and id" do
25
25
  @message.id.should eq "203"
26
26
  @message.level.should eq "warning"
27
27
  end
28
-
28
+
29
29
  it "returns true for #warning?" do
30
30
  @message.warning?.should eq true
31
31
  end
32
-
32
+
33
33
  it "sets text" do
34
34
  @message.text.should match /^Query/
35
35
  end
36
-
36
+
37
37
  it "sets timestamp" do
38
38
  @message.timestamp.should be_a Time
39
39
  end
40
40
  end
41
-
41
+
42
42
  #---------------------------
43
-
43
+
44
44
  describe "error" do
45
45
  json_fixture do
46
46
  <<-JSON
@@ -56,11 +56,11 @@ describe NPR::API::Message do
56
56
  }
57
57
  JSON
58
58
  end
59
-
59
+
60
60
  before :each do
61
61
  @message = NPR::API::Message.new(@fixture)
62
62
  end
63
-
63
+
64
64
  it "is an error" do
65
65
  @message.error?.should eq true
66
66
  end
@@ -5,7 +5,7 @@ describe NPR::API::QueryBuilder do
5
5
  before :each do
6
6
  @builder = NPR::API::QueryBuilder.new(NPR::Story)
7
7
  end
8
-
8
+
9
9
  it "turns the query builder in params that the API can understand" do
10
10
  @builder.where(:id => 5).order("date descending").limit(10).offset(100)
11
11
  @builder.to_params.should eq Hash[
@@ -15,99 +15,99 @@ describe NPR::API::QueryBuilder do
15
15
  :startNum => 100
16
16
  ]
17
17
  end
18
-
18
+
19
19
  it "merges in @builder[:extra] last, which overrides anything" do
20
20
  @builder.set(:id => 5).where(:id => 10)
21
21
  @builder.to_params.should eq Hash[:id => 5]
22
22
  end
23
-
23
+
24
24
  it "doesn't create params if the value was not set" do
25
25
  @builder.where(:id => 5).to_params.keys.should eq [:id]
26
26
  end
27
-
27
+
28
28
  it "is an empty hash if no params are set" do
29
29
  @builder.to_params.should eq Hash.new
30
30
  end
31
31
  end
32
32
 
33
33
  #----------------------
34
-
34
+
35
35
  describe "#to_a" do
36
36
  config!(:apiKey => "key")
37
-
37
+
38
38
  before :each do
39
39
  @builder = NPR::API::QueryBuilder.new(NPR::Story)
40
40
  @builder.set(:apiKey => "key")
41
41
  end
42
-
42
+
43
43
  it "returns an array of stories if present" do
44
44
  @builder.where(:id => 5).order("date descending").limit(10).offset(100)
45
-
45
+
46
46
  stories = mock_response "json/06_story_multiple_ids.json" do
47
47
  @builder.to_a
48
48
  end
49
-
49
+
50
50
  stories.should be_a Array
51
51
  stories.should_not be_empty
52
52
  stories.first.should be_a NPR::Story
53
53
  end
54
-
54
+
55
55
  it "returns an empty array if no list or no stories were found" do
56
56
  @builder.where(:id => 5).order("date descending").limit(10).offset(100)
57
-
57
+
58
58
  stories = mock_response "json/05_no_api_key.json" do
59
59
  @builder.to_a
60
60
  end
61
-
61
+
62
62
  stories.should be_a Array
63
63
  stories.should be_empty
64
64
  end
65
65
  end
66
66
 
67
67
  #----------------------
68
-
68
+
69
69
  describe "#query" do
70
70
  config!(:apiKey => "key")
71
-
71
+
72
72
  before :each do
73
73
  @builder = NPR::API::QueryBuilder.new(NPR::Story)
74
74
  end
75
-
75
+
76
76
  it "sends off a query and returns the response object" do
77
77
  response = mock_response "json/01_story_full_media.json" do
78
78
  @builder.where(:id => 100).query
79
79
  end
80
-
80
+
81
81
  response.should be_a NPR::API::Response
82
- end
82
+ end
83
83
  end
84
-
84
+
85
85
  #----------------------
86
-
86
+
87
87
  describe "#set" do
88
88
  before :each do
89
89
  @builder = NPR::API::QueryBuilder.new(NPR::Story)
90
90
  end
91
-
91
+
92
92
  it "sets arbitrary parameters" do
93
93
  @builder.set(:whatever => "something cool")
94
94
  @builder.builder[:extra].should eq Hash[
95
95
  :whatever => "something cool"
96
96
  ]
97
97
  end
98
-
98
+
99
99
  it "returns itself" do
100
100
  @builder.set(:a => "b").should eq @builder
101
101
  end
102
102
  end
103
-
103
+
104
104
  #----------------------
105
105
 
106
106
  describe "#where" do
107
107
  before :each do
108
108
  @builder = NPR::API::QueryBuilder.new(NPR::Story)
109
109
  end
110
-
110
+
111
111
  it "adds the conditions to the query builder" do
112
112
  @builder.where(:id => 9999)
113
113
  @builder.where(:origId => 100)
@@ -118,70 +118,70 @@ describe NPR::API::QueryBuilder do
118
118
  :origId => 100
119
119
  }]
120
120
  end
121
-
121
+
122
122
  it "returns itself" do
123
123
  @builder.where(:id => 0).should eq @builder
124
124
  end
125
125
  end
126
-
126
+
127
127
  #----------------------
128
-
128
+
129
129
  describe "#order" do
130
130
  before :each do
131
131
  @builder = NPR::API::QueryBuilder.new(NPR::Story)
132
132
  end
133
-
133
+
134
134
  it "adds the order to the query builder" do
135
135
  @builder.order("date descending")
136
136
  @builder.builder.should eq Hash[:order => "date descending"]
137
137
  end
138
-
138
+
139
139
  it "returns itself" do
140
140
  @builder.order("date ascending").should eq @builder
141
141
  end
142
142
  end
143
-
143
+
144
144
  #----------------------
145
-
145
+
146
146
  describe "#limit" do
147
147
  before :each do
148
148
  @builder = NPR::API::QueryBuilder.new(NPR::Story)
149
149
  end
150
-
150
+
151
151
  it "adds the limit to the query builder" do
152
152
  @builder.limit(10)
153
153
  @builder.builder.should eq Hash[:limit => 10]
154
154
  end
155
-
155
+
156
156
  it "returns itself" do
157
157
  @builder.limit(0).should eq @builder
158
158
  end
159
159
  end
160
-
160
+
161
161
  #----------------------
162
-
162
+
163
163
  describe "#offset" do
164
164
  before :each do
165
165
  @builder = NPR::API::QueryBuilder.new(NPR::Story)
166
166
  end
167
-
167
+
168
168
  it "adds the offset to the query builder" do
169
169
  @builder.offset(100)
170
170
  @builder.builder.should eq Hash[:offset => 100]
171
171
  end
172
-
172
+
173
173
  it "returns itself" do
174
174
  @builder.offset(0).should eq @builder
175
175
  end
176
176
  end
177
-
177
+
178
178
  #----------------------
179
-
179
+
180
180
  describe "chaining queries" do
181
181
  before :each do
182
182
  @builder = NPR::API::QueryBuilder.new(NPR::Story)
183
183
  end
184
-
184
+
185
185
  it "can chain the queries" do
186
186
  @builder.where(:id => 5).order("date descending").limit(10).offset(100)
187
187
  @builder.builder.should eq Hash[