Class: Bormashino::Fetch
- Inherits:
-
Object
- Object
- Bormashino::Fetch
- Defined in:
- lib/bormashino/fetch.rb
Overview
wrapper of Fetch API
Instance Attribute Summary collapse
-
#init ⇒ Object
Returns the value of attribute init.
-
#options ⇒ Object
Returns the value of attribute options.
-
#resolved_to ⇒ Object
Returns the value of attribute resolved_to.
-
#resource ⇒ Object
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(resource:, resolved_to:, init: {}, options: {}) ⇒ Fetch
constructor
A new instance of Fetch.
- #run ⇒ Object
Constructor Details
#initialize(resource:, resolved_to:, init: {}, options: {}) ⇒ Fetch
Returns a new instance of Fetch.
10 11 12 13 14 15 16 17 |
# File 'lib/bormashino/fetch.rb', line 10 def initialize(resource:, resolved_to:, init: {}, options: {}) JS.eval("console.warn('Bormashino::Fetch is deprecated. Use Fetch API and JS::Object#await')") @resource = resource @init = init @resolved_to = resolved_to = end |
Instance Attribute Details
#init ⇒ Object
Returns the value of attribute init.
8 9 10 |
# File 'lib/bormashino/fetch.rb', line 8 def init @init end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/bormashino/fetch.rb', line 8 def end |
#resolved_to ⇒ Object
Returns the value of attribute resolved_to.
8 9 10 |
# File 'lib/bormashino/fetch.rb', line 8 def resolved_to @resolved_to end |
#resource ⇒ Object
Returns the value of attribute resource.
8 9 10 |
# File 'lib/bormashino/fetch.rb', line 8 def resource @resource end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bormashino/fetch.rb', line 19 def run raise 'No mounted apps' unless Bormashino::Server.mounted? # rubocop:disable Style::DocumentDynamicEvalDefinition JS.eval " fetch(\n \#{@resource.to_json},\n \#{@init.to_json}\n ).then((r) => {\n r.text().then((t) => {\n window.bormashino.request(\n 'post',\n \#{@resolved_to.to_json},\n 'status=' + r.status +\n '&payload=' + encodeURIComponent(t) +\n '&options=' + \#{CGI.escape(@options.to_json).to_json}\n )\n })\n })\n ENDOFEVAL\n # rubocop:enable Style::DocumentDynamicEvalDefinition\nend\n" |