Sha256: 54fdac0a1f3a5970467af91dbe7db73a522a3a879208dba1c0a717eb3d6f0178

Contents?: true

Size: 957 Bytes

Versions: 2

Compression:

Stored size: 957 Bytes

Contents

require 'active_record'
require 'protected_attributes'
require 'sinatra'

require 'killbill'
require 'zendesk_api'

require 'zendesk/zendesk_user'
require 'zendesk/user_updater'
require 'zendesk/user_updater_initializer'

module Killbill::Zendesk
  class ZendeskPlugin < Killbill::Plugin::Notification

    # For testing
    attr_reader :updater

    def start_plugin
      super
      @updater = Killbill::Zendesk::UserUpdaterInitializer.instance.initialize!(@conf_dir, @kb_apis, @logger)
    end

    def after_request
      # return DB connections to the Pool if required
      ::ActiveRecord::Base.connection.close if ::ActiveRecord::Base.connection_pool.active_connection?
    end

    def on_event(event)
      if @updater.nil?
        logger.warn "ZendeskPlugin wasn't started properly - check logs"
        return
      end
      @updater.update(event.account_id) if [:ACCOUNT_CREATION, :ACCOUNT_CHANGE].include?(event.event_type)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
killbill-zendesk-3.0.1 lib/zendesk.rb
killbill-zendesk-3.0.0 lib/zendesk.rb