Sha256: 8e2f7ee13fbe061848957745ed032cb64aead1bfc8f81685e506afbb5f22798b

Contents?: true

Size: 1.75 KB

Versions: 7

Compression:

Stored size: 1.75 KB

Contents

require File.expand_path('../../helpers/browse_everything_helper',__FILE__)

class BrowseEverythingController < ActionController::Base
  layout 'browse_everything'
  helper BrowseEverythingHelper

  after_filter {session["#{provider_name}_token"] = provider.token unless provider.nil? }
  
  def index
    render :layout => !request.xhr?
  end

  def show
    render :layout => !request.xhr?
  end
  
  def auth
    code = params[:code]
    session["#{provider_name}_token"] = provider.connect(params,session["#{provider_name}_data"])
  end

  def resolve
    selected_files = params[:selected_files] || []
    @links = selected_files.collect { |file| 
      p,f = file.split(/:/) 
      (url,extra) = browser.providers[p].link_for(f)
      result = { url: url }
      result.merge!(extra) unless extra.nil?
      result
    }
    respond_to do |format|  
      format.html { render :layout => false }
      format.json { render :json => @links }
    end
  end

  private

  def auth_link
    @auth_link ||= if provider.present?
      link, data = provider.auth_link
      session["#{provider_name}_data"] = data
      "#{link}&state=#{provider.key}"
    else
      nil
    end
  end

  def browser
    if @browser.nil?
      @browser = BrowseEverything::Browser.new(url_options)
      @browser.providers.values.each do |p|
        p.token = session["#{p.key}_token"]
      end
    end
    @browser
  end

  def browse_path
    @path ||= params[:path] || ''
  end

  def provider
    @provider ||= browser.providers[provider_name]
  end

  def provider_name
    @provider_nane ||= params[:provider] || params[:state].to_s.split(/\|/).last
  end

  helper_method :auth_link
  helper_method :browser
  helper_method :browse_path
  helper_method :provider
  helper_method :provider_name
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
browse-everything-0.4.5 app/controllers/browse_everything_controller.rb
browse-everything-0.4.4 app/controllers/browse_everything_controller.rb
browse-everything-0.4.3 app/controllers/browse_everything_controller.rb
browse-everything-0.4.2 app/controllers/browse_everything_controller.rb
browse-everything-0.4.1 app/controllers/browse_everything_controller.rb
browse-everything-0.4.0 app/controllers/browse_everything_controller.rb
browse-everything-0.3.0 app/controllers/browse_everything_controller.rb