Class: RExchange::Folder
- Inherits:
-
Object
- Object
- RExchange::Folder
- Includes:
- Enumerable, REXML
- Defined in:
- lib/rexchange/folder.rb,
lib/rexchange/generic_item.rb
Direct Known Subclasses
Constant Summary collapse
- CONTENT_TYPES =
{}
Instance Attribute Summary collapse
-
#credentials ⇒ Object
readonly
Returns the value of attribute credentials.
-
#displayname ⇒ Object
readonly
Returns the value of attribute displayname.
Instance Method Summary collapse
-
#each ⇒ Object
Iterate through each entry in this folder.
-
#folders ⇒ Object
Return an Array of subfolders for this folder.
- #folders_hash ⇒ Object
-
#initialize(credentials, parent, displayname, href, content_type) ⇒ Folder
constructor
A new instance of Folder.
- #make_subfolder(subfolder) ⇒ Object
- #message_hrefs(href_regex) ⇒ Object
-
#method_missing(sym, *args) ⇒ Object
Used to access subfolders.
-
#search(conditions = {}) ⇒ Object
Not Implemented!.
-
#to_s ⇒ Object
Return the absolute path to this folder (but not the full URI).
Constructor Details
#initialize(credentials, parent, displayname, href, content_type) ⇒ Folder
Returns a new instance of Folder.
23 24 25 26 27 |
# File 'lib/rexchange/folder.rb', line 23 def initialize(credentials, parent, displayname, href, content_type) @credentials, @parent, @href = credentials, parent, href @content_type = CONTENT_TYPES[content_type] || Message @displayname = displayname end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args) ⇒ Object
Used to access subfolders.
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rexchange/folder.rb', line 30 def method_missing(sym, *args) if folders_hash.has_key?(sym.to_s) folders_hash[sym.to_s] else puts folders_hash.keys.inspect puts sym.to_s raise FolderNotFoundError.new("#{sym} is not a subfolder of #{@displayname} - #{@href}") end end |
Instance Attribute Details
#credentials ⇒ Object (readonly)
Returns the value of attribute credentials.
21 22 23 |
# File 'lib/rexchange/folder.rb', line 21 def credentials @credentials end |
#displayname ⇒ Object (readonly)
Returns the value of attribute displayname.
21 22 23 |
# File 'lib/rexchange/folder.rb', line 21 def displayname @displayname end |
Instance Method Details
#each ⇒ Object
Iterate through each entry in this folder
48 49 50 51 52 |
# File 'lib/rexchange/folder.rb', line 48 def each @content_type::find(@credentials, to_s).each do |item| yield item end end |
#folders ⇒ Object
Return an Array of subfolders for this folder
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rexchange/folder.rb', line 61 def folders @folders ||= begin request_body = <<-eos <D:searchrequest xmlns:D = "DAV:"> <D:sql> SELECT "DAV:displayname", "DAV:contentclass" FROM SCOPE('shallow traversal of "#{@href}"') WHERE "DAV:ishidden" = false AND "DAV:isfolder" = true </D:sql> </D:searchrequest> eos folders = [] DavSearchRequest.execute(@credentials, :body => request_body) do |response| # iterate through folders query and add a new Folder # object for each, under a normalized name. xpath_query = "/*/a:response[a:propstat/a:status/text() = 'HTTP/1.1 200 OK']" Document.new(response.body).elements.each(xpath_query) do |m| href = m.elements['a:href'].text displayname = m.elements['a:propstat/a:prop/a:displayname'].text contentclass = m.elements['a:propstat/a:prop/a:contentclass'].text folders << Folder.new(@credentials, self, displayname, href, contentclass.split(':').last.sub(/folder$/, '')) end end folders end end |
#folders_hash ⇒ Object
94 95 96 |
# File 'lib/rexchange/folder.rb', line 94 def folders_hash @folders_hash ||= folders.inject({}){|memo, f| memo[f.displayname.normalize]=f; memo} end |
#make_subfolder(subfolder) ⇒ Object
98 99 100 101 |
# File 'lib/rexchange/folder.rb', line 98 def make_subfolder(subfolder) path = @href.ensure_ends_with("/") + subfolder.ensure_ends_with("/") DavMkcolRequest.execute(@credentials, path) end |
#message_hrefs(href_regex) ⇒ Object
43 44 45 |
# File 'lib/rexchange/folder.rb', line 43 def (href_regex) RExchange::MessageHref::(href_regex, @credentials, to_s) end |
#search(conditions = {}) ⇒ Object
Not Implemented!
55 56 57 58 |
# File 'lib/rexchange/folder.rb', line 55 def search(conditions = {}) raise NotImplementedError.new('Bad Touch!') @content_type::find(@credentials, to_s, conditions) end |
#to_s ⇒ Object
Return the absolute path to this folder (but not the full URI)
104 105 106 |
# File 'lib/rexchange/folder.rb', line 104 def to_s @href end |