rscribd 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,8 @@
1
+ === 1.3.0 / 2011-7-5
2
+
3
+ * Reduced memory usage for the built-in multipart-post method
4
+ * Added support for (optional) multipart-post gem by Nick Sieger (even less memory usage)
5
+
1
6
  === 1.2.0 / 2010-5-13
2
7
 
3
8
  * Added support for collections.
data/README CHANGED
@@ -1,6 +1,6 @@
1
1
  h1. rscribd
2
2
 
3
- * 1.2.0 (May 13, 2010)
3
+ * 1.3.0 (July 5, 2011)
4
4
 
5
5
  h2. DESCRIPTION:
6
6
 
@@ -53,12 +53,21 @@ h2. REQUIREMENTS:
53
53
 
54
54
  * A Scribd API account
55
55
  * Ruby 1.8 or newer, with RubyGems 1.3 or newer.
56
+ * (optional) multipart-post gem by Nick Sieger from http://github.com/nicksieger/multipart-post
56
57
 
57
58
  h2. INSTALL:
58
59
 
59
60
  * The client library is a RubyGem called *rscribd*. To install, type
60
61
  @sudo gem install rscribd@.
61
62
 
63
+ * To use the optional multipart-post gem by Nick Sieger, make sure it is available in the load path and call
64
+ <pre><code>
65
+ Scribd::API.instance.enable_multipart_post_gem
66
+
67
+ # and to stop using the multipart-post gem
68
+ Scribd::API.instance.disable_multipart_post_gem
69
+ </code></pre>
70
+
62
71
  h2. LICENSE:
63
72
 
64
73
  (The MIT License)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
@@ -83,6 +83,17 @@ module Scribd
83
83
  @key = ENV['SCRIBD_API_KEY']
84
84
  @secret = ENV['SCRIBD_API_SECRET']
85
85
  @user = User.new
86
+ disable_multipart_post_gem
87
+ end
88
+
89
+ def enable_multipart_post_gem
90
+ require 'net/http/post/multipart'
91
+ require File.expand_path('../../support/buffered_upload_io', __FILE__)
92
+ @use_multipart_post_gem = true
93
+ end
94
+
95
+ def disable_multipart_post_gem
96
+ @use_multipart_post_gem = false
86
97
  end
87
98
 
88
99
  # @private
@@ -117,6 +128,37 @@ module Scribd
117
128
  fields['api_sig'] = sign(sign_fields)
118
129
  debug("** POST parameters: #{fields.inspect}")
119
130
 
131
+ res = send_request_to_scribd(fields)
132
+
133
+ debug "** Response:"
134
+ debug(res.body)
135
+ debug "** End response"
136
+
137
+ # Convert response into XML
138
+ xml = REXML::Document.new(res.body)
139
+ raise MalformedResponseError, "The response received from the remote host could not be interpreted" unless xml.elements['/rsp']
140
+
141
+ # See if there was an error and raise an exception
142
+ if xml.elements['/rsp'].attributes['stat'] == 'fail'
143
+ # Load default code and error
144
+ code, message = -1, "Unidentified error:\n#{res.body}"
145
+
146
+ # Get actual error code and message
147
+ err = xml.elements['/rsp/error']
148
+ code, message = err.attributes['code'], err.attributes['message'] if err
149
+
150
+ # Add more data
151
+ message = "Method: #{method} Response: code=#{code} message=#{message}"
152
+
153
+ raise ResponseError.new(code), message
154
+ end
155
+
156
+ return xml
157
+ end
158
+
159
+ private
160
+
161
+ def send_request_to_scribd(fields)
120
162
  # Create the connection
121
163
  http = Net::HTTP.new(HOST, PORT)
122
164
  # TODO configure timeouts through the properties
@@ -124,8 +166,7 @@ module Scribd
124
166
  # API methods can be SLOW. Make sure this is set to something big to prevent spurious timeouts
125
167
  http.read_timeout = 15*60
126
168
 
127
- request = Net::HTTP::Post.new(REQUEST_PATH)
128
- request.multipart_params = fields
169
+ request = request_using_multipart_post_gem(fields) || request_using_supplied_multipart_post(fields)
129
170
 
