Module: WAB::Impl::Agoo::Sender
- Included in:
- ExportProxy, Handler, TqlHandler
- Defined in:
- lib/wab/impl/agoo/sender.rb
Overview
The Sender module adds support for sending results and errors.
Instance Method Summary collapse
-
#parse_query(query_string) ⇒ Object
Parses a query string into a Hash.
-
#send_error(e, res) ⇒ Object
Sends an error from a rescued call.
-
#send_result(result, res, path, query) ⇒ Object
Sends the results from a controller request.
Instance Method Details
#parse_query(query_string) ⇒ Object
Parses a query string into a Hash.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wab/impl/agoo/sender.rb', line 30 def parse_query(query_string) query = {} if !query_string.nil? && !query_string.empty? query_string.split('&').each { |opt| k, v = opt.split('=') # TBD convert %xx to char query[k] = v } end # Detect numbers (others later) query.each_pair { |k,v| i = Utils.attempt_key_to_int(v) query[k] = i unless i.nil? # TBD how about float } end |
#send_error(e, res) ⇒ Object
Sends an error from a rescued call.
20 21 22 23 24 25 26 27 |
# File 'lib/wab/impl/agoo/sender.rb', line 20 def send_error(e, res) res.code = 500 res['Content-Type'] = 'application/json' body = { code: -1, error: "#{e.class}: #{e.}" } body[:backtrace] = e.backtrace res.body = @shell.data(body).json(@shell.indent) @shell.logger.warn(Impl.format_error(e)) end |
#send_result(result, res, path, query) ⇒ Object
Sends the results from a controller request.
10 11 12 13 14 15 16 17 |
# File 'lib/wab/impl/agoo/sender.rb', line 10 def send_result(result, res, path, query) result = @shell.data(result) unless result.is_a?(WAB::Data) response_body = result.json(@shell.indent) res.code = 200 res['Content-Type'] = 'application/json' @shell.logger.debug("reply to #{path.join('/')}#{query}: #{response_body}") if @shell.logger.debug? res.body = response_body end |