Sha256: 1896fd3465910d63a425fd780e3e32969ea38a4723ee23352122ba00bbea1388

Contents?: true

Size: 1.42 KB

Versions: 28

Compression:

Stored size: 1.42 KB

Contents

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

    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

28 entries across 28 versions & 1 rubygems

Version Path
rhosync-2.1.1 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.1.0 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.1.0.beta.2 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.1.0.beta.1 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.9 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.8 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.7 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.6 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.5 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.4 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.3 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.2 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.1 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.0 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.0.rc2 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.0.rc1 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.0.beta13 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.0.beta12 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.0.beta11 lib/rhosync/console/app/helpers/helpers.rb
rhosync-2.0.0.beta10 lib/rhosync/console/app/helpers/helpers.rb