Sha256: 5571276ded38ac3631d6f25f142342c7711d40cbb0737f83be4ffb6941997ce8

Contents?: true

Size: 1.38 KB

Versions: 7

Compression:

Stored size: 1.38 KB

Contents

module Killbill::Zendesk
  class UserUpdaterInitializer
    include Singleton

    attr_reader :updater

    def initialize!(conf_dir, kb_apis, logger)
      # Parse the config file
      begin
        @config = YAML.load_file("#{conf_dir}/zendesk.yml")
      rescue Errno::ENOENT
        logger.warn "Unable to find the config file #{conf_dir}/zendesk.yml"
        return
      end

      logger.log_level = Logger::DEBUG if (@config[:logger] || {})[:debug]

      client = ZendeskAPI::Client.new do |config|
        config.url = "https://#{@config[:zendesk][:subdomain]}.zendesk.com/api/v2"

        config.username = @config[:zendesk][:username]
        config.password = @config[:zendesk][:password]
        config.token = @config[:zendesk][:token]
        # Not yet available?
        #config.access_token = @config[:zendesk][:access_token]
        config.retry = true if @config[:zendesk][:retry]

        config.logger = logger
      end

      if defined?(JRUBY_VERSION)
        # See https://github.com/jruby/activerecord-jdbc-adapter/issues/302
        require 'jdbc/mysql'
        Jdbc::MySQL.load_driver(:require) if Jdbc::MySQL.respond_to?(:load_driver)
      end

      ActiveRecord::Base.establish_connection(@config[:database])
      ActiveRecord::Base.logger = logger

      @updater = UserUpdater.new(client, kb_apis, logger)
    end

    def initialized?
      !@updater.nil?
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
killbill-zendesk-2.0.0 lib/zendesk/user_updater_initializer.rb
killbill-zendesk-1.3.0 lib/zendesk/user_updater_initializer.rb
killbill-zendesk-1.2.4 lib/zendesk/user_updater_initializer.rb
killbill-zendesk-1.2.3 lib/zendesk/user_updater_initializer.rb
killbill-zendesk-1.2.2 lib/zendesk/user_updater_initializer.rb
killbill-zendesk-1.2.1 lib/zendesk/user_updater_initializer.rb
killbill-zendesk-1.2.0 lib/zendesk/user_updater_initializer.rb