def initialize(config, options={})
if config[:uri].nil? && config[:apidoc_cache_dir].nil?
raise ApipieBindings::ConfigurationError.new('Either :uri or :apidoc_cache_dir needs to be set')
end
@uri = config[:uri]
@api_version = config[:api_version] || 1
@language = config[:language]
apidoc_cache_base_dir = config[:apidoc_cache_base_dir] || File.join(File.expand_path('~/.cache'), 'apipie_bindings')
@apidoc_cache_dir = config[:apidoc_cache_dir] || File.join(apidoc_cache_base_dir, @uri.tr(':/', '_'), "v#{@api_version}")
@apidoc_cache_name = config[:apidoc_cache_name] || set_default_name
@apidoc_authenticated = (config[:apidoc_authenticated].nil? ? true : config[:apidoc_authenticated])
@dry_run = config[:dry_run] || false
@aggressive_cache_checking = config[:aggressive_cache_checking] || false
@fake_responses = config[:fake_responses] || {}
@logger = config[:logger]
unless @logger
@logger = Logger.new(STDERR)
@logger.level = Logger::ERROR
end
config = config.dup
headers = {
:content_type => 'application/json',
:accept => "application/json;version=#{@api_version}"
}
headers.merge!({ "Accept-Language" => language }) if language
headers.merge!(config[:headers]) unless config[:headers].nil?
headers.merge!(options.delete(:headers)) unless options[:headers].nil?
log.debug "Global headers: #{headers.ai}"
@credentials = config[:credentials] if config[:credentials] && config[:credentials].respond_to?(:to_params)
@resource_config = {
:timeout => config[:timeout],
:headers => headers,
:verify_ssl => false
}.merge(options)
@config = config
end