rscribd 1.2.0 → 1.3.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e4c7c101fe64a581936479c3682375f1f87b2dc74d76f35f1ce1f20e9313edd6
4
+ data.tar.gz: 8ed9e32d5a6c90dce0631d43250585de562daa43c312a9db2ac830efdb6da1a8
5
+ SHA512:
6
+ metadata.gz: 50fe6a9f006bf2c1dedaeae35a02f5e4d8a3ae6932ff653dfb5af92e6dd8a80f0d923c2204adc0e9236f9810bd1ac82cc16054b343ee685211987976d1bb83b8
7
+ data.tar.gz: f312b77398e661295ddc889f16d6663fb80609a0295769db296811e985c6f484eb82459803bc4edae24cc092c25d0e873ccf0f6b20ddaaf507f24be7eeda8927
data/History.txt CHANGED
@@ -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
data/lib/scribd/api.rb CHANGED
@@ -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)
data/rscribd.gemspec CHANGED
@@ -1,74 +1,73 @@
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.1"
9
+
10
+ s.post_install_message = <<~MSG
11
+
12
+ ⚠️ DEPRECATED: rscribd is no longer maintained.
13
+
14
+ The Scribd developer/upload API has been retired by Scribd; this gem can no longer connect to a live service.
15
+
16
+ This is the final release. No further updates are planned.
17
+
18
+ MSG
9
19
 
10
20
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
21
  s.authors = ["Tim Morgan", "Jared Friedman", "Mike Watts"]
12
- s.date = %q{2010-05-13}
22
+ s.date = %q{2011-07-06}
13
23
  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
24
  s.email = %q{api@scribd.com}
15
25
  s.extra_rdoc_files = [
16
26
  "README"
17
27
  ]
18
28
  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"
29
+ "History.txt",
30
+ "README",
31
+ "Rakefile",
32
+ "VERSION",
33
+ "lib/rscribd.rb",
34
+ "lib/scribd/api.rb",
35
+ "lib/scribd/category.rb",
36
+ "lib/scribd/collection.rb",
37
+ "lib/scribd/document.rb",
38
+ "lib/scribd/errors.rb",
39
+ "lib/scribd/resource.rb",
40
+ "lib/scribd/security.rb",
41
+ "lib/scribd/user.rb",
42
+ "lib/support/buffered_upload_io.rb",
43
+ "lib/support/extensions.rb",
44
+ "lib/support/multipart_hack.rb",
45
+ "rscribd.gemspec",
46
+ "sample/01_upload.rb",
47
+ "sample/02_user.rb",
48
+ "sample/test.txt",
49
+ "spec/api_spec.rb",
50
+ "spec/category_spec.rb",
51
+ "spec/collection_spec.rb",
52
+ "spec/document_spec.rb",
53
+ "spec/error_spec.rb",
54
+ "spec/resource_spec.rb",
55
+ "spec/rscribd_spec.rb",
56
+ "spec/security_spec.rb",
57
+ "spec/spec_helper.rb",
58
+ "spec/user_spec.rb"
48
59
  ]
49
60
  s.homepage = %q{http://www.scribd.com/developers}
50
- s.rdoc_options = ["--charset=UTF-8"]
51
61
  s.require_paths = ["lib"]
52
62
  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
- ]
63
+ s.rubygems_version = %q{1.3.7}
64
+ s.summary = %q{[DEPRECATED] Ruby client library for the Scribd API}
66
65
 
67
66
  if s.respond_to? :specification_version then
68
67
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
69
68
  s.specification_version = 3
70
69
 
71
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
70
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
72
71
  s.add_runtime_dependency(%q<mime-types>, [">= 0"])
73
72
  s.add_development_dependency(%q<rspec>, [">= 0"])
74
73
  s.add_development_dependency(%q<yard>, [">= 0"])
data/spec/api_spec.rb CHANGED
@@ -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
data/spec/error_spec.rb CHANGED
@@ -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
data/spec/rscribd_spec.rb CHANGED
@@ -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'
data/spec/user_spec.rb CHANGED
@@ -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,70 +1,66 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rscribd
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 1
7
- - 2
8
- - 0
9
- version: 1.2.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.1
10
5
  platform: ruby
11
- authors:
6
+ authors:
12
7
  - Tim Morgan
13
8
  - Jared Friedman
14
9
  - Mike Watts
15
- autorequire:
16
10
  bindir: bin
17
11
  cert_chain: []
18
-
19
- date: 2010-05-13 00:00:00 -07:00
20
- default_executable:
21
- dependencies:
22
- - !ruby/object:Gem::Dependency
12
+ date: 2011-07-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
23
15
  name: mime-types
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
- requirements:
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
27
18
  - - ">="
28
- - !ruby/object:Gem::Version
29
- segments:
30
- - 0
31
- version: "0"
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
32
21
  type: :runtime
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: rspec
36
22
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
38
- requirements:
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
39
25
  - - ">="
40
- - !ruby/object:Gem::Version
41
- segments:
42
- - 0
43
- version: "0"
26
+ - !ruby/object:Gem::Version
27
+ version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rspec
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
44
35
  type: :development
45
- version_requirements: *id002
46
- - !ruby/object:Gem::Dependency
47
- name: yard
48
36
  prerelease: false
49
- requirement: &id003 !ruby/object:Gem::Requirement
50
- requirements:
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
51
39
  - - ">="
52
- - !ruby/object:Gem::Version
53
- segments:
54
- - 0
55
- version: "0"
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: yard
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
56
49
  type: :development
57
- version_requirements: *id003
58
- description: The official Ruby gem for the Scribd API. Scribd is a document-sharing website allowing people to upload and view documents online.
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ description: The official Ruby gem for the Scribd API. Scribd is a document-sharing
57
+ website allowing people to upload and view documents online.
59
58
  email: api@scribd.com
60
59
  executables: []
61
-
62
60
  extensions: []
63
-
64
- extra_rdoc_files:
61
+ extra_rdoc_files:
65
62
  - README
66
- files:
67
- - .gitignore
63
+ files:
68
64
  - History.txt
69
65
  - README
70
66
  - Rakefile
@@ -78,6 +74,7 @@ files:
78
74
  - lib/scribd/resource.rb
79
75
  - lib/scribd/security.rb
80
76
  - lib/scribd/user.rb
77
+ - lib/support/buffered_upload_io.rb
81
78
  - lib/support/extensions.rb
82
79
  - lib/support/multipart_hack.rb
83
80
  - rscribd.gemspec
@@ -92,44 +89,35 @@ files:
92
89
  - spec/resource_spec.rb
93
90
  - spec/rscribd_spec.rb
94
91
  - spec/security_spec.rb
92
+ - spec/spec_helper.rb
95
93
  - spec/user_spec.rb
96
- has_rdoc: true
97
94
  homepage: http://www.scribd.com/developers
98
95
  licenses: []
96
+ metadata: {}
97
+ post_install_message: |2+
99
98
 
100
- post_install_message:
101
- rdoc_options:
102
- - --charset=UTF-8
103
- require_paths:
99
+ ⚠️ DEPRECATED: rscribd is no longer maintained.
100
+
101
+ The Scribd developer/upload API has been retired by Scribd; this gem can no longer connect to a live service.
102
+
103
+ This is the final release. No further updates are planned.
104
+
105
+ rdoc_options: []
106
+ require_paths:
104
107
  - lib
105
- required_ruby_version: !ruby/object:Gem::Requirement
106
- requirements:
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
107
110
  - - ">="
108
- - !ruby/object:Gem::Version
109
- segments:
110
- - 0
111
- version: "0"
112
- required_rubygems_version: !ruby/object:Gem::Requirement
113
- requirements:
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
114
115
  - - ">="
115
- - !ruby/object:Gem::Version
116
- segments:
117
- - 0
118
- version: "0"
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
119
118
  requirements: []
120
-
121
- rubyforge_project: rscribd
122
- rubygems_version: 1.3.6
123
- signing_key:
119
+ rubygems_version: 4.0.11
124
120
  specification_version: 3
125
- 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
121
+ summary: "[DEPRECATED] Ruby client library for the Scribd API"
122
+ test_files: []
123
+ ...
data/.gitignore DELETED
@@ -1,5 +0,0 @@
1
- doc
2
- pkg
3
- .idea
4
- .DS_Store
5
- .yardoc