Sha256: 1fe08a8ba9ee3f56f3e5d983682a77986a568c2563b56a435cef2f91557dad07

Contents?: true

Size: 1.82 KB

Versions: 36

Compression:

Stored size: 1.82 KB

Contents

class FanforcePlugin::Sinatra

  # INDEX ########################################################################
  def route_index(params)
    page :index, :layout => :promotional
  end
  ['/', '/index.html'].each do |path|
    get path do route_index(params) end
  end

  # INSTALL ######################################################################
  def route_install(params)
    raise "This is not a valid plugin install request: #{env['HTTP_HOST']}" if !ff.valid_install_request?(params)
    api_key = $Redis.get("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{ff.params[:fanforce_id]}")

    #raise 'A different API key already exists for this addon. Please uninstall first.' if api_key.present? and ff.params[:api_key] != api_key
    $Redis.set("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{ff.params[:fanforce_id]}", ff.params[:api_key])
    ff.auth(ff.params[:api_key])

    json status: 'installed', success: true
  end
  any '/install' do route_install(params) end

  # UNINSTALL ####################################################################
  def route_uninstall(params)
    raise 'This is not a valid plugin uninstall request.' if !ff.valid_uninstall_request?(params)
    api_key = $Redis.get("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{ff.params[:fanforce_id]}")

    raise 'API keys must match before an addon can be uninstalled.' if api_key.present? and ff.params[:api_key] != api_key
    $Redis.del("installed:#{ff.params[:addon_type]}-#{ff.params[:addon_id]}:#{ff.params[:fanforce_id]}")
    json status: 'uninstalled', success: true
  end
  any '/uninstall' do route_uninstall(params) end

  # PING-PONG ####################################################################
  def route_ping_pong(params)
    json success: true
  end
  get '/ping-pong' do route_ping_pong(params) end

end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
fanforce-plugin-factory-0.20.2 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.20.1 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.20.0 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.19.3 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.19.1 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.19.0 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.18.0 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.17.2 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.17.1 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.17.0 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.16.1 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.16.0 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.15.1 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.14.1 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.14.0 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.13.5 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.13.4 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.13.3 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.13.2 lib/fanforce/plugin_factory/routes.rb
fanforce-plugin-factory-0.13.1 lib/fanforce/plugin_factory/routes.rb