class ConverserConfig

Attributes

app_api_key[RW]
framework[RW]
server_url[RW]

Public Class Methods

new(config) click to toggle source
# File lib/motion/project/converser.rb, line 8
def initialize(config)
  @config = config
end

Public Instance Methods

app_api_key=(app_api_key) click to toggle source
# File lib/motion/project/converser.rb, line 23
def app_api_key=(app_api_key)
  @app_api_key = app_api_key
  create_code
end
framework=(path) click to toggle source
# File lib/motion/project/converser.rb, line 12
def framework=(path)
  if @framework != path
    @config.unvendor_project(@framework)
    @framework = path
    @config.vendor_project(path, :static, :products => ['libVGConversationKit_universal.a'], :headers_dir => 'include')
    @config.resources_dirs << "#{path}/ConverserResources"
    @config.frameworks << 'MessageUI'
    create_code
  end
end
server_url=(server_url) click to toggle source
# File lib/motion/project/converser.rb, line 28
def server_url=(server_url)
  @server_url = server_url
  create_code
end

Private Instance Methods

add_file(path) click to toggle source
# File lib/motion/project/converser.rb, line 58
def add_file(path)
  files = @config.files.flatten
  @config.files << path unless files.find { |x| File.expand_path(x) == File.expand_path(path) }
end
create_code() click to toggle source
# File lib/motion/project/converser.rb, line 35
  def create_code
    return unless @framework && @app_api_key && @server_url
    code = <<EOF
# This file is automatically generated. Do not edit.

class ConverserEngine
  def self.instance
    Dispatch.once { @instance ||= VGConversationEngine.alloc.initWithHostName('#{@server_url}', andKey: '#{@app_api_key}') }
    @instance
  end
end
EOF
    converser_file = './app/converser_code.rb'
    create_stub(converser_file, code)
    add_file(converser_file)
  end
create_stub(path, code) click to toggle source
# File lib/motion/project/converser.rb, line 52
def create_stub(path, code)
  if !File.exist?(path) or File.read(path) != code
    File.open(path, 'w') { |io| io.write(code) }
  end
end