130
171
  tries = TRIES
131
172
  begin
@@ -141,35 +182,32 @@ module Scribd
141
182
  end
142
183
  raise $!
143
184
  end
144
-
145
- debug "** Response:"
146
- debug(res.body)
147
- debug "** End response"
148
185
 
149
- # Convert response into XML
150
- xml = REXML::Document.new(res.body)
151
- raise MalformedResponseError, "The response received from the remote host could not be interpreted" unless xml.elements['/rsp']
186
+ ensure
187
+ http.finish if http && http.started?
188
+ end
152
189
 
153
- # See if there was an error and raise an exception
154
- if xml.elements['/rsp'].attributes['stat'] == 'fail'
155
- # Load default code and error
156
- code, message = -1, "Unidentified error:\n#{res.body}"
190
+ def request_using_supplied_multipart_post(fields)
191
+ request = Net::HTTP::Post.new(REQUEST_PATH)
192
+ request.multipart_params = fields
193
+ request
194
+ end
157
195
 
158
- # Get actual error code and message
159
- err = xml.elements['/rsp/error']
160
- code, message = err.attributes['code'], err.attributes['message'] if err
196
+ def request_using_multipart_post_gem(fields)
197
+ return nil unless @use_multipart_post_gem
161
198
 
162
- # Add more data
163
- message = "Method: #{method} Response: code=#{code} message=#{message}"
199
+ fields = fields.dup
200
+ original_file_value = fields['file']
201
+ if original_file_value
202
+ filename = File.basename(original_file_value.path)
203
+ mime_types = MIME::Types.of(filename)
204
+ mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
164
205
 
165
- raise ResponseError.new(code), message
206
+ fields['file'] = BufferedUploadIO.new(original_file_value, mime_type, filename)
166
207
  end
167
-
168
- return xml
208
+ Net::HTTP::Post::Multipart.new(REQUEST_PATH, fields)
169
209
  end
170
210
 
171
- private
172
-
173
211
  # FIXME: Since we don't need XMLRPC, the exception could be different
174
212
  # TODO: It would probably be better if we wrapped the fault
175
213
  # in something more meaningful. At the very least, a broad
@@ -228,4 +266,5 @@ module Scribd
228
266
  $stderr.puts(str) if @debug
229
267
  end
230
268
  end
269
+
231
270
  end
@@ -77,7 +77,7 @@ module Scribd
77
77
 
78
78
  def children
79
79
  return @children if @children
80
- response = API.instance.send_request('docs.getCategories', :category_id => self.id)
80
+ response = API.instance.send_request('docs.getCategories', :category_id => self.scribd_id)
81
81
  children = Array.new
82
82
  response.get_elements('/rsp/result_set/result').each do |res|
83
83
  children << Category.new(:xml => res)
@@ -101,7 +101,7 @@ module Scribd
101
101
  # category.browse(:sort => 'views', :category_id => 1, :limit => 10)
102
102
 
103
103
  def browse(options={})
104
- response = API.instance.send_request('docs.browse', options.merge(:category_id => self.id))
104
+ response = API.instance.send_request('docs.browse', options.merge(:category_id => self.scribd_id))
105
105
  documents = []
106
106
  response.elements['/rsp/result_set'].elements.each do |doc|
107
107
  documents << Document.new(:xml => doc)
@@ -386,6 +386,61 @@ module Scribd
386
386
  Scribd::Security.document_access_list(self)
387
387
  end
388
388
 
