rscribd 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +12 -0
- data/README.txt +3 -3
- data/Rakefile +1 -1
- data/lib/scribddoc.rb +64 -19
- data/lib/scribdresource.rb +6 -1
- data/lib/scribduser.rb +2 -2
- data/sample/02_user.rb +1 -1
- metadata +3 -3
data/History.txt
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
=== 0.1.0 / 2008-10-1
|
2
|
+
|
3
|
+
* Changed Scribd::Document.find method to take an ActiveRecord-style scope
|
4
|
+
variable (which can be :all, :first, etc.) as its first parameter. Options are
|
5
|
+
now specified as the second parameter.
|
6
|
+
* Scribd::Document.find can also be used with a single integer to find a
|
7
|
+
document by ID.
|
8
|
+
* Scribd::Document.find now takes offset and limit parameters (for scopes that
|
9
|
+
return arrays of documents).
|
10
|
+
* Added a Scribd::Document#download_url method.
|
11
|
+
* Should no longer raise an exception when logging in.
|
12
|
+
|
1
13
|
=== 0.0.5 / 2008-09-25
|
2
14
|
|
3
15
|
* Updated RScribd to work with server-side API changes.
|
data/README.txt
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
= rscribd
|
2
2
|
|
3
|
-
* 0.0
|
3
|
+
* 0.1.0 (Oct 1, 2008)
|
4
4
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
7
|
This gem provides a simple and powerful library for the Scribd API, allowing you
|
8
8
|
to write Ruby applications or Ruby on Rails websites that upload, convert,
|
9
9
|
display, search, and control documents in many formats. For more information on
|
10
|
-
the Scribd platform, visit http://www.scribd.com/
|
10
|
+
the Scribd platform, visit http://www.scribd.com/publisher
|
11
11
|
|
12
12
|
== FEATURES:
|
13
13
|
|
@@ -25,7 +25,7 @@ storage system to store your documents in accessible manner. Scribd's ad system
|
|
25
25
|
will help you monetize your documents easily.
|
26
26
|
|
27
27
|
First, you'll need to get a Scribd API account. Visit
|
28
|
-
http://www.scribd.com/
|
28
|
+
http://www.scribd.com/publisher/api to apply for a platform account.
|
29
29
|
|
30
30
|
On the Platform site you will be given an API key and secret. The API object
|
31
31
|
will need these to authenticate you:
|
data/Rakefile
CHANGED
data/lib/scribddoc.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'uri'
|
2
2
|
|
3
3
|
module Scribd
|
4
4
|
|
@@ -25,8 +25,9 @@ module Scribd
|
|
25
25
|
#
|
26
26
|
# Aside from these two attributes, you can set other attributes that affect
|
27
27
|
# how the file is displayed on Scribd. See the API documentation online for a
|
28
|
-
# list of attributes, at
|
29
|
-
# (consult the
|
28
|
+
# list of attributes, at
|
29
|
+
# http://www.scribd.com/publisher/api?method_name=docs.search (consult the
|
30
|
+
# "Result explanation" section).
|
30
31
|
#
|
31
32
|
# These attributes can be accessed or changed directly
|
32
33
|
# (<tt>doc.title = 'Title'</tt>). You must save a document after changing its
|
@@ -53,6 +54,7 @@ module Scribd
|
|
53
54
|
|
54
55
|
def initialize(options={})
|
55
56
|
super
|
57
|
+
@download_urls = Hash.new
|
56
58
|
if options[:xml] then
|
57
59
|
load_attributes(options[:xml])
|
58
60
|
@attributes[:owner] = options[:owner]
|
@@ -164,27 +166,56 @@ module Scribd
|
|
164
166
|
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) }
|
165
167
|
end
|
166
168
|
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
169
|
+
# === Finding by query
|
170
|
+
#
|
171
|
+
# This method is called with a scope and a hash of options to documents by
|
172
|
+
# their content. You must at a minimum supply a +query+ option, with a
|
173
|
+
# string that will become the full-text search query. For a list of other
|
174
|
+
# supported options, please see the online API documentation at
|
175
|
+
# http://www.scribd.com/publisher/api?method_name=docs.search
|
176
|
+
#
|
177
|
+
# The scope can be any value given for the +scope+ parameter in the above
|
178
|
+
# website, or <tt>:first</tt> to return the first result only (not an array
|
179
|
+
# of results).
|
180
|
+
#
|
181
|
+
# The +num_results+ option has been aliased as +limit+, and the +num_start+
|
182
|
+
# option has been aliased as +offset+.
|
172
183
|
#
|
173
184
|
# Documents returned from this method will have their +owner+ attributes set
|
174
185
|
# to nil.
|
186
|
+
#
|
187
|
+
# Scribd::Document.find(:all, :query => 'cats and dogs', :limit => 10)
|
188
|
+
#
|
189
|
+
# === Finding by ID
|
190
|
+
#
|
191
|
+
# Passing in simply a numerical ID loads the document with that ID. You can
|
192
|
+
# pass additional options as defined at
|
193
|
+
# httphttp://www.scribd.com/publisher/api?method_name=docs.getSettings
|
194
|
+
#
|
195
|
+
# Scribd::Document.find(108196)
|
196
|
+
#
|
197
|
+
# For now only documents that belong to the current user can be accessed in
|
198
|
+
# this manner.
|
175
199
|
|
176
|
-
def self.find(options)
|
177
|
-
|
178
|
-
raise ArgumentError, "You must specify
|
200
|
+
def self.find(scope, options={})
|
201
|
+
doc_id = scope if scope.kind_of?(Integer)
|
202
|
+
raise ArgumentError, "You must specify a query or document ID" unless options[:query] or doc_id
|
179
203
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
204
|
+
if doc_id then
|
205
|
+
options[:doc_id] = doc_id
|
206
|
+
response = API.instance.send_request('docs.getSettings', options)
|
207
|
+
return Document.new(:xml => response.elements['/rsp'])
|
208
|
+
else
|
209
|
+
options[:scope] = scope == :first ? 'all' : scope.to_s
|
210
|
+
options[:num_results] = options[:limit]
|
211
|
+
options[:num_start] = options[:offset]
|
212
|
+
response = API.instance.send_request('docs.search', options)
|
213
|
+
documents = []
|
214
|
+
response.elements['/rsp/result_set'].elements.each do |doc|
|
215
|
+
documents << Document.new(:xml => doc)
|
216
|
+
end
|
217
|
+
return scope == :first ? documents.first : documents
|
186
218
|
end
|
187
|
-
return documents
|
188
219
|
end
|
189
220
|
|
190
221
|
# Synonym for create.
|
@@ -200,7 +231,7 @@ module Scribd
|
|
200
231
|
#
|
201
232
|
# The conversion status is returned as a string. For a full list of
|
202
233
|
# conversion statuses, see the online API documentation at
|
203
|
-
# http://www.scribd.com/
|
234
|
+
# http://www.scribd.com/publisher/api?method_name=docs.getConversionStatus
|
204
235
|
#
|
205
236
|
# Unlike other properties of a document, this is retrieved from the server
|
206
237
|
# every time it's queried.
|
@@ -229,5 +260,19 @@ module Scribd
|
|
229
260
|
def owner=(newuser) #:nodoc:
|
230
261
|
saved? ? raise(NotImplementedError, "Cannot change a document's owner once the document has been saved") : super
|
231
262
|
end
|
263
|
+
|
264
|
+
# Retrieves a document's download URL. You can provide a format for the
|
265
|
+
# download. Valid formats are listed at
|
266
|
+
# http://www.scribd.com/publisher/api?method_name=docs.getDownloadUrl
|
267
|
+
#
|
268
|
+
# If you do not provide a format, the link will be for the document's
|
269
|
+
# original format.
|
270
|
+
|
271
|
+
def download_url(format='original')
|
272
|
+
@download_urls[format] ||= begin
|
273
|
+
response = API.instance.send_request('docs.getDownloadUrl', :doc_id => self.id, :doc_type => format)
|
274
|
+
response.elements['/rsp/download_link'].cdatas.first.to_s
|
275
|
+
end
|
276
|
+
end
|
232
277
|
end
|
233
278
|
end
|
data/lib/scribdresource.rb
CHANGED
@@ -143,7 +143,12 @@ module Scribd
|
|
143
143
|
def load_attributes(xml)
|
144
144
|
@attributes.clear
|
145
145
|
xml.each_element do |element|
|
146
|
-
text = element.text.
|
146
|
+
text = if element.text.nil? or element.text.chomp.strip.empty? then
|
147
|
+
element.cdatas ? element.cdatas.first.value : nil
|
148
|
+
else
|
149
|
+
element.text
|
150
|
+
end
|
151
|
+
|
147
152
|
@attributes[element.name.to_sym] = if element.attributes['type'] == 'integer' then
|
148
153
|
text.to_i
|
149
154
|
elsif element.attributes['type'] == 'float' then
|
data/lib/scribduser.rb
CHANGED
@@ -18,7 +18,7 @@ module Scribd
|
|
18
18
|
# user = Scribd::API.instance.user
|
19
19
|
#
|
20
20
|
# For information on a user's attributes, please consult the online API
|
21
|
-
# documentation at http://www.scribd.com/
|
21
|
+
# documentation at http://www.scribd.com/publisher/api?method_name=user.login
|
22
22
|
#
|
23
23
|
# You can create a new account with the signup (a.k.a. create) method:
|
24
24
|
#
|
@@ -69,7 +69,7 @@ module Scribd
|
|
69
69
|
# Scribd::Document instances returned through this method have more
|
70
70
|
# attributes than those returned by the Scribd::Document.find method. The
|
71
71
|
# additional attributes are documented online at
|
72
|
-
# http://www.scribd.com/
|
72
|
+
# http://www.scribd.com/publisher/api?method_name=docs.getSettings
|
73
73
|
|
74
74
|
def documents
|
75
75
|
response = API.instance.send_request('docs.getList', { :session_key => @attributes[:session_key] })
|
data/sample/02_user.rb
CHANGED
@@ -32,7 +32,7 @@ begin
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
-
results = Scribd::Document.find(:query => 'checklist') # Search over the user's docs for the string '
|
35
|
+
results = Scribd::Document.find(:all, :query => 'checklist') # Search over the user's docs for the string 'checklist'
|
36
36
|
puts "Search through docs turned up #{results.size} results:"
|
37
37
|
for doc in results
|
38
38
|
puts "#{doc.title}"
|
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: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jared Friedman
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-10-01 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.7.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/
|
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"
|
36
36
|
email: api@scribd.com
|
37
37
|
executables: []
|
38
38
|
|