Class: Grendel::DocumentManager
- Inherits:
-
Object
- Object
- Grendel::DocumentManager
- Defined in:
- lib/grendel/document_manager.rb
Instance Method Summary collapse
-
#delete(name) ⇒ Object
delete the specified document from Grendel.
-
#find(name) ⇒ Object
retreive a document.
-
#initialize(user) ⇒ DocumentManager
constructor
A new instance of DocumentManager.
-
#list ⇒ Object
list all documents.
-
#store(name, data, content_type = nil) ⇒ Object
store a document, creating a new one if it doesn’t exist, or replacing the existing one if it does.
Constructor Details
#initialize(user) ⇒ DocumentManager
Returns a new instance of DocumentManager.
4 5 6 7 |
# File 'lib/grendel/document_manager.rb', line 4 def initialize(user) @user = user @base_uri = "/documents" end |
Instance Method Details
#delete(name) ⇒ Object
delete the specified document from Grendel
42 43 44 |
# File 'lib/grendel/document_manager.rb', line 42 def delete(name) @user.delete(@base_uri + "/" + name) end |
#find(name) ⇒ Object
retreive a document
16 17 18 19 20 21 22 23 24 |
# File 'lib/grendel/document_manager.rb', line 16 def find(name) response = @user.get(@base_uri + "/" + name) params = { :name => name, :data => response.body, :content_type => response.headers['content-type'].first } Document.new(@user, params) end |
#list ⇒ Object
list all documents
10 11 12 13 |
# File 'lib/grendel/document_manager.rb', line 10 def list response = @user.get(@base_uri) response["documents"].map {|d| Document.new(@user, d) } end |
#store(name, data, content_type = nil) ⇒ Object
store a document, creating a new one if it doesn’t exist, or replacing the existing one if it does
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/grendel/document_manager.rb', line 27 def store(name, data, content_type = nil) # if the content type isn't provided, guess it or set it to a default unless content_type if mime_type = MIME::Types.type_for(name).first content_type = mime_type.content_type else content_type = 'application/octet-stream' end end response = @user.put(@base_uri + "/" + name, data, :raw_data => true, :headers => {'Content-Type' => content_type}) Document.new(@user, :name => name, :data => data, :content_type => content_type) end |