389
+ # Returns a URL for a thumbnail image of this document.
390
+ #
391
+ # @param [Hash] options Options for customizing the thumbnail image.
392
+ # @option options [Fixnum] :page (1) The page number to generate a thumbnail
393
+ # of.
394
+ # @option options [Fixnum] :width The width of the image, in pixels.
395
+ # @option options [Fixnum] :height The height of the image, in pixels.
396
+ # @option options [Array<Fixnum>] :size A two-element array consisting of
397
+ # the width and height of the image, in pixels.
398
+ # @return [String] The URL of the thumbnail image.
399
+ # @raise [ArgumentError] If @:width@ is specified but @:height@ is not, or
400
+ # vice versa.
401
+ # @raise [ArgumentError] If @:width@ and @:size@ are both specified.
402
+ # @raise [ArgumentError] If @:size@ is not a two-item array.
403
+
404
+ def thumbnail_url(options={})
405
+ self.class.thumbnail_url self.id, options
406
+ end
407
+
408
+ # Returns a URL for a thumbnail image of a given document. The document must
409
+ # be public, or you must own it.
410
+ #
411
+ # @param [Fixnum] id The document's ID on the Scribd website.
412
+ # @param [Hash] options Options for customizing the thumbnail image.
413
+ # @option options [Fixnum] :page (1) The page number to generate a thumbnail
414
+ # of.
415
+ # @option options [Fixnum] :width The width of the image, in pixels.
416
+ # @option options [Fixnum] :height The height of the image, in pixels.
417
+ # @option options [Array<Fixnum>] :size A two-element array consisting of
418
+ # the width and height of the image, in pixels.
419
+ # @return [String] The URL of the thumbnail image.
420
+ # @raise [ArgumentError] If @:width@ is specified but @:height@ is not, or
421
+ # vice versa.
422
+ # @raise [ArgumentError] If @:width@ and @:size@ are both specified.
423
+ # @raise [ArgumentError] If @:size@ is not a two-item array.
424
+
425
+ def self.thumbnail_url(id, options={})
426
+ w = h = nil
427
+ if (options[:width] or options[:height]) and options[:size] then
428
+ raise ArgumentError, "Cannot specify both width/height and size"
429
+ elsif options[:width] and options[:height] then
430
+ w = options[:width]
431
+ h = options[:height]
432
+ elsif options[:size] then
433
+ raise ArgumentError, "Size option must be a two-element array" unless options[:size].kind_of?(Array) and options[:size].size == 2
434
+ w = options[:size].first
435
+ h = options[:size].last
436
+ elsif options[:width] or options[:height] then
437
+ raise ArgumentError, "Must specify both width and height, or neither"
438
+ end
439
+
440
+ response = API.instance.send_request('thumbnail.get', { :doc_id => id, :width => w, :height => h, :page => options[:page] }.compact)
441
+ response.elements['/rsp/thumbnail_url'].text
442
+ end
443
+
389
444
  # @return The @document_id@ attribute.
390
445
 
391
446
  def id
@@ -45,6 +45,11 @@ module Scribd
45
45
  @created = false
46
46
  @attributes = Hash.new
47
47
  end
48
+
49
+ # Return the Scribd ID for a resource, so as not to conflict with object.id
50
+ def scribd_id
51
+ @attributes[:id]
52
+ end
48
53
 
49
54
  # Creates a new instance with the given attributes, saves it immediately,
50
55
  # and returns it. You should call its {#created?} method if you need to
@@ -0,0 +1,12 @@
1
+ # while c = File.read(max_size); end # still reads the whole file into memory
2
+ # buffer = ''; while c = File.read(max_size, buffer ); end # reuses a string variable to reduce memory usage
3
+ class BufferedUploadIO < UploadIO
4
+ def initialize(*args)
5
+ super(*args)
6
+ @buffer = ''
7
+ end
8
+
9
+ def read(amount, buffer = @buffer)
10
+ @io.read(amount, buffer)
11
+ end
12
+ end
@@ -14,6 +14,14 @@ class Hash
14
14
  options
15
15
  end
16
16
  end unless method_defined?(:stringify_keys)
17
+
18
+ def compact
19
+ reject { |key, val| val.nil? }
20
+ end
21
+
22
+ def compact!
23
+ delete_if { |key, val| val.nil? }
24
+ end
17
25
  end
18
26
 
19
27
  # @private
@@ -14,24 +14,25 @@ module Net
14
14
  boundary_token = [Array.new(8) {rand(256)}].join
15
15
  self.content_type = "multipart/form-data; boundary=#{boundary_token}"
16
16
  boundary_marker = "--#{boundary_token}\r\n"
