我有一个主要使用opal编译的ruby编写的webapp。我现在想在我自己的云中存储/检索文件,也许使用WebDAV。我正在寻找一个如何使用HTTP模块执行此操作的示例。
我试过
HTTP.get("https://owncloud/foo.abc") do |req|
req.username= "user"
...
end.then do |response|
puts response
end
但这不起作用。然后没有方法用于模块HTTP。
所以看起来如果我将一个块传递给HTTP.get它就不再返回一个promise。
当我没有通过障碍时,我不知道 如何配置请求。
如果我能找到一个完整的示例如何使用来自蛋白石的HTTP,那是最好的。 蛋白石博客中的一个小例子并没有完全消失。
答案 0 :(得分:0)
我认为用户名/密码应该在选项哈希(see the opal-jquery README)中传递。
HTTP.get("https://owncloud/foo.abc", username: 'user').then do |response|
puts response
end
该块用作回调的默认形式。要切换到promise样式,您不应传递任何块,而是尝试将HTTP.get
的结果分配给变量以修改请求选项:
req = HTTP.get("https://owncloud/foo.abc")
puts req.inspect # <= do something with the request
req.then do |response|
puts response
end