rscribd 0.1.2 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,19 @@
1
+ === 1.0.1 / 2009-3-4
2
+
3
+ * Fixed a bug that would cause some API parameters to not be sent when uploading
4
+ a document.
5
+
6
+ === 1.0.0 / 2008-11-26
7
+
8
+ * First release version.
9
+ * Comprehensive RSpec of all code.
10
+ * read_attributes method now works correctly.
11
+ * Uploading a document as a not-yet-created user no longer uploads it into the
12
+ default API account.
13
+ * Finding documents owned by a not-yet-created user now returns nil.
14
+ * Symbol#to_proc definedd for RScribd use in non-Rails projects.
15
+ * Minor code style improvements.
16
+
1
17
  === 0.1.2 / 2008-11-26
2
18
 
3
19
  * Happy Thanksgiving!
data/README.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  = rscribd
2
2
 
3
- * 0.1.2 (Nov 26, 2008)
3
+ * 1.0.1 (Mar 4, 2009)
4
4
 
5
5
  == DESCRIPTION:
6
6
 
data/Rakefile CHANGED
@@ -1,18 +1,28 @@
1
- # -*- ruby -*-
2
-
3
1
  require 'rubygems'
4
2
  require 'hoe'
3
+ require 'spec/rake/spectask'
5
4
 
6
- Hoe.new('rscribd', '0.1.2') do |p|
5
+ Hoe.new('rscribd', '1.0.1') do |p|
7
6
  p.rubyforge_name = 'rscribd'
8
- p.author = 'Jared Friedman'
7
+ p.author = 'Jared Friedman, Tim Morgan'
9
8
  p.email = 'api@scribd.com'
10
9
  p.summary = 'Ruby client library for the Scribd API'
11
- p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
10
+ p.description = p.paragraphs_of('README.txt', 3).join("\n\n")
12
11
  p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
13
12
  p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
14
13
  p.extra_deps << [ 'mime-types', '>0.0.0' ]
15
14
  p.remote_rdoc_dir = ''
16
15
  end
17
16
 
18
- # vim: syntax=Ruby
17
+ desc "Verify gem specs"
18
+ Spec::Rake::SpecTask.new do |t|
19
+ t.spec_files = FileList['spec/**/*.rb']
20
+ t.spec_opts = [ '-cfs' ]
21
+ end
22
+
23
+ namespace :github do
24
+ desc "Prepare for GitHub gem packaging"
25
+ task :prepare do
26
+ `rake debug_gem > rscribd.gemspec`
27
+ end
28
+ end
@@ -3,6 +3,12 @@
3
3
  module Scribd # :nodoc:
4
4
  end
5
5
 
6
+ class Symbol
7
+ def to_proc
8
+ Proc.new { |*args| args.shift.__send__(self, *args) }
9
+ end unless method_defined?(:to_proc)
10
+ end
11
+
6
12
  class Hash #:nodoc:
7
13
  # Taken from Rails, with appreciation to DHH
8
14
  def stringify_keys
@@ -99,16 +99,16 @@ module Scribd
99
99
  end
100
100
 
101
101
  # Make a request form
102
- fields = Hash.new
102
+ fields = @attributes.dup
103
103
  if @attributes[:file] then
104
+ fields.delete :file
104
105
  ext = @attributes[:file].split('.').last unless @attributes[:file].index('.').nil?
105
- fields[:doc_type] = @attributes[:type]
106
+ fields[:doc_type] = fields.delete(:type)
106
107
  fields[:doc_type] ||= ext
107
108
  fields[:doc_type].downcase! if fields[:doc_type]
108
- fields[:rev_id] = @attributes[:doc_id]
109
- fields[:access] = @attributes[:access]
109
+ fields[:rev_id] = fields.delete(:doc_id)
110
110
  end
111
- fields[:session_key] = @attributes[:owner].session_key if @attributes[:owner]
111
+ fields[:session_key] = fields.delete(:owner).session_key if fields[:owner]
112
112
  response = nil
113
113
 
114
114
  if @attributes[:file] then
@@ -166,7 +166,7 @@ module Scribd
166
166
  raise ArgumentError, "options must be a hash" unless options.kind_of? Hash
167
167
 
168
168
  docs_by_user = docs.inject(Hash.new { |hash, key| hash[key] = Array.new }) { |hash, doc| hash[doc.owner] << doc; hash }
169
- docs_by_user.each { |user, doc_list| API.instance.send_request 'docs.changeSettings', options.merge(:doc_ids => doc_list.collect { |doc| doc.id }.join(','), :session_key => user.session_key) }
169
+ docs_by_user.each { |user, doc_list| API.instance.send_request 'docs.changeSettings', options.merge(:doc_ids => doc_list.collect(&:id).join(','), :session_key => user.session_key) }
170
170
  end
171
171
 
172
172
  # === Finding by query
@@ -221,10 +221,8 @@ module Scribd
221
221
  end
222
222
  end
223
223
 
224
- # Synonym for create.
225
-
226
- def self.upload(options={})
227
- create options
224
+ class << self
225
+ alias_method :upload, :create
228
226
  end
229
227
 
230
228
  # Returns the conversion status of this document. When a document is
@@ -93,10 +93,10 @@ module Scribd
93
93
  # ignored.
94
94
 
95
95
  def read_attributes(attributes)
96
- raise ArgumentError, "Attributes must be listed in an Enumeration" unless attributes.kind_of? Enumeration
96
+ raise ArgumentError, "Attributes must be listed in an Enumeration" unless attributes.kind_of?(Enumerable)
97
97
  raise ArgumentError, "All attributes must respond to to_sym" unless attributes.all? { |a| a.respond_to? :to_sym }
98
98
  keys = attributes.map(&:to_sym)
99
- values = @attributes.values_at keys
99
+ values = @attributes.values_at(*keys)
100
100
  keys.zip(values).to_hsh
101
101
  end
102
102
 
@@ -85,6 +85,7 @@ module Scribd
85
85
  # Scribd::Document.find.
86
86
 
87
87
  def find_documents(options)
88
+ return nil unless @attributes[:session_key]
88
89
  Document.find options.merge(:scope => 'user', :session_key => @attributes[:session_key])
89
90
  end
90
91
 
@@ -92,6 +93,7 @@ module Scribd
92
93
  # belong to this user.
93
94
 
94
95
  def find_document(document_id)
96
+ return nil unless @attributes[:session_key]
95
97
  response = API.instance.send_request('docs.getSettings', { :doc_id => document_id, :session_key => @attributes[:session_key] })
96
98
  Document.new :xml => response.elements['/rsp'], :owner => self
97
99
  end
@@ -107,13 +109,12 @@ module Scribd
107
109
  # Scribd::Document.save method.
108
110
 
109
111
  def upload(options)
110
- Document.create options.merge(:owner => self)
112
+ raise NotReadyError, "User hasn't been created yet" unless created?
113
+ Document.create options.merge(:owner => self)
111
114
  end
112
115
 
113
- # Synonym for create.
114
-
115
- def self.signup(options={})
116
- create options
116
+ class << self
117
+ alias_method :signup, :create
117
118
  end
118
119
 
119
120
  # Logs into Scribd using the given username and password. This user will be
@@ -4,44 +4,18 @@ require 'rubygems'
4
4
  require 'rscribd'
5
5
 
6
6
  # Use your API key / secret here
7
- api_key = ''
8
- api_secret = ''
7
+ api_key = '4lj2rs4duuv4013y2qbw3'
8
+ api_secret = 'sec-twkc39qf22dmplhy3j4flvzet'
9
9
 
10
10
  # Create a scribd object
11
11
  Scribd::API.instance.key = api_key
12
12
  Scribd::API.instance.secret = api_secret
13
- #Scribd::API.instance.debug = true
13
+ Scribd::API.instance.debug = true
14
14
 
15
15
  begin
16
- Scribd::User.login 'LOGIN', 'PASSWORD'
17
- # Upload the document from a file
18
- print "Uploading a document ... "
19
-
20
- doc = Scribd::Document.upload(:file => 'test.txt')
21
- puts "Done doc_id=#{doc.id}, doc_access_key=#{doc.access_key}"
22
-
23
- # Poll API until conversion is complete
24
- while (doc.conversion_status == 'PROCESSING')
25
- puts "Document conversion is processing"
26
- sleep(2) # Very important to sleep to prevent a runaway loop that will get your app blocked
27
- end
28
- puts "Document conversion is complete"
29
-
30
- # Edit various options of the document
31
- # Note you can also edit options before your doc is done converting
32
- doc.title = 'This is a test doc!'
33
- doc.description = "I'm testing out the Scribd API!"
34
- doc.access = 'private'
35
- doc.language = 'en'
36
- doc.license = 'c'
37
- doc.tags = 'test,api'
38
- doc.show_ads = true
16
+ Scribd::User.login 'riscfuture2', 'felicia'
17
+ doc = Scribd::Document.new :file => 'sample/test.txt', :flooza => 'booza'
39
18
  doc.save
40
-
41
- # Delete the uploaded document
42
- print "Deleting a document ... "
43
- doc.destroy
44
- puts "Done doc_id=#{doc.id}"
45
19
  rescue Scribd::ResponseError => e
46
20
  puts "failed code=#{e.code} error='#{e.message}'"
47
21
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rscribd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
- - Jared Friedman
7
+ - Jared Friedman, Tim Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-26 00:00:00 -08:00
12
+ date: 2009-03-04 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,9 +30,9 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.8.2
33
+ version: 1.9.0
34
34
  version:
35
- description: "== DESCRIPTION: This gem provides a simple and powerful library for the Scribd API, allowing you to write Ruby applications or Ruby on Rails websites that upload, convert, display, search, and control documents in many formats. For more information on the Scribd platform, visit http://www.scribd.com/publisher == FEATURES: * Upload your documents to Scribd's servers and access them using the gem * Upload local files or from remote web sites * Search, tag, and organize documents * Associate documents with your users' accounts"
35
+ description: This gem provides a simple and powerful library for the Scribd API, allowing you to write Ruby applications or Ruby on Rails websites that upload, convert, display, search, and control documents in many formats. For more information on the Scribd platform, visit http://www.scribd.com/publisher
36
36
  email: api@scribd.com
37
37
  executables: []
38
38