Class: Nextcloud::Api
- Inherits:
-
Object
- Object
- Nextcloud::Api
- Defined in:
- src/ruby/share-nc-folders.rb,
src/ruby/unshare-shares-to-klassen.rb
Instance Method Summary collapse
-
#request(method, path, params = nil, body = nil, depth = nil, destination = nil, raw = false) ⇒ Object
Sends API request to Nextcloud.
Instance Method Details
#request(method, path, params = nil, body = nil, depth = nil, destination = nil, raw = false) ⇒ Object
Sends API request to Nextcloud
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'src/ruby/share-nc-folders.rb', line 38 def request(method, path, params = nil, body = nil, depth = nil, destination = nil, raw = false) response = Net::HTTP.start(@url.host, @url.port, use_ssl: @url.scheme == "https") do |http| http.read_timeout = HTTP_READ_TIMEOUT req = Kernel.const_get("Net::HTTP::#{method.capitalize}").new(@url.request_uri + path) req["OCS-APIRequest"] = true req.basic_auth @username, @password req["Content-Type"] = "application/x-www-form-urlencoded" req["Depth"] = 0 if depth req["Destination"] = destination if destination req.set_form_data(params) if params req.body = body if body http.request(req) end # if ![201, 204, 207].include? response.code # raise Errors::Error.new("Nextcloud received invalid status code") # end raw ? response.body : Nokogiri::XML.parse(response.body) end |