Class: Killbill::Zendesk::UserUpdaterInitializer

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/zendesk/user_updater_initializer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#updaterObject (readonly)

Returns the value of attribute updater.



5
6
7
# File 'lib/zendesk/user_updater_initializer.rb', line 5

def updater
  @updater
end

Instance Method Details

#initialize!(conf_dir, kb_apis, logger) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/zendesk/user_updater_initializer.rb', line 7

def initialize!(conf_dir, kb_apis, logger)
  # Parse the config file
  begin
    @config = YAML.load(ERB.new(File.read("#{conf_dir}/zendesk.yml")).result)
  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

  require 'active_record'
  require 'active_record/bogacs'
  require 'arjdbc'

  ::ActiveRecord::ConnectionAdapters::ConnectionHandler.connection_pool_class = ::ActiveRecord::Bogacs::FalsePool
  db_config = @config[:database] || {
      :adapter              => :mysql,
      # See KillbillActivator#KILLBILL_OSGI_JDBC_JNDI_NAME
      :data_source          => Java::JavaxNaming::InitialContext.new.lookup('killbill/osgi/jdbc'),
      # Since AR-JDBC 1.4, to disable session configuration
      :configure_connection => false
  }
  ActiveRecord::Base.establish_connection(db_config)

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

#initialized?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/zendesk/user_updater_initializer.rb', line 48

def initialized?
  !@updater.nil?
end