Class: RefreshingmenusApi::Widget

Inherits:
Object
  • Object
show all
Defined in:
lib/refreshingmenus_api/widget.rb

Class Method Summary collapse

Class Method Details

.script_src(options) ⇒ Object

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/refreshingmenus_api/widget.rb', line 13

def self.script_src(options)
  options = options.clone # Don't fuck up Hash we don't own..
  raise ArgumentError, "Expected options argument to be a Hash, got #{options.inspect}." if not options.is_a?(Hash)
  options[:dom_id] = 'rm-menuwidget'
  raise ArgumentError, "Expected a :place_id as option but got #{options[:place_id].inspect}." if not options[:place_id].is_a?(String)
  raise ArgumentError, "Expected a :widget_token as option but got #{options[:widget_token].inspect}." if not options[:widget_token].is_a?(String)
  secure = options.delete(:secure)
  version = options.delete(:version) || '1'
  base_uri = options.delete(:base_uri) || 'www.refreshingmenus.com'
  "#{secure ? 'https' : 'http'}://#{base_uri}/api/v#{version}/widget.js?#{options.to_param}"
end

.script_tag(options) ⇒ Object

Options:

  • widget_token (required) - Your RefreshingMenus Widget token

  • place_id (required) - The RefreshingMenus Place ID (UUID)

  • secure - Boolean, we’ll use https if true

  • style - The style name we should use (default: ‘default’), use ‘none’ for no styling (if you embed your own styling)



9
10
11
# File 'lib/refreshingmenus_api/widget.rb', line 9

def self.script_tag(options)
  return "<script id='#{options[:dom_id]}' src='#{self.src(options)}'></script>"
end