Class: Scribd::Collection
Overview
A collection on Scribd is a list of Documents created and maintained by a user.
@Collection@ instances and retrieved via the User#collections method. @Collections@ cannot be modified using the gem or the API. You can, however, #add and #remove Documents from a @Collection@.
Constant Summary collapse
- DOCUMENT_MISSING_ERROR_CODE =
652- DOCUMENT_EXISTS_ERROR_CODE =
653
Instance Attribute Summary collapse
-
#owner ⇒ Scribd::User
readonly
The user that created this collection.
Instance Method Summary collapse
- #<<(document) ⇒ Object
-
#add(document, ignore_if_exists = true) ⇒ Scribd::Document
Adds a Document to this collection.
-
#id ⇒ String
The @collection_id@ attribute.
-
#initialize(options = {}) ⇒ Collection
constructor
A new instance of Collection.
-
#name ⇒ String
The @collection_name@ attribute.
-
#remove(document, ignore_if_missing = true) ⇒ Scribd::Document
(also: #delete)
Removes a Document from this collection.
Methods inherited from Resource
create, #created?, #destroy, find, #inspect, #method_missing, #read_attribute, #read_attributes, #save, #saved?, #scribd_id, #write_attributes
Constructor Details
#initialize(options = {}) ⇒ Collection
Returns a new instance of Collection.
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/scribd/collection.rb', line 20 def initialize(={}) super if [:xml] then load_attributes([:xml]) @owner = [:owner] @saved = true @created = true else raise "Collections cannot be created, only retrieved." end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Scribd::Resource
Instance Attribute Details
#owner ⇒ Scribd::User (readonly)
Returns The user that created this collection.
17 18 19 |
# File 'lib/scribd/collection.rb', line 17 def owner @owner end |
Instance Method Details
#<<(document) ⇒ Object
56 57 58 |
# File 'lib/scribd/collection.rb', line 56 def <<(document) add document end |
#add(document, ignore_if_exists = true) ⇒ Scribd::Document
Adds a Document to this collection.
the document is already in the collection. the document already exists in the collection. See the online API documentation for more information.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/scribd/collection.rb', line 43 def add(document, ignore_if_exists=true) raise ArgumentError, "You can only add Scribd::Documents to collections" unless document.kind_of?(Scribd::Document) begin API.instance.send_request 'docs.addToCollection', :collection_id => collection_id, :doc_id => document.id, :session_key => owner.session_key rescue ResponseError => err raise unless ignore_if_exists raise if err.code.to_i != DOCUMENT_EXISTS_ERROR_CODE end return document end |
#id ⇒ String
Returns The @collection_id@ attribute.
86 87 88 |
# File 'lib/scribd/collection.rb', line 86 def id collection_id end |
#name ⇒ String
Returns The @collection_name@ attribute.
92 93 94 |
# File 'lib/scribd/collection.rb', line 92 def name collection_name end |
#remove(document, ignore_if_missing = true) ⇒ Scribd::Document Also known as: delete
Removes a Document from this collection.
the document is not in the collection. and the document does not exist in the collection. See the online API documentation for more information.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/scribd/collection.rb', line 71 def remove(document, ignore_if_missing=true) raise ArgumentError, "You can only remove Scribd::Documents from collections" unless document.kind_of?(Scribd::Document) begin API.instance.send_request 'docs.removeFromCollection', :collection_id => collection_id, :doc_id => document.id, :session_key => owner.session_key rescue ResponseError => err raise unless ignore_if_missing raise if err.code.to_i != DOCUMENT_MISSING_ERROR_CODE end return document end |