spec/core/spec_helper.rb
# tests fail when this is included in a Module (someone else also defines client)
tests fail when this is included in a Module (someone else also defines client)
tests fail when this is included in a Module ( someone else also defines client )
def client
  credentials = File.join(File.dirname(__FILE__), '..', 'fixtures', 'credentials.yml')
  @client ||= begin
    client = ZendeskAPI::Client.new do |config|
      if File.exist?(credentials)
        data = YAML.load(File.read(credentials))
        config.username = data["username"]
        if data["token"]
          config.access_token = data["token"]
          config.url_based_access_token = true
        else
          config.password = data["password"]
        end
        if data["auth"]
          config.extend(Module.new do
            attr_accessor :authorization
            def options
              super.tap do |options|
                options[:headers].merge!(
                  :authorization => "Basic #{Base64.urlsafe_encode64(authorization)}"
                )
              end
            end
          end)
          config.authorization = data["auth"]
        end
        config.url = data["url"]
        if data["url"].start_with?("http://")
          config.allow_http = true
        end
      else
        unless $credentials_warning
          STDERR.puts "using default credentials: live specs will fail."
          STDERR.puts "add your credentials to spec/fixtures/credentials.yml (see: spec/fixtures/credentials.yml.example)"
          $credentials_warning = true
        end
        config.username = "please.change"
        config.password = "me"
        config.url = "https://my.zendesk.com/api/v2"
      end
      config.logger = Logger.new("/dev/null")
      config.retry = true
    end
    client.config.logger.level = (ENV["LOG"] ? Logger::DEBUG : Logger::WARN)
    client.config.cache.size = 0
    client.callbacks.clear
    client.insert_callback do |env|
      warning = env[:response_headers]["X-Zendesk-API-Warn"]
      if warning && warning !~ /\["access_token"\]/ && client.config.logger
        client.config.logger.warn "WARNING: #{warning}"
      end
    end
    client
  end
end
def client credentials = File . join ( File . dirname ( __FILE__ ) , '..' , 'fixtures' , 'credentials.yml' ) @client ||= begin client = ZendeskAPI :: Client . new do | config | if File . exist? ( credentials ) data = YAML . load ( File . read ( credentials ) ) config . username = data [ "username" ] if data [ "token" ] config . access_token = data [ "token" ] config . url_based_access_token = true else config . password = data [ "password" ] end if data [ "auth" ] config . extend ( Module . new do attr_accessor :authorization def options super . tap do | options | options [ :headers ] . merge! ( :authorization => "Basic #{Base64.urlsafe_encode64(authorization)}" ) end end end ) config . authorization = data [ "auth" ] end config . url = data [ "url" ] if data [ "url" ] . start_with? ( "http://" ) config . allow_http = true end else unless $credentials_warning STDERR . puts "using default credentials: live specs will fail." STDERR . puts "add your credentials to spec/fixtures/credentials.yml (see: spec/fixtures/credentials.yml.example)" $credentials_warning = true end config . username = "please.change" config . password = "me" config . url = "https://my.zendesk.com/api/v2" end config . logger = Logger . new ( "/dev/null" ) config . retry = true end client . config . logger . level = ( ENV [ "LOG" ] ? Logger :: DEBUG : Logger :: WARN ) client . config . cache . size = 0 client . callbacks . clear client . insert_callback do | env | warning = env [ :response_headers ] [ "X-Zendesk-API-Warn" ] if warning && warning !~ / \[ "access_token" \] / && client . config . logger client . config . logger . warn "WARNING: #{warning}" end end client end end
tests fail when this is included in a Module (someone else also defines client)
tests fail when this is included in a Module ( someone else also defines client )