Sha256: d505d4864cab45ba44d6931504cfd22a32f41f4e471c86f25d8ebea55c7a6bc3

Contents?: true

Size: 1.83 KB

Versions: 5

Compression:

Stored size: 1.83 KB

Contents

class Fanforce::Plugin::Sinatra

  def route_index_ui
    page :index, :layout => :promotional
  end

  def route_config_ui
    route_ui(:config)
  end

  def route_close_popup_ui
    page :close_popup
  end

  def route_install_callback
    raise "This is not a valid plugin install request (#{env['HTTP_HOST']}): #{params.to_s}" if !ff.valid_install_request?(params)
    api_key = Plugin.redis.get("installed:plugin-#{params[:plugin_id]}:#{params[:organization_id]}")

    if api_key.present? and api_key != params[:api_key]
      is_valid_key = Fanforce::API.new.get("/api_auths/is_valid_key/#{params[:api_key]}", organization_id: params[:organization_id], plugin_id: params[:plugin_id])[:result]
      raise 'A different API key already exists for this plugin. Please uninstall first.' if !is_valid_key
    end
    Plugin.redis.set("installed:plugin-#{params[:plugin_id]}:#{params[:organization_id]}", params[:api_key])
    ff.set_auth(params[:api_key])

    json status: 'finished'
  end

  def route_uninstall_callback
    raise 'This is not a valid plugin uninstall request.' if !ff.valid_uninstall_request?(params)
    api_key = Plugin.redis.get("installed:plugin-#{params[:plugin_id]}:#{params[:organization_id]}")

    if api_key.present? and api_key != params[:api_key]
      is_valid_key = Fanforce::API.new.get("/api_auths/is_valid_key/#{params[:api_key]}", organization_id: params[:organization_id], plugin_id: params[:plugin_id])[:result]
      raise 'API keys must match before an plugin can be uninstalled.' if !is_valid_key
    end
    Plugin.redis.del("installed:plugin-#{params[:plugin_id]}:#{params[:organization_id]}")

    json status: 'finished'
  end

  def route_ping_callback
    json success: true
  end

  def route_visitor_ui(name, com_dir=nil)
    opts = {:layout => :visitor}
    opts[:com_dir] = com_dir if com_dir
    page name, opts
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
fanforce-plugin-factory-2.0.0.rc29 lib/fanforce/plugin_factory/sinatra/route_helpers/plugin.rb
fanforce-plugin-factory-2.0.0.rc28 lib/fanforce/plugin_factory/sinatra/route_helpers/plugin.rb
fanforce-plugin-factory-2.0.0.rc27 lib/fanforce/plugin_factory/sinatra/route_helpers/plugin.rb
fanforce-plugin-factory-2.0.0.rc26 lib/fanforce/plugin_factory/sinatra/route_helpers/plugin.rb
fanforce-plugin-factory-2.0.0.rc25 lib/fanforce/plugin_factory/sinatra/route_helpers/plugin.rb