Module: NextcloudClient::Helpers
- Included in:
- Ocs::App, Ocs::FileSharingApi, Ocs::FileSharingApi::FederatedCloudShares, Ocs::Group, Ocs::GroupFolder, Ocs::User, Ocs::User::Group, Webdav::Directory
- Defined in:
- lib/nextcloud-client/helpers/nextcloud-client.rb,
lib/nextcloud-client/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
50 51 52 53 |
# File 'lib/nextcloud-client/helpers/nextcloud-client.rb', line 50 def (doc, obj) = (doc) obj.define_singleton_method(:meta) { } && obj end |
#doc_to_hash(doc, xpath = "/") ⇒ Hash
Converts document to hash
40 41 42 43 |
# File 'lib/nextcloud-client/helpers/nextcloud-client.rb', line 40 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
29 30 31 32 33 |
# File 'lib/nextcloud-client/helpers/nextcloud-client.rb', line 29 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
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/nextcloud-client/helpers/nextcloud-client.rb', line 90 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
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/nextcloud-client/helpers/nextcloud-client.rb', line 68 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
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/nextcloud-client/helpers/nextcloud-client.rb', line 13 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
60 61 62 |
# File 'lib/nextcloud-client/helpers/nextcloud-client.rb', line 60 def path_from_href(href, url) href.match(/#{url}(.*)/)[1] end |