17
- self.body = param_hash.map do |param_name, param_value|
18
- boundary_marker + case param_value
17
+ self.body = param_hash.inject('') do |memo, (param_name, param_value)|
18
+ memo << boundary_marker
19
+ case param_value
19
20
  when File
20
- file_to_multipart(param_name, param_value)
21
+ file_to_multipart(memo, param_name, param_value)
21
22
  else
22
- text_to_multipart(param_name, param_value.to_s)
23
+ memo << text_to_multipart(param_name, param_value.to_s)
23
24
  end
24
- end.join('') + "--#{boundary_token}--\r\n"
25
+ end << "--#{boundary_token}--\r\n"
25
26
  end
26
27
 
27
28
  protected
28
- def file_to_multipart(key,file)
29
+ def file_to_multipart(memo, key,file)
29
30
  filename = File.basename(file.path)
30
31
  mime_types = MIME::Types.of(filename)
31
32
  mime_type = mime_types.empty? ? "application/octet-stream" : mime_types.first.content_type
32
- part = %Q|Content-Disposition: form-data; name="#{key}"; filename="#{filename}"\r\n|
33
- part += "Content-Transfer-Encoding: binary\r\n"
34
- part += "Content-Type: #{mime_type}\r\n\r\n#{file.read}\r\n"
33
+ memo << %Q|Content-Disposition: form-data; name="#{key}"; filename="#{filename}"\r\n|
34
+ memo << "Content-Transfer-Encoding: binary\r\n"
35
+ memo << "Content-Type: #{mime_type}\r\n\r\n#{file.read}\r\n"
35
36
  end
36
37
 
37
38
  def text_to_multipart(key,value)
@@ -1,74 +1,63 @@
1
1
  # Generated by jeweler
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rscribd}
8
- s.version = "1.2.0"
8
+ s.version = "1.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tim Morgan", "Jared Friedman", "Mike Watts"]
12
- s.date = %q{2010-05-13}
12
+ s.date = %q{2011-07-06}
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
14
  s.email = %q{api@scribd.com}
15
15
  s.extra_rdoc_files = [
16
16
  "README"
17
17
  ]
18
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"
19
+ "History.txt",
20
+ "README",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "lib/rscribd.rb",
24
+ "lib/scribd/api.rb",
25
+ "lib/scribd/category.rb",
26
+ "lib/scribd/collection.rb",
27
+ "lib/scribd/document.rb",
28
+ "lib/scribd/errors.rb",
29
+ "lib/scribd/resource.rb",
30
+ "lib/scribd/security.rb",
31
+ "lib/scribd/user.rb",
32
+ "lib/support/buffered_upload_io.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/spec_helper.rb",
48
+ "spec/user_spec.rb"
48
49
  ]
49
50
  s.homepage = %q{http://www.scribd.com/developers}
50
- s.rdoc_options = ["--charset=UTF-8"]
51
51
  s.require_paths = ["lib"]
52
52
  s.rubyforge_project = %q{rscribd}
53
- s.rubygems_version = %q{1.3.6}
53
+ s.rubygems_version = %q{1.3.7}
54
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
55
 
67
56
  if s.respond_to? :specification_version then
68
57
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
69
58
  s.specification_version = 3
70
59
 
71
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
60
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
72
61
  s.add_runtime_dependency(%q<mime-types>, [">= 0"])
73
62
  s.add_development_dependency(%q<rspec>, [">= 0"])
74
63
  s.add_development_dependency(%q<yard>, [">= 0"])
@@ -1,6 +1,4 @@
1
- old_dir = Dir.getwd
2
- Dir.chdir(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rscribd'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Scribd::API do
6
4
  it "should be a singleton" do
@@ -127,5 +125,3 @@ Content-Disposition: form-data; name=#{key.to_s.inspect}
127
125
  Scribd::API.instance.user.should_not be_nil
128
126
  end
129
127
  end
130
-
131
- Dir.chdir old_dir
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  CATEGORY = Proc.new { |id, name, children|
2
4
  id ||= rand(1000)
3
5
  name ||= "Test Category #{id}"
@@ -42,7 +44,7 @@ describe Scribd::Category do
42
44
  end
43
45
 
44
46
  context "attributes" do
45
- its(:id) { should eql('12') }
47
+ its(:scribd_id) { should eql('12') }
46
48
  its(:name) { should eql('test') }
47
49
  end
48
50
 
@@ -53,7 +55,7 @@ describe Scribd::Category do
53
55
  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
56
  category.children.should be_kind_of(Array)
55
57
  category.children.first.should be_kind_of(Scribd::Category)
56
- category.children.first.id.should eql('100')
58
+ category.children.first.scribd_id.should eql('100')
57
59
  category.children.first.name.should eql('Test Category 100')
58
60
  category.children.first.children_preloaded?.should be_false
59
61
  category.children.first.parent.should eql(category)
@@ -76,7 +78,7 @@ describe Scribd::Category do
76
78
 
77
79
  describe :all do
78
80
  before :each do
79
- @response = REXML::Document.new(RESULT.call).root
81
+ @response = REXML::Document.new(RESULT.call(CATEGORY_TAG.call)).root
80
82
  end
81
83
 
82
84
  it "should send an API request to docs.getCategories" do
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe Scribd::Collection do
2
4
  before :each do
3
5
  Scribd::API.instance.key = 'test key'
@@ -1,6 +1,4 @@
1
- old_dir = Dir.getwd
2
- Dir.chdir(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rscribd'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Scribd::Document do
6
4
  before :each do
@@ -68,6 +66,7 @@ describe Scribd::Document do
68
66
  @response = mock('Net::HTTPResponse @response')
69
67
  @response.stub!(:body).and_return "<rsp stat='ok'></rsp>"
70
68
  @http.stub!(:request).and_return(@response)
69
+ @http.stub!(:started?).and_return(false)
71
70
  Net::HTTP.stub!(:new).and_return(@http)
72
71
  end
73
72
 
@@ -652,6 +651,77 @@ describe Scribd::Document do
652
651
  doc.access_list
653
652
  end
654
653
  end
654
+
655
+ describe "#thumbnail_url" do
656
+ before :each do
657
+ @doc = Scribd::Document.new(:doc_id => 123)
658
+ end
659
+
660
+ it "should call Scribd::Document.thumbnail_url" do
661
+ Scribd::Document.should_receive(:thumbnail_url).once.with(123, {})
662
+ @doc.thumbnail_url
663
+ end
664
+
665
+ it "should pass options" do
666
+ Scribd::Document.should_receive(:thumbnail_url).once.with(123, { :page => 10 })
667
+ @doc.thumbnail_url(:page => 10)
668
+ end
669
+ end
670
+
671
+ describe ".thumbnail_url" do
672
+ before :each do
673
+ @url = "http://imgv2-2.scribdassets.com/img/word_document/1/111x142/ff94c77a69/1277782307"
674
+ @response = REXML::Document.new(<<-EOF
675
+ <?xml version="1.0" encoding="UTF-8"?>
676
+ <rsp stat="ok">
677
+ <thumbnail_url>#{@url}</thumbnail_url>
678
+ </rsp>
679
+ EOF
680
+ )
681
+ end
682
+
683
+ it "should raise an exception if both width/height and size are specified" do
684
+ Scribd::API.instance.stub!(:send_request).and_return(@response)
685
+ lambda { Scribd::Document.thumbnail_url(123, :width => 123, :size => [ 1, 2 ]) }.should raise_error(ArgumentError)
686
+ lambda { Scribd::Document.thumbnail_url(123, :height => 123, :size => [ 1, 2 ]) }.should raise_error(ArgumentError)
687
+ lambda { Scribd::Document.thumbnail_url(123, :width => 123, :height => 321, :size => [ 1, 2 ]) }.should raise_error(ArgumentError)
688
+ end
689
+
690
+ it "should raise an exception if size is not an array" do
691
+ Scribd::API.instance.stub!(:send_request).and_return(@response)
692
+ lambda { Scribd::Document.thumbnail_url(123, :size => 123) }.should raise_error(ArgumentError)
693
+ end
694
+
695
+ it "should raise an exception if size is not 2 elements long" do
696
+ Scribd::API.instance.stub!(:send_request).and_return(@response)
697
+ lambda { Scribd::Document.thumbnail_url(123, :size => [ 1 ]) }.should raise_error(ArgumentError)
698
+ lambda { Scribd::Document.thumbnail_url(123, :size => [ 1, 2, 3 ]) }.should raise_error(ArgumentError)
699
+ end
700
+
701
+ it "should raise an exception if either width xor height is specified" do
702
+ Scribd::API.instance.stub!(:send_request).and_return(@response)
703
+ lambda { Scribd::Document.thumbnail_url(123, :width => 123) }.should raise_error(ArgumentError)
704
+ lambda { Scribd::Document.thumbnail_url(123, :height => 123) }.should raise_error(ArgumentError)
705
+ end
706
+
707
+ it "should call the thumbnail.get API method" do
708
+ Scribd::API.instance.should_receive(:send_request).once.with('thumbnail.get', :doc_id => 123).and_return(@response)
709
+ Scribd::Document.thumbnail_url(123).should eql(@url)
710
+ end
711
+
712
+ it "should pass the width and height" do
713
+ Scribd::API.instance.should_receive(:send_request).once.with('thumbnail.get', :doc_id => 123, :width => 2, :height => 4).and_return(@response)
714
+ Scribd::Document.thumbnail_url(123, :width => 2, :height => 4)
715
+ end
716
+
717
+ it "should pass a size" do
718
+ Scribd::API.instance.should_receive(:send_request).once.with('thumbnail.get', :doc_id => 123, :width => 2, :height => 4).and_return(@response)
719
+ Scribd::Document.thumbnail_url(123, :size => [ 2, 4 ])
720
+ end
721
+
722
+ it "should pass the page number" do
723
+ Scribd::API.instance.should_receive(:send_request).once.with('thumbnail.get', :doc_id => 123, :page => 10).and_return(@response)
724
+ Scribd::Document.thumbnail_url(123, :page => 10)
725
+ end
726
+ end
655
727
  end
656
-
657
- Dir.chdir old_dir
@@ -1,6 +1,4 @@
1
- old_dir = Dir.getwd
2
- Dir.chdir(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rscribd'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Scribd::ResponseError do
6
4
  it "should set the code attribute on initialization" do
@@ -8,5 +6,3 @@ describe Scribd::ResponseError do
8
6
  error.code.should eql(123)
9
7
  end
10
8
  end
11
-
12
- Dir.chdir old_dir
@@ -1,6 +1,4 @@
1
- old_dir = Dir.getwd
2
- Dir.chdir(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rscribd'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Scribd::Resource do
6
4
  describe "initialized from attributes" do
@@ -122,5 +120,3 @@ describe Scribd::Resource do
122
120
  end
123
121
  end
124
122
  end
125
-
126
- Dir.chdir old_dir
@@ -1,6 +1,4 @@
1
- old_dir = Dir.getwd
2
- Dir.chdir(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rscribd'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Symbol do
6
4
  it "should define a to_proc method" do
@@ -31,5 +29,3 @@ describe Array do
31
29
  [ [ 1, 2], [3, 4] ].to_hsh.should == { 1 => 2, 3 => 4 }
32
30
  end
33
31
  end
34
-
35
- Dir.chdir old_dir
@@ -1,3 +1,5 @@
1
+ require 'spec_helper'
2
+
1
3
  describe Scribd::Security do
2
4
  before :each do
3
5
  @document = Scribd::Document.new(:xml => REXML::Document.new('<result><doc_id>123</doc_id></result>').root)
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ $LOAD_PATH.unshift File.expand_path('..', __FILE__)
3
+
4
+ require 'rscribd'
@@ -1,6 +1,4 @@
1
- old_dir = Dir.getwd
2
- Dir.chdir(File.join(File.dirname(__FILE__), '..', 'lib'))
3
- require 'rscribd'
1
+ require 'spec_helper'
4
2
 
5
3
  describe Scribd::User do
6
4
  describe "initialized from attributes" do
@@ -279,5 +277,3 @@ describe Scribd::User do
279
277
  end
280
278
  end
281
279
  end
282
-
283
- Dir.chdir old_dir
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rscribd
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 1
7
- - 2
8
+ - 3
8
9
  - 0
9
- version: 1.2.0
10
+ version: 1.3.0
10
11
  platform: ruby
11
12
  authors:
12
13
  - Tim Morgan
@@ -16,16 +17,18 @@ autorequire:
16
17
  bindir: bin
17
18
  cert_chain: []
18
19
 
19
- date: 2010-05-13 00:00:00 -07:00
20
+ date: 2011-07-06 00:00:00 -06:00
20
21
  default_executable:
21
22
  dependencies:
22
23
  - !ruby/object:Gem::Dependency
23
24
  name: mime-types
24
25
  prerelease: false
25
26
  requirement: &id001 !ruby/object:Gem::Requirement
27
+ none: false
26
28
  requirements:
27
29
  - - ">="
28
30
  - !ruby/object:Gem::Version
31
+ hash: 3
29
32
  segments:
30
33
  - 0
31
34
  version: "0"
@@ -35,9 +38,11 @@ dependencies:
35
38
  name: rspec
36
39
  prerelease: false
37
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
38
42
  requirements:
39
43
  - - ">="
40
44
  - !ruby/object:Gem::Version
45
+ hash: 3
41
46
  segments:
42
47
  - 0
43
48
  version: "0"
@@ -47,9 +52,11 @@ dependencies:
47
52
  name: yard
48
53
  prerelease: false
49
54
  requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
50
56
  requirements:
51
57
  - - ">="
52
58
  - !ruby/object:Gem::Version
59
+ hash: 3
53
60
  segments:
54
61
  - 0
55
62
  version: "0"
@@ -64,7 +71,6 @@ extensions: []
64
71
  extra_rdoc_files:
65
72
  - README
66
73
  files:
67
- - .gitignore
68
74
  - History.txt
69
75
  - README
70
76
  - Rakefile
@@ -78,6 +84,7 @@ files:
78
84
  - lib/scribd/resource.rb
79
85
  - lib/scribd/security.rb
80
86
  - lib/scribd/user.rb
87
+ - lib/support/buffered_upload_io.rb
81
88
  - lib/support/extensions.rb
82
89
  - lib/support/multipart_hack.rb
83
90
  - rscribd.gemspec
@@ -92,44 +99,41 @@ files:
92
99
  - spec/resource_spec.rb
93
100
  - spec/rscribd_spec.rb
94
101
  - spec/security_spec.rb
102
+ - spec/spec_helper.rb
95
103
  - spec/user_spec.rb
96
104
  has_rdoc: true
97
105
  homepage: http://www.scribd.com/developers
98
106
  licenses: []
99
107
 
100
108
  post_install_message:
101
- rdoc_options:
102
- - --charset=UTF-8
109
+ rdoc_options: []
110
+
103
111
  require_paths:
104
112
  - lib
105
113
  required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
106
115
  requirements:
107
116
  - - ">="
108
117
  - !ruby/object:Gem::Version
118
+ hash: 3
109
119
  segments:
110
120
  - 0
111
121
  version: "0"
112
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
113
124
  requirements:
114
125
  - - ">="
115
126
  - !ruby/object:Gem::Version
127
+ hash: 3
116
128
  segments:
117
129
  - 0
118
130
  version: "0"
119
131
  requirements: []
120
132
 
121
133
  rubyforge_project: rscribd
122
- rubygems_version: 1.3.6
134
+ rubygems_version: 1.3.7
123
135
  signing_key:
124
136
  specification_version: 3
125
137
  summary: Ruby client library for the Scribd API
126
- test_files:
127
- - spec/api_spec.rb
128
- - spec/category_spec.rb
129
- - spec/collection_spec.rb
130
- - spec/document_spec.rb
131
- - spec/error_spec.rb
132
- - spec/resource_spec.rb
133
- - spec/rscribd_spec.rb
134
- - spec/security_spec.rb
135
- - spec/user_spec.rb
138
+ test_files: []
139
+
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- doc
2
- pkg
3
- .idea
4
- .DS_Store
5
- .yardoc