def query(type, query = {})
    query = force_case(query).reject {|k, v| v.nil? }
    if attrs = query['attributes']
      attrs = Util.arglist(attrs).map {|a| force_attr(a)}
      query['attributes'] = Util.strlist(attrs, ",")
    end
    qstr = query.empty?? '': "?#{Util.encode_form(query)}"
    info = json_get(@target, "#{type_info(type, :path)}#{qstr}",
        @key_style,  headers)
    unless info.is_a?(Hash) && info[rk = jkey(:resources)].is_a?(Array)

      # hide client endpoints that are not yet scim compatible
      if type == :client && info.is_a?(Hash)
        info = info.each{ |k, v| fake_client_id(v) }.values
        if m = /^client_id\s+eq\s+"([^"]+)"$/i.match(query['filter'])
          idk = jkey(:client_id)
          info = info.select { |c| c[idk].casecmp(m[1]) == 0 }
        end
        return {rk => info}
      end

      raise BadResponse, "invalid reply to #{type} query of #{@target}"
    end
    info
  end
def query(type, query = {})
    query = force_case(query).reject {|k, v| v.nil? }
    if attrs = query['attributes']
      attrs = Util.arglist(attrs).map {|a| force_attr(a)}
      query['attributes'] = Util.strlist(attrs, ",")
    end
    qstr = query.empty?? '': "?#{Util.encode_form(query)}"
    info = json_get(@target, "#{type_info(type, :path)}#{qstr}",
        @key_style,  headers)
    unless info.is_a?(Hash) && info[rk = jkey(:resources)].is_a?(Array)

      # hide client endpoints that are not yet scim compatible
      if type == :client && info.is_a?(Hash)
        info = info.each{ |k, v| fake_client_id(v) }.values
        if m = /^client_id\s+eq\s+"([^"]+)"$/i.match(query['filter'])
          idk = jkey(:client_id)
          info = info.select { |c| c[idk].casecmp(m[1]) == 0 }
        end
        return {rk => info}
      end

      raise BadResponse, "invalid reply to #{type} query of #{@target}"
    end
    info
  end
Gets a set of attributes for each object that matches a given filter.
 @param (see #add)
 @param [Hash] query may contain the following keys:
   * +attributes+: a comma or space separated list of attribute names to be
     returned for each object that matches the filter. If no attribute
     list is given, all attributes are returned.
   * +filter+: a filter to select which objects are returned. See
     {http://www.simplecloud.info/specs/draft-scim-api-01.html#query-resources}
   * +startIndex+: for paged output, start index of requested result set.
   * +count+: maximum number of results per reply
 @return [Hash] including a +resources+ array of results and
   pagination data.