Sha256: 1d4754c3d288f9c66ac9992145d02e0250c00c130793168ed2875d900b16819a

Contents?: true

Size: 1.65 KB

Versions: 23

Compression:

Stored size: 1.65 KB

Contents

class Kaui::EngineController < ApplicationController
  before_filter :authenticate_user!

  layout :get_layout

  # Common options for the Kill Bill client
  def options_for_klient(options = {})
    {
      # TODO Kaui doesn't support multi-tenancy yet
      :api_key => KillBillClient.api_key,
      :api_secret => KillBillClient.api_secret,
      :username => current_user.kb_username || KillBillClient.username,
      :password => current_user.password || KillBillClient.password,
      :session_id => current_user.kb_session_id
    }.merge(options)
  end

  # Used for auditing purposes
  def current_user
    super rescue Kaui.config[:default_current_user]
  end

  def current_ability
    # Redefined here to namespace Ability in the correct module
    @current_ability ||= Kaui::Ability.new(current_user)
  end

  protected

  def as_string(e)
    if e.is_a?(RestClient::Exception)
      "#{e.message}, server response: #{as_string_from_response(e.response)}".split(/\n/).take(5).join("\n")
    elsif e.is_a?(KillBillClient::API::ResponseError)
      "Error #{e.response.code}: #{as_string_from_response(e.response.body)}"
    else
      e.message
    end
  end

  def as_string_from_response(response)
    error_message = response
    begin
      # BillingExceptionJson?
      error_message = JSON.parse response
    rescue => e
    end

    if error_message.respond_to? :[] and error_message['message'].present?
      # Likely BillingExceptionJson
      error_message = error_message['message']
    end
    # Limit the error size to avoid ActionDispatch::Cookies::CookieOverflow
    error_message[0..1000]
  end

  def get_layout
    layout ||= Kaui.config[:layout]
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
kaui-0.6.6 app/controllers/kaui/engine_controller.rb
kaui-0.6.5 app/controllers/kaui/engine_controller.rb
kaui-0.6.4 app/controllers/kaui/engine_controller.rb
kaui-0.6.3 app/controllers/kaui/engine_controller.rb
kaui-0.6.2 app/controllers/kaui/engine_controller.rb
kaui-0.6.1 app/controllers/kaui/engine_controller.rb
kaui-0.6.0 app/controllers/kaui/engine_controller.rb
kaui-0.5.3 app/controllers/kaui/engine_controller.rb
kaui-0.5.2 app/controllers/kaui/engine_controller.rb
kaui-0.5.1 app/controllers/kaui/engine_controller.rb
kaui-0.5.0 app/controllers/kaui/engine_controller.rb
kaui-0.4.9 app/controllers/kaui/engine_controller.rb
kaui-0.4.8 app/controllers/kaui/engine_controller.rb
kaui-0.4.7 app/controllers/kaui/engine_controller.rb
kaui-0.4.6 app/controllers/kaui/engine_controller.rb
kaui-0.4.5 app/controllers/kaui/engine_controller.rb
kaui-0.4.4 app/controllers/kaui/engine_controller.rb
kaui-0.4.3 app/controllers/kaui/engine_controller.rb
kaui-0.4.2 app/controllers/kaui/engine_controller.rb
kaui-0.4.1 app/controllers/kaui/engine_controller.rb