def initialize(dev_token=nil, associate=nil, locale=nil, cache=nil,
user_agent = USER_AGENT)
def_locale = locale
locale = 'us' unless locale
locale.downcase!
configs = [ '/etc/amazonrc' ]
configs << File.expand_path('~/.amazonrc') if ENV.key?('HOME')
@config = {}
configs.each do |config|
if File.exists?(config) && File.readable?(config)
Amazon::dprintf("Opening %s ...\n", config)
File.open(config) { |f| lines = f.readlines }.each do |line|
line.chomp!
next if line =~ /^(#|$)/
Amazon::dprintf("Read: %s\n", line)
begin
match = line.match(/^(\S+)\s*=\s*(['"]?)([^'"]+)(['"]?)/)
key, begin_quote, val, end_quote = match[1,4]
raise ConfigError if begin_quote != end_quote
rescue NoMethodError, ConfigError
raise ConfigError, "bad config line: #{line}"
end
@config[key] = val
eval line.sub(/=/, '||=')
end
end
end
locale = @config['locale'] if @config.key?('locale') && ! def_locale
validate_locale(locale)
if dev_token.nil?
raise TokenError, 'dev_token may not be nil'
end
@token = dev_token
@id = associate || DEFAULT_ID[locale]
@user_agent = user_agent
@cache = unless cache == false
Amazon::Search::Cache.new(@config['cache_dir'] ||
'/tmp/amazon')
else
nil
end
self.locale = locale
end