Sha256: 3cae2d40bfb42e26be517835cc84be9f16c72dd79b185885e031bc074fb9398d

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

class RhoconnectConsole::Server
  helpers do
    def url_path(*path_parts)
      [ path_prefix, path_parts ].join("/").squeeze('/')
    end
    alias_method :u, :url_path

    def resque_path
      # Replace 'console' at the end of path by 'resque'
      url_path("").sub!(/console\/?\Z/, "resque/")
    end

    def path_prefix
      request.env['SCRIPT_NAME']
    end

    def is_errors?
      session[:errors] and session[:errors].size > 0
    end
      
    def show_errors
      return '' unless session[:errors]
      res = []
      session[:errors].each do |error|
    	  res << "<p style=\"color:#800\">#{error}</p>"
    	end
    	session[:errors] = nil
    	res.join
    end
        
    def handle_api_error(error_message)
      begin
        yield
      rescue RestClient::Exception => re
        session[:errors] ||= []
        if re.response.body.nil? or re.response.body.length == 0
          session[:errors] << "#{error_message}: [#{re.http_code}] #{re.message}"  
        else
          session[:errors] << "#{error_message}: #{re.response.body}"
        end
      rescue Exception => e      
        session[:errors] ||= []
        session[:errors] << "#{error_message}: #{e.message}"
      end     
    end
    
    def doc_params
      doc_params = "source_id=#{CGI.escape(params[:source_id])}&user_id=#{CGI.escape(params[:user_id])}"
      doc_params += "&device_id=#{CGI.escape(params[:device_id])}" if params[:device_id] 
      doc_params
    end
    
    def doc_is_string
      params[:dbkey].ends_with?('token') or params[:dbkey].ends_with?('size')
    end        
  end   
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rhoconnect-3.1.2 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.1.1 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.1.0 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.1.0.beta2 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.1.0.beta1 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.0.6 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.0.5 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.0.4 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.0.3 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.0.2 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.0.1 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.0.0 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.0.0.rc1 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.0.0.beta3 lib/rhoconnect/console/app/helpers/helpers.rb
rhoconnect-3.0.0.beta1 lib/rhoconnect/console/app/helpers/helpers.rb