rscribd 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ # @private
2
+ class Symbol
3
+ def to_proc
4
+ Proc.new { |*args| args.shift.__send__(self, *args) }
5
+ end unless method_defined?(:to_proc)
6
+ end
7
+
8
+ # @private
9
+ class Hash
10
+ # Taken from Rails, with appreciation to DHH
11
+ def stringify_keys
12
+ inject({}) do |options, (key, value)|
13
+ options[key.to_s] = value
14
+ options
15
+ end
16
+ end unless method_defined?(:stringify_keys)
17
+ end
18
+
19
+ # @private
20
+ class Array
21
+ def to_hsh
22
+ h = Hash.new
23
+ each { |k, v| h[k] = v }
24
+ h
25
+ end
26
+ end
@@ -6,7 +6,9 @@ require 'rubygems'
6
6
  require 'mime/types' # Requires gem install mime-types
7
7
  require 'cgi'
8
8
 
9
- module Net #:nodoc:all
9
+ # @private
10
+ module Net
11
+ # @private
10
12
  class HTTP::Post
11
13
  def multipart_params=(param_hash={})
12
14
  boundary_token = [Array.new(8) {rand(256)}].join
@@ -0,0 +1,86 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{rscribd}
8
+ s.version = "1.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tim Morgan", "Jared Friedman", "Mike Watts"]
12
+ s.date = %q{2010-05-13}
13
+ s.description = %q{The official Ruby gem for the Scribd API. Scribd is a document-sharing website allowing people to upload and view documents online.}
14
+ s.email = %q{api@scribd.com}
15
+ s.extra_rdoc_files = [
16
+ "README"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "History.txt",
21
+ "README",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "lib/rscribd.rb",
25
+ "lib/scribd/api.rb",
26
+ "lib/scribd/category.rb",
27
+ "lib/scribd/collection.rb",
28
+ "lib/scribd/document.rb",
29
+ "lib/scribd/errors.rb",
30
+ "lib/scribd/resource.rb",
31
+ "lib/scribd/security.rb",
32
+ "lib/scribd/user.rb",
33
+ "lib/support/extensions.rb",
34
+ "lib/support/multipart_hack.rb",
35
+ "rscribd.gemspec",
36
+ "sample/01_upload.rb",
37
+ "sample/02_user.rb",
38
+ "sample/test.txt",
39
+ "spec/api_spec.rb",
40
+ "spec/category_spec.rb",
41
+ "spec/collection_spec.rb",
42
+ "spec/document_spec.rb",
43
+ "spec/error_spec.rb",
44
+ "spec/resource_spec.rb",
45
+ "spec/rscribd_spec.rb",
46
+ "spec/security_spec.rb",
47
+ "spec/user_spec.rb"
48
+ ]
49
+ s.homepage = %q{http://www.scribd.com/developers}
50
+ s.rdoc_options = ["--charset=UTF-8"]
51
+ s.require_paths = ["lib"]
52
+ s.rubyforge_project = %q{rscribd}
53
+ s.rubygems_version = %q{1.3.6}
54
+ s.summary = %q{Ruby client library for the Scribd API}
55
+ s.test_files = [
56
+ "spec/api_spec.rb",
57
+ "spec/category_spec.rb",
58
+ "spec/collection_spec.rb",
59
+ "spec/document_spec.rb",
60
+ "spec/error_spec.rb",
61
+ "spec/resource_spec.rb",
62
+ "spec/rscribd_spec.rb",
63
+ "spec/security_spec.rb",
64
+ "spec/user_spec.rb"
65
+ ]
66
+
67
+ if s.respond_to? :specification_version then
68
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
69
+ s.specification_version = 3
70
+
71
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
72
+ s.add_runtime_dependency(%q<mime-types>, [">= 0"])
73
+ s.add_development_dependency(%q<rspec>, [">= 0"])
74
+ s.add_development_dependency(%q<yard>, [">= 0"])
75
+ else
76
+ s.add_dependency(%q<mime-types>, [">= 0"])
77
+ s.add_dependency(%q<rspec>, [">= 0"])
78
+ s.add_dependency(%q<yard>, [">= 0"])
79
+ end
80
+ else
81
+ s.add_dependency(%q<mime-types>, [">= 0"])
82
+ s.add_dependency(%q<rspec>, [">= 0"])
83
+ s.add_dependency(%q<yard>, [">= 0"])
84
+ end
85
+ end
86
+
@@ -0,0 +1,177 @@
1
+ CATEGORY = Proc.new { |id, name, children|
2
+ id ||= rand(1000)
3
+ name ||= "Test Category #{id}"
4
+ children ||= nil
5
+
6
+ str = <<-EOF
7
+ <id>#{id}</id>
8
+ <name><![CDATA[#{name}]]></name>
9
+ EOF
10
+ str + (children ? "<subcategories>#{children}</subcategories>" : "")
11
+ }
12
+
13
+ CATEGORY_TAG = Proc.new { |root, category|
14
+ root ||= 'result'
15
+ category ||= CATEGORY.call
16
+
17
+ <<-EOF
18
+ <#{root}>
19
+ #{category}
20
+ </#{root}>
21
+ EOF
22
+ }
23
+
24
+ RESULT = Proc.new { |categories|
25
+ categories ||= (0..10).map { CATEGORY_TAG.call(nil, nil, ((0..10).map { CATEGORY_TAG.call('subcategory') }.join("\n"))) }.join("\n")
26
+ <<-EOF
27
+ <?xml version="1.0" encoding="UTF-8"?>
28
+ <rsp stat="ok">
29
+ <result_set>
30
+ #{categories}
31
+ </result_set>
32
+ </rsp>
33
+ EOF
34
+ }
35
+
36
+ describe Scribd::Category do
37
+ subject { Scribd::Category.new(:xml => REXML::Document.new(CATEGORY_TAG.call(nil, CATEGORY.call('12', 'test'))).root) }
38
+
39
+ describe "#initialize" do
40
+ it "should raise an error if initialized without XML" do
41
+ lambda { Scribd::Category.new :name => 'foo' }.should raise_error
42
+ end
43
+
44
+ context "attributes" do
45
+ its(:id) { should eql('12') }
46
+ its(:name) { should eql('test') }
47
+ end
48
+
49
+ it "should populate children that link back to their parents" do
50
+ response = CATEGORY_TAG.call(nil, CATEGORY.call(nil, nil, CATEGORY_TAG.call('subcategory', CATEGORY.call('100'))))
51
+
52
+ category = Scribd::Category.new(:xml => REXML::Document.new(response).root)
53
+ Scribd::API.instance.should_not_receive(:send_request) # not really being tested here, but we should make sure we don't actually make remote requests
54
+ category.children.should be_kind_of(Array)
55
+ category.children.first.should be_kind_of(Scribd::Category)
56
+ category.children.first.id.should eql('100')
57
+ category.children.first.name.should eql('Test Category 100')
58
+ category.children.first.children_preloaded?.should be_false
59
+ category.children.first.parent.should eql(category)
60
+ end
61
+
62
+ it { should be_saved }
63
+ it { should be_created }
64
+ end
65
+
66
+ describe "#children_preloaded?" do
67
+ it "should be true for categories initialized with children" do
68
+ response = CATEGORY_TAG.call(nil, CATEGORY.call(nil, nil, CATEGORY_TAG.call('subcategory')))
69
+ Scribd::Category.new(:xml => REXML::Document.new(response).root).children_preloaded?.should be_true
70
+ end
71
+
72
+ it "should be false for categories initialized without children" do
73
+ Scribd::Category.new(:xml => REXML::Document.new(CATEGORY_TAG.call).root).children_preloaded?.should be_false
74
+ end
75
+ end
76
+
77
+ describe :all do
78
+ before :each do
79
+ @response = REXML::Document.new(RESULT.call).root
80
+ end
81
+
82
+ it "should send an API request to docs.getCategories" do
83
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.getCategories').and_return(@response)
84
+ Scribd::Category.all
85
+ end
86
+
87
+ it "should set with_subcategories if include_children is true" do
88
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.getCategories', :with_subcategories => true).and_return(@response)
89
+ Scribd::Category.all(true)
90
+ end
91
+
92
+ it "should return an array of categories" do
93
+ Scribd::API.instance.stub!(:send_request).and_return(@response)
94
+ categories = Scribd::Category.all
95
+ categories.should be_kind_of(Array)
96
+ categories.first.should be_kind_of(Scribd::Category)
97
+ categories.last.should be_kind_of(Scribd::Category)
98
+ end
99
+ end
100
+
101
+ describe "#children" do
102
+ before :each do
103
+ xml = REXML::Document.new(CATEGORY_TAG.call(nil, CATEGORY.call(nil, nil, CATEGORY_TAG.call('subcategory')))).root
104
+ @preloaded = Scribd::Category.new(:xml => xml)
105
+
106
+ xml = REXML::Document.new(CATEGORY_TAG.call(nil, CATEGORY.call('3'))).root
107
+ @not_preloaded = Scribd::Category.new(:xml => xml)
108
+
109
+ @response = REXML::Document.new(RESULT.call(CATEGORY_TAG.call)).root
110
+ end
111
+
112
+ it "should not make a network call if the category has preloaded children" do
113
+ Scribd::API.instance.should_not_receive(:send_request)
114
+ @preloaded.children
115
+ end
116
+
117
+ it "should otherwise make an API call to docs.getCategories" do
118
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.getCategories', :category_id => '3').and_return(@response)
119
+ @not_preloaded.children
120
+ end
121
+
122
+ it "should return an array of child categories" do
123
+ Scribd::API.instance.stub!(:send_request).and_return(@response)
124
+ cats = @not_preloaded.children
125
+ cats.should be_kind_of(Array)
126
+ cats.first.should be_kind_of(Scribd::Category)
127
+ end
128
+ end
129
+
130
+ describe "#browse" do
131
+ before :each do
132
+ @response = REXML::Document.new(<<-EOF
133
+ <?xml version="1.0" encoding="UTF-8"?>
134
+ <rsp stat="ok">
135
+ <result_set totalResultsAvailable="922" totalResultsReturned="2" firstResultPosition="1" list="true">
136
+ <result>
137
+ <title>&lt;![CDATA[Ruby on Java]]&gt;</title>
138
+ <description>&lt;![CDATA[Ruby On Java, Barcamp, Washington DC]]&gt;</description>
139
+ <access_key>key-t3q5qujoj525yun8gf7</access_key>
140
+ <doc_id>244565</doc_id>
141
+ <page_count>10</page_count>
142
+ <download_formats></download_formats>
143
+ </result>
144
+ <result>
145
+ <title>&lt;![CDATA[Ruby on Java Part II]]&gt;</title>
146
+ <description>&lt;![CDATA[Ruby On Java Part II, Barcamp, Washington DC]]&gt;</description>
147
+ <access_key>key-2b3udhalycthsm91d1ps</access_key>
148
+ <doc_id>244567</doc_id>
149
+ <page_count>12</page_count>
150
+ <download_formats>pdf,txt</download_formats>
151
+ </result>
152
+ </result_set>
153
+ </rsp>
154
+ EOF
155
+ ).root
156
+ end
157
+
158
+ it "should make an API call to docs.browse" do
159
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.browse', :category_id => '12').and_return(@response)
160
+ subject.browse
161
+ end
162
+
163
+ it "should pass options to the API call" do
164
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.browse', :category_id => '12', :foo => 'bar').and_return(@response)
165
+ subject.browse(:foo => 'bar')
166
+ end
167
+
168
+ it "should return an array of Documents" do
169
+ Scribd::API.instance.stub!(:send_request).and_return(@response)
170
+ docs = subject.browse
171
+ docs.should be_kind_of(Array)
172
+ docs.each do |doc|
173
+ doc.should be_kind_of(Scribd::Document)
174
+ end
175
+ end
176
+ end
177
+ end
@@ -0,0 +1,127 @@
1
+ describe Scribd::Collection do
2
+ before :each do
3
+ Scribd::API.instance.key = 'test key'
4
+ Scribd::API.instance.secret = 'test sec'
5
+ end
6
+
7
+ subject do
8
+ user = Scribd::User.new(:xml => REXML::Document.new("<rsp stat='ok'><user_id type='integer'>225</user_id><username>sancho</username><name>Sancho Sample</name><session_key>some key</session_key></rsp>").root)
9
+ Scribd::Collection.new(:xml => REXML::Document.new("<result><collection_id>61</collection_id><collection_name>My Collection</collection_name></result>").root, :owner => user)
10
+ end
11
+
12
+ describe "#initialize" do
13
+ context "from XML" do
14
+ its(:collection_id) { should eql("61") }
15
+ its(:collection_name) { should eql("My Collection") }
16
+ it { should be_saved }
17
+ it { should be_created }
18
+
19
+ it "should set the owner" do
20
+ user = Scribd::User.new
21
+ coll = Scribd::Collection.new(:xml => REXML::Document.new("<result><collection_id>61</collection_id><collection_name>My Collection</collection_name></result>").root, :owner => user)
22
+ coll.owner.should eql(user)
23
+ end
24
+ end
25
+
26
+ context "from attributes" do
27
+ it "should raise an exception" do
28
+ lambda { Scribd::Collection.new(:collection_id => 61, :collection_name => "My Collection") }.should raise_error
29
+ end
30
+ end
31
+ end
32
+
33
+ context "aliased attributes" do
34
+ its(:id) { should eql('61') }
35
+ its(:name) { should eql('My Collection') }
36
+ end
37
+
38
+ describe "#add" do
39
+ before :each do
40
+ @good_response = <<-EOF
41
+ <?xml version="1.0" encoding="UTF-8"?>
42
+ <rsp stat="ok">
43
+ </rsp>
44
+ EOF
45
+ @document = Scribd::Document.new(:doc_id => '123')
46
+ end
47
+
48
+ it "should raise ArgumentError if an invalid document is given" do
49
+ lambda { subject.add(123) }.should raise_error(ArgumentError)
50
+ end
51
+
52
+ it "should make an API call to docs.addToCollection" do
53
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.addToCollection', hash_including(:doc_id => '123', :collection_id => '61', :session_key => 'some key')).and_return(REXML::Document.new(@good_response).root)
54
+ subject.add(@document)
55
+ end
56
+
57
+ it "should capture ResponseErrors of code 653 if ignore_if_exists is true" do
58
+ Scribd::API.instance.stub!(:send_request).and_raise(Scribd::ResponseError.new('653'))
59
+ lambda { subject.add(@document) }.should_not raise_error
60
+ end
61
+
62
+ it "should not capture ResponseErrors of code 653 if ignore_if_exists is false" do
63
+ Scribd::API.instance.stub!(:send_request).and_raise(Scribd::ResponseError.new('653'))
64
+ lambda { subject.add(@document, false) }.should raise_error(Scribd::ResponseError)
65
+ end
66
+
67
+ it "should not capture ResponseErrors of other codes" do
68
+ Scribd::API.instance.stub!(:send_request).and_raise(Scribd::ResponseError.new('652'))
69
+ lambda { subject.add(@document, false) }.should raise_error(Scribd::ResponseError)
70
+ lambda { subject.add(@document) }.should raise_error(Scribd::ResponseError)
71
+ end
72
+
73
+ it "should return the document" do
74
+ Scribd::API.instance.stub!(:send_request).and_return(REXML::Document.new(@good_response).root)
75
+ subject.add(@document).should eql(@document)
76
+ end
77
+ end
78
+
79
+ describe "#<<" do
80
+ it "should call #add" do
81
+ doc_mock = mock('Scribd::Document')
82
+ subject.should_receive(:add).once.with(doc_mock).and_return(doc_mock)
83
+ (subject << doc_mock).should eql(doc_mock)
84
+ end
85
+ end
86
+
87
+ describe "#remove" do
88
+ before :each do
89
+ @good_response = <<-EOF
90
+ <?xml version="1.0" encoding="UTF-8"?>
91
+ <rsp stat="ok">
92
+ </rsp>
93
+ EOF
94
+ @document = Scribd::Document.new(:doc_id => '123')
95
+ end
96
+
97
+ it "should raise ArgumentError if an invalid document is given" do
98
+ lambda { subject.remove(123) }.should raise_error(ArgumentError)
99
+ end
100
+
101
+ it "should make an API call to docs.removeFromCollection" do
102
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.removeFromCollection', hash_including(:doc_id => '123', :collection_id => '61', :session_key => 'some key')).and_return(REXML::Document.new(@good_response).root)
103
+ subject.remove(@document)
104
+ end
105
+
106
+ it "should capture ResponseErrors of code 652 if ignore_if_missing is true" do
107
+ Scribd::API.instance.stub!(:send_request).and_raise(Scribd::ResponseError.new('652'))
108
+ lambda { subject.remove(@document) }.should_not raise_error
109
+ end
110
+
111
+ it "should not capture ResponseErrors of code 653 if ignore_if_missing is false" do
112
+ Scribd::API.instance.stub!(:send_request).and_raise(Scribd::ResponseError.new('652'))
113
+ lambda { subject.remove(@document, false) }.should raise_error(Scribd::ResponseError)
114
+ end
115
+
116
+ it "should not capture ResponseErrors of other codes" do
117
+ Scribd::API.instance.stub!(:send_request).and_raise(Scribd::ResponseError.new('653'))
118
+ lambda { subject.remove(@document, false) }.should raise_error(Scribd::ResponseError)
119
+ lambda { subject.remove(@document) }.should raise_error(Scribd::ResponseError)
120
+ end
121
+
122
+ it "should return the document" do
123
+ Scribd::API.instance.stub!(:send_request).and_return(REXML::Document.new(@good_response).root)
124
+ subject.remove(@document).should eql(@document)
125
+ end
126
+ end
127
+ end
@@ -263,6 +263,13 @@ describe Scribd::Document do
263
263
  @document.save
264
264
  end
265
265
 
266
+ it "should not pass the thumbnail option to the docs.upload call" do
267
+ @document.thumbnail = 'sample/test.txt'
268
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.upload', hash_not_including(:thumbnail))
269
+ Scribd::API.instance.should_receive(:send_request).any_number_of_times
270
+ @document.save
271
+ end
272
+
266
273
  describe "successfully" do
267
274
  before :each do
268
275
  @document.stub!(:id).and_return(3)
@@ -293,6 +300,49 @@ describe Scribd::Document do
293
300
  it "should return true" do
294
301
  @document.save.should be_true
295
302
  end
303
+
304
+ describe "with a path thumbnail" do
305
+ before :each do
306
+ @document.thumbnail = "sample/image.jpg"
307
+ end
308
+
309
+ it "should call docs.uploadThumb with a File object from the path" do
310
+ file_mock = mock('File (thumb)', :close => nil)
311
+ File.should_receive(:open).with(@document.thumbnail, 'rb').and_return(file_mock)
312
+ File.should_receive(:open).any_number_of_times.and_return(mock('File (content)', :close => nil))
313
+
314
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.uploadThumb', :file => file_mock, :doc_id => 3)
315
+ Scribd::API.instance.should_receive(:send_request).any_number_of_times
316
+
317
+ @document.save
318
+ end
319
+ end
320
+
321
+ describe "with a File thumbnail" do
322
+ before :each do
323
+ @document.thumbnail = File.open("sample/test.txt")
324
+ end
325
+
326
+ it "should call docs.uploadThumb with the File object" do
327
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.uploadThumb', :file => @document.thumbnail, :doc_id => 3)
328
+ Scribd::API.instance.should_receive(:send_request).any_number_of_times
329
+ @document.save
330
+ end
331
+ end
332
+
333
+ describe "with a URL thumbnail" do
334
+ before :each do
335
+ @document.thumbnail = "http://www.scribd.com/favicon.ico"
336
+ end
337
+
338
+ it "should open a stream for the URL and pass it to docs.uploadThumb" do
339
+ stream_mock = mock('open-uri stream', :close => nil)
340
+ @document.should_receive(:open).once.with(an_instance_of(URI::HTTP)).and_return(stream_mock)
341
+ Scribd::API.instance.should_receive(:send_request).once.with('docs.uploadThumb', :file => stream_mock, :doc_id => 3)
342
+ Scribd::API.instance.should_receive(:send_request).any_number_of_times
343
+ @document.save
344
+ end
345
+ end
296
346
  end
297
347
 
298
348
  it "should not send the file, type, or access parameters to the changeSettings call" do
@@ -310,6 +360,13 @@ describe Scribd::Document do
310
360
  @document.save
311
361
  end
312
362
 
363
+ it "should not pass thumbnail to the changeSettings call" do
364
+ @document.thumbnail = 'sample/test.txt'
365
+ Scribd::API.instance.should_receive(:send_request).with('docs.changeSettings', hash_not_including(:thumbnail))
366
+ Scribd::API.instance.should_receive(:send_request).any_number_of_times
367
+ @document.save
368
+ end
369
+
313
370
  it "should pass the owner's session key to changeSettings" do
314
371
  owner = mock('Scribd::User owner')
315
372
  owner.stub!(:session_key).and_return('his key')
@@ -379,8 +436,8 @@ describe Scribd::Document do
379
436
  lambda { Scribd::Document.find('oh hai') }.should raise_error(ArgumentError)
380
437
  end
381
438
 
382
- it "should raise an ArgumentError if a query is not provided for scoped lookups" do
383
- lambda { Scribd::Document.find(:all, :title => 'hi') }.should raise_error(ArgumentError)
439
+ it "should raise an ArgumentError if a query is not provided for non-ID lookups" do
440
+ lambda { Scribd::Document.find(:title => 'hi') }.should raise_error(ArgumentError)
384
441
  end
385
442
 
386
443
  describe "by ID" do
@@ -393,11 +450,6 @@ describe Scribd::Document do
393
450
  Scribd::Document.find 123
394
451
  end
395
452
 
396
- it "should pass other options to the getSettings call" do
397
- Scribd::API.instance.should_receive(:send_request).once.with('docs.getSettings', hash_including(:arg => 'val')).and_return(@xml)
398
- Scribd::Document.find 123, :arg => 'val'
399
- end
400
-
401
453
  it "should return a Document created from the resulting XML" do
402
454
  Scribd::API.instance.stub!(:send_request).and_return(@xml)
403
455
  doc = Scribd::Document.find(123)
@@ -411,34 +463,22 @@ describe Scribd::Document do
411
463
  @xml = REXML::Document.new("<rsp stat='ok'><result_set><result><access_key>abc123</access_key></result><result><access_key>abc321</access_key></result></result_set></rsp>")
412
464
  end
413
465
 
414
- it "should set the scope field according to the parameter" do
415
- Scribd::API.instance.should_receive(:send_request).with('docs.search', hash_including(:scope => 'all')).and_return(@xml)
416
- Scribd::Document.find(:all, :query => 'test')
417
- end
418
-
419
466
  it "should return an ordered array of Document results" do
420
467
  Scribd::API.instance.stub!(:send_request).and_return(@xml)
421
- docs = Scribd::Document.find(:all, :query => 'test')
468
+ docs = Scribd::Document.find(:query => 'test')
422
469
  docs.should have(2).items
423
470
  docs.first.access_key.should eql('abc123')
424
471
  docs.last.access_key.should eql('abc321')
425
472
  end
426
473
 
427
- it "should set the scope to 'all' and return the first result if :first is provided" do
428
- Scribd::API.instance.should_receive(:send_request).with('docs.search', hash_including(:scope => 'all')).and_return(@xml)
429
- docs = Scribd::Document.find(:first, :query => 'test')
430
- docs.should be_kind_of(Scribd::Document)
431
- docs.access_key.should eql('abc123')
432
- end
433
-
434
474
  it "should set the num_results field to the limit option" do
435
475
  Scribd::API.instance.should_receive(:send_request).with('docs.search', hash_including(:num_results => 10)).and_return(@xml)
436
- docs = Scribd::Document.find(:all, :query => 'test', :limit => 10)
476
+ docs = Scribd::Document.find(:query => 'test', :limit => 10)
437
477
  end
438
478
 
439
479
  it "should set the num_start field to the offset option" do
440
480
  Scribd::API.instance.should_receive(:send_request).with('docs.search', hash_including(:num_start => 10)).and_return(@xml)
441
- docs = Scribd::Document.find(:all, :query => 'test', :offset => 10)
481
+ docs = Scribd::Document.find(:query => 'test', :offset => 10)
442
482
  end
443
483
  end
444
484
  end
@@ -448,16 +488,17 @@ describe Scribd::Document do
448
488
  @xml = REXML::Document.new("<rsp stat='ok'><result_set><result><access_key>abc123</access_key></result><result><access_key>abc321</access_key></result></result_set></rsp>")
449
489
  end
450
490
 
451
- it "should set the scope field according the options" do
452
- Scribd::API.instance.should_receive(:send_request).with('docs.featured', hash_including(:scope => 'hot')).and_return(@xml)
453
- Scribd::Document.featured(:all, :scope => 'hot', :limit => 10)
454
- end
455
-
456
- it "should return first result if :first is provided" do
491
+ it "should call the docs.featured API method" do
457
492
  Scribd::API.instance.should_receive(:send_request).with('docs.featured', {}).and_return(@xml)
458
- docs = Scribd::Document.featured(:first)
459
- docs.should be_kind_of(Scribd::Document)
460
- docs.access_key.should eql('abc123')
493
+ docs = Scribd::Document.featured
494
+ docs.should be_kind_of(Array)
495
+ docs.first.should be_kind_of(Scribd::Document)
496
+ docs.first.access_key.should eql('abc123')
497
+ end
498
+
499
+ it "should pass options to the API" do
500
+ Scribd::API.instance.should_receive(:send_request).with('docs.featured', :foo => 'bar').and_return(@xml)
501
+ docs = Scribd::Document.featured(:foo => 'bar')
461
502
  end
462
503
  end
463
504
 
@@ -466,21 +507,20 @@ describe Scribd::Document do
466
507
  @xml = REXML::Document.new("<rsp stat='ok'><result_set><result><access_key>abc123</access_key></result><result><access_key>abc321</access_key></result></result_set></rsp>")
467
508
  end
468
509
 
469
- it "should not pass the scope parameter in the options" do
470
- Scribd::API.instance.should_receive(:send_request).with('docs.browse', hash_including(:sort => 'views', :category_id => 1, :limit => 10)).and_return(@xml)
471
- Scribd::Document.browse(:all, :sort => 'views', :category_id => 1, :limit => 10)
472
- end
473
-
474
- it "should return first result if :first is provided" do
510
+ it "should call the docs.browse method" do
475
511
  Scribd::API.instance.should_receive(:send_request).with('docs.browse', {}).and_return(@xml)
476
- docs = Scribd::Document.browse(:first)
477
- docs.should be_kind_of(Scribd::Document)
478
- docs.access_key.should eql('abc123')
512
+ docs = Scribd::Document.browse
513
+ docs.should be_kind_of(Array)
514
+ docs.first.should be_kind_of(Scribd::Document)
515
+ docs.first.access_key.should eql('abc123')
516
+ end
517
+
518
+ it "should pass options to the API" do
519
+ Scribd::API.instance.should_receive(:send_request).with('docs.browse', :foo => 'bar').and_return(@xml)
520
+ docs = Scribd::Document.browse(:foo => 'bar')
479
521
  end
480
522
  end
481
523
 
482
- it "should have an upload synonym for the create method"
483
-
484
524
  describe ".conversion_status" do
485
525
  before :each do
486
526
  @document = Scribd::Document.new(:xml => REXML::Document.new("<doc_id type='integer'>123</doc_id>"))
@@ -588,6 +628,30 @@ describe Scribd::Document do
588
628
  @document.download_url.should eql("http://www.example.com/doc.pdf")
589
629
  end
590
630
  end
631
+
632
+ describe "#grant_access" do
633
+ it "should call Scribd::Security.grant_access" do
634
+ doc = Scribd::Document.new
635
+ Scribd::Security.should_receive(:grant_access).once.with('foo', doc)
636
+ doc.grant_access('foo')
637
+ end
638
+ end
639
+
640
+ describe "#revoke_access" do
641
+ it "should call Scribd::Security.revoke_access" do
642
+ doc = Scribd::Document.new
643
+ Scribd::Security.should_receive(:revoke_access).once.with('foo', doc)
644
+ doc.revoke_access('foo')
645
+ end
646
+ end
647
+
648
+ describe "#access_list" do
649
+ it "should call Scribd::Security.document_access_list" do
650
+ doc = Scribd::Document.new
651
+ Scribd::Security.should_receive(:document_access_list).once.with(doc)
652
+ doc.access_list
653
+ end
654
+ end
591
655
  end
592
656
 
593
657
  Dir.chdir old_dir