Module: Nextcloud::Helpers
- Included in:
- Ocs::App, Ocs::FileSharingApi, Ocs::FileSharingApi::FederatedCloudShares, Ocs::Group, Ocs::User, Ocs::User::Group, Webdav::Directory
- Defined in:
- lib/nextcloud/helpers/nextcloud.rb,
lib/nextcloud/helpers/properties.rb
Overview
Helper methods that are used through lib
Defined Under Namespace
Modules: Properties
Instance Method Summary collapse
-
#add_meta(doc, obj) ⇒ #define_singleton_method
Adds meta method to an object.
-
#doc_to_hash(doc, xpath = "/") ⇒ Hash
Converts document to hash.
-
#get_meta(doc) ⇒ Hash
Parses meta information returned by API, may include a status, status code and a message.
-
#has_dav_errors(doc) ⇒ Hash, Boolean
Shows error or returns false.
-
#parse_dav_response(doc) ⇒ Hash
Shows errors, or success message.
-
#parse_with_meta(doc, xpath) ⇒ Array
Makes an array out of repeated elements.
-
#path_from_href(href, url) ⇒ String
Extracts remaining part of url.
Instance Method Details
#add_meta(doc, obj) ⇒ #define_singleton_method
Adds meta method to an object
49 50 51 52 |
# File 'lib/nextcloud/helpers/nextcloud.rb', line 49 def (doc, obj) = (doc) obj.define_singleton_method(:meta) { } && obj end |
#doc_to_hash(doc, xpath = "/") ⇒ Hash
Converts document to hash
39 40 41 42 |
# File 'lib/nextcloud/helpers/nextcloud.rb', line 39 def doc_to_hash(doc, xpath = "/") h = Hash.from_xml(doc.xpath(xpath).to_xml) h end |
#get_meta(doc) ⇒ Hash
Parses meta information returned by API, may include a status, status code and a message
28 29 30 31 32 |
# File 'lib/nextcloud/helpers/nextcloud.rb', line 28 def (doc) = doc.xpath("//meta/*").each_with_object({}) do |node, | [node.name] = node.text end end |
#has_dav_errors(doc) ⇒ Hash, Boolean
Shows error or returns false
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/nextcloud/helpers/nextcloud.rb', line 89 def has_dav_errors(doc) doc.remove_namespaces! if doc.at_xpath("//error") { exception: doc.xpath("//exception").text, message: doc.xpath("//message").text } else false end end |
#parse_dav_response(doc) ⇒ Hash
Shows errors, or success message
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/nextcloud/helpers/nextcloud.rb', line 67 def parse_dav_response(doc) doc.remove_namespaces! if doc.at_xpath("//error") { exception: doc.xpath("//exception").text, message: doc.xpath("//message").text } elsif doc.at_xpath("//status") { status: doc.xpath("//status").text } else { status: "ok" } end end |
#parse_with_meta(doc, xpath) ⇒ Array
Makes an array out of repeated elements
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/nextcloud/helpers/nextcloud.rb', line 12 def (doc, xpath) groups = [] doc.xpath(xpath).each do |prop| groups << prop.text end = (doc) groups.send(:define_singleton_method, :meta) do end groups end |
#path_from_href(href, url) ⇒ String
Extracts remaining part of url
59 60 61 |
# File 'lib/nextcloud/helpers/nextcloud.rb', line 59 def path_from_href(href, url) href.match(/#{url}(.*)/)[1] end |