def authenticate
      # :x_amee_source = "X-AMEE-Source".to_sym
      request = Typhoeus::Request.new("#{protocol}#{@server}/auth/signIn", 
        :method => "post",
        :verbose => DEBUG,
        :headers => {
          :Accept => content_type(:xml),
        },
        :body => form_encode(:username=>@username, :password=>@password)
      )

      hydra.queue(request)
      hydra.run
      response = request.response

      @auth_token = response.headers_hash['AuthToken']
      d {request.url}
      d {response.code}
      d {@auth_token}

      connection_failed if response.code == 0

      unless authenticated?
        raise AMEE::AuthFailed.new("Authentication failed. Please check your username and password. (tried #{@username},#{@password})")
      end
      # Detect API version
      if response.body.is_json?
        @version = JSON.parse(response.body)["user"]["apiVersion"].to_f
      elsif response.body.is_xml?
        @version = REXML::Document.new(response.body).elements['Resources'].elements['SignInResource'].elements['User'].elements['ApiVersion'].text.to_f
      else
        @version = 1.0
      end
    end
def authenticate
      # :x_amee_source = "X-AMEE-Source".to_sym
      request = Typhoeus::Request.new("#{protocol}#{@server}/auth/signIn", 
        :method => "post",
        :verbose => DEBUG,
        :headers => {
          :Accept => content_type(:xml),
        },
        :body => form_encode(:username=>@username, :password=>@password)
      )

      hydra.queue(request)
      hydra.run
      response = request.response

      @auth_token = response.headers_hash['AuthToken']
      d {request.url}
      d {response.code}
      d {@auth_token}

      connection_failed if response.code == 0

      unless authenticated?
        raise AMEE::AuthFailed.new("Authentication failed. Please check your username and password. (tried #{@username},#{@password})")
      end
      # Detect API version
      if response.body.is_json?
        @version = JSON.parse(response.body)["user"]["apiVersion"].to_f
      elsif response.body.is_xml?
        @version = REXML::Document.new(response.body).elements['Resources'].elements['SignInResource'].elements['User'].elements['ApiVersion'].text.to_f
      else
        @version = 1.0
      end
    end
Post to the sign in resource on the API, so that all future
 requests are signed