Module: PandaPal::LaunchUrlHelpers
- Defined in:
- app/lib/panda_pal/launch_url_helpers.rb
Class Method Summary collapse
- .absolute_launch_url(launch_type, host:, launch_handler: nil) ⇒ Object
- .add_url_params(url, params) ⇒ Object
- .launch_route(opts, launch_type: nil) ⇒ Object
- .launch_url(opts, launch_type: nil) ⇒ Object
- .normalize_lti_launch_desc(opts) ⇒ Object
- .resolve_url_symbol(sym, **opts) ⇒ Object
Class Method Details
.absolute_launch_url(launch_type, host:, launch_handler: nil) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/lib/panda_pal/launch_url_helpers.rb', line 3 def self.absolute_launch_url(launch_type, host:, launch_handler: nil) opts = PandaPal.lti_paths[launch_type] is_direct = opts[:no_redirect] || !launch_handler.present? if is_direct final_url = launch_url(opts, launch_type: launch_type) return final_url if URI.parse(final_url).absolute? return [host.to_s, final_url].join else launch_handler = resolve_route(launch_handler) if launch_handler.is_a?(Symbol) return add_url_params([host.to_s, launch_handler].join, { launch_type: launch_type, }) end end |
.add_url_params(url, params) ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'app/lib/panda_pal/launch_url_helpers.rb', line 52 def self.add_url_params(url, params) uri = URI(url) decoded_params = URI.decode_www_form(uri.query || "") params.each do |k, v| decoded_params << [k, v] end uri.query = URI.encode_www_form(decoded_params) uri.to_s end |
.launch_route(opts, launch_type: nil) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/lib/panda_pal/launch_url_helpers.rb', line 32 def self.launch_route(opts, launch_type: nil) if opts.is_a?(Symbol) || opts.is_a?(String) launch_type = opts.to_sym opts = PandaPal.lti_paths[launch_type] end if opts[:route_helper_key] opts[:route_helper_key].to_sym else opts[:url] ||= launch_type opts[:url] end end |
.launch_url(opts, launch_type: nil) ⇒ Object
26 27 28 29 30 |
# File 'app/lib/panda_pal/launch_url_helpers.rb', line 26 def self.launch_url(opts, launch_type: nil) url = launch_route(opts, launch_type: launch_type) url = resolve_url_symbol(url) if url.is_a?(Symbol) url end |
.normalize_lti_launch_desc(opts) ⇒ Object
19 20 21 22 23 24 |
# File 'app/lib/panda_pal/launch_url_helpers.rb', line 19 def self.normalize_lti_launch_desc(opts) opts = opts.dup opts.delete(:route_helper_key) opts.delete(:no_redirect) opts end |
.resolve_url_symbol(sym, **opts) ⇒ Object
46 47 48 49 50 |
# File 'app/lib/panda_pal/launch_url_helpers.rb', line 46 def self.resolve_url_symbol(sym, **opts) sym = :"#{sym}_url" unless sym.to_s.ends_with?('_url') opts[:only_path] = true unless opts.key?(:only_path) resolve_route(:"MainApp/#{sym}", **opts) end |