0

I have a webapp written mostly in ruby compiled with opal. I now would like to store/retrieve file in my owncloud, maybe using WebDAV. I am looking for an example how to do this using HTTP module.

I tried

HTTP.get("https://owncloud/foo.abc") do |req|
   req.username= "user"
   ...
end.then do |response|
   puts response
end

But that does not work. no method then for module HTTP.

So it seem that if I pass a block to HTTP.get it no longer returns a promise.

When I do not pass a block I don' know how to configure the request.

Best if I could find an full example how to use HTTP from opal. The small example in opal blog die not hell out.

Bernhard
  • 686
  • 8
  • 20

1 Answers1

0

I think username/password should be passed in the options hash (see the opal-jquery README).

HTTP.get("https://owncloud/foo.abc", username: 'user').then do |response|
   puts response
end



A note about the Promise-style:

The block is used as the default form of callback. To switch to promise-style you should not pass any block, instead try assigning the result of HTTP.get to a variable to modify the request options:

req = HTTP.get("https://owncloud/foo.abc")

puts req.inspect # <= do something with the request

req.then do |response|
   puts response
end
Elia Schito
  • 989
  • 7
  • 18
  • I am a bit confused where to find information about HTTP: There is something in opal-browser, somehtin in opal-jquery – Bernhard Aug 11 '14 at 08:59
  • In particular I never know when HTTP.get retuns a Promise and when a HTTP. Does it also depend on the Opal version? Im a playing around in http://opalrb.org/try/# resp. in http://fkchang.github.io/opal-irb/index-jq.html – Bernhard Aug 11 '14 at 09:25
  • @fkchang's irb report opal 0.6.0 and it doesn't have support for Promise – Elia Schito Aug 11 '14 at 13:14
  • `HTTP` is part of `opal-jquery` and it's a wrapper for `$.ajax` and [looking at the changelog](https://github.com/opal/opal-jquery/blob/master/CHANGELOG.md#edge) you can see promises support has not yet been released – Elia Schito Aug 11 '14 at 13:17