rscribd 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.0.2 / 2009-7-9
2
+
3
+ * Added support for getting information about the API user when no other user
4
+ has been logged in.
5
+ * Files to upload can now be specified as both file paths and File streams.
6
+
1
7
  === 1.0.1 / 2009-3-4
2
8
 
3
9
  * Fixed a bug that would cause some API parameters to not be sent when uploading
data/README.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  = rscribd
2
2
 
3
- * 1.0.1 (Mar 4, 2009)
3
+ * 1.0.2 (July 9, 2009)
4
4
 
5
5
  == DESCRIPTION:
6
6
 
data/Rakefile CHANGED
@@ -2,7 +2,8 @@ require 'rubygems'
2
2
  require 'hoe'
3
3
  require 'spec/rake/spectask'
4
4
 
5
- Hoe.new('rscribd', '1.0.1') do |p|
5
+ Hoe.spec('rscribd') do |p|
6
+ p.version = '1.0.2'
6
7
  p.rubyforge_name = 'rscribd'
7
8
  p.author = 'Jared Friedman, Tim Morgan'
8
9
  p.email = 'api@scribd.com'
@@ -14,11 +15,11 @@ Hoe.new('rscribd', '1.0.1') do |p|
14
15
  p.remote_rdoc_dir = ''
15
16
  end
16
17
 
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
18
+ # desc "Verify gem specs"
19
+ # Spec::Rake::SpecTask.new do |t|
20
+ # t.spec_files = FileList['spec/*.rb']
21
+ # t.spec_opts = [ '-cfs' ]
22
+ # end
22
23
 
23
24
  namespace :github do
24
25
  desc "Prepare for GitHub gem packaging"
data/lib/scribdapi.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'singleton'
2
- require 'md5'
2
+ require 'digest/md5'
3
3
  require 'rexml/document'
4
4
 
5
5
  module Scribd
@@ -70,6 +70,7 @@ module Scribd
70
70
  @asychronous = false
71
71
  @key = ENV['SCRIBD_API_KEY']
72
72
  @secret = ENV['SCRIBD_API_SECRET']
73
+ @user = User.new
73
74
  end
74
75
 
75
76
  def send_request(method, fields={}) #:nodoc:
@@ -203,7 +204,7 @@ module Scribd
203
204
  # signature
204
205
  #
205
206
  def sign(args)
206
- return MD5.md5(@secret + args.sort.flatten.join).to_s
207
+ return Digest::MD5.hexdigest(@secret + args.sort.flatten.join).to_s
207
208
  end
208
209
 
209
210
  # Outputs whatever is given into the $stderr if debugging is enabled.
data/lib/scribddoc.rb CHANGED
@@ -100,9 +100,12 @@ module Scribd
100
100
 
101
101
  # Make a request form
102
102
  fields = @attributes.dup
103
- if @attributes[:file] then
103
+ if file = @attributes[:file] then
104
104
  fields.delete :file
105
- ext = @attributes[:file].split('.').last unless @attributes[:file].index('.').nil?
105
+ is_file_object = file.is_a?(File)
106
+ file_path = is_file_object ? file.path : file
107
+ ext = File.extname(file_path).gsub(/^\./, '')
108
+ ext = nil if ext == ''
106
109
  fields[:doc_type] = fields.delete(:type)
107
110
  fields[:doc_type] ||= ext
108
111
  fields[:doc_type].downcase! if fields[:doc_type]
@@ -122,10 +125,10 @@ module Scribd
122
125
  fields[:url] = @attributes[:file]
123
126
  response = API.instance.send_request 'docs.uploadFromUrl', fields
124
127
  elsif uri.kind_of? URI::Generic or uri.nil? then
125
- File.open(@attributes[:file]) do |file|
126
- fields[:file] = file
127
- response = API.instance.send_request 'docs.upload', fields
128
- end
128
+ file_obj = is_file_object ? file : File.open(file, 'r')
129
+ fields[:file] = file_obj
130
+ response = API.instance.send_request 'docs.upload', fields
131
+ file_obj.close unless is_file_object
129
132
  end
130
133
  end
131
134
 
@@ -2,9 +2,8 @@
2
2
  # http://pivots.pivotallabs.com/users/damon/blog/articles/227-standup-04-27-07-testing-file-uploads
3
3
 
4
4
  require 'net/https'
5
- require "rubygems"
6
- require "mime/types" # Requires gem install mime-types
7
- require "base64"
5
+ require 'rubygems'
6
+ require 'mime/types' # Requires gem install mime-types
8
7
  require 'cgi'
9
8
 
10
9
  module Net #:nodoc:all
data/sample/01_upload.rb CHANGED
@@ -4,18 +4,44 @@ require 'rubygems'
4
4
  require 'rscribd'
5
5
 
6
6
  # Use your API key / secret here
7
- api_key = '4lj2rs4duuv4013y2qbw3'
8
- api_secret = 'sec-twkc39qf22dmplhy3j4flvzet'
7
+ api_key = ''
8
+ api_secret = ''
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 'riscfuture2', 'felicia'
17
- doc = Scribd::Document.new :file => 'sample/test.txt', :flooza => 'booza'
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
18
39
  doc.save
40
+
41
+ # Delete the uploaded document
42
+ print "Deleting a document ... "
43
+ doc.destroy
44
+ puts "Done doc_id=#{doc.id}"
19
45
  rescue Scribd::ResponseError => e
20
46
  puts "failed code=#{e.code} error='#{e.message}'"
21
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rscribd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared Friedman, Tim Morgan
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-04 00:00:00 -08:00
12
+ date: 2009-07-09 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -30,9 +30,13 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 1.9.0
33
+ version: 2.3.1
34
34
  version:
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
35
+ description: |-
36
+ This gem provides a simple and powerful library for the Scribd API, allowing you
37
+ to write Ruby applications or Ruby on Rails websites that upload, convert,
38
+ display, search, and control documents in many formats. For more information on
39
+ the Scribd platform, visit http://www.scribd.com/publisher
36
40
  email: api@scribd.com
37
41
  executables: []
38
42
 
@@ -60,6 +64,8 @@ files:
60
64
  - sample/test.txt
61
65
  has_rdoc: true
62
66
  homepage:
67
+ licenses: []
68
+
63
69
  post_install_message:
64
70
  rdoc_options:
65
71
  - --main
@@ -81,9 +87,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
87
  requirements: []
82
88
 
83
89
  rubyforge_project: rscribd
84
- rubygems_version: 1.3.1
90
+ rubygems_version: 1.3.4
85
91
  signing_key:
86
- specification_version: 2
92
+ specification_version: 3
87
93
  summary: Ruby client library for the Scribd API
88
94
  test_files: []
89
95