Builds the api query
516201
def __build_url(self, api_call, **kwargs):
        """"""
        kwargs['key'] = self.api_key
        if 'language' not in kwargs:
            kwargs['language'] = self.language
        if 'format' not in kwargs:
            kwargs['format'] = self.__format
        api_query = urlencode(kwargs)

        return "{0}{1}?{2}".format(urls.BASE_URL,
                                   api_call,
                                   api_query)
540915
public <T>
    Query<T> build(
                    final Query<T> query,
                    final QueryParams params
                    )
    {
//        query.disableValidation();

        for (String  key : params.keys()) {
            Handler  handler = _getHandler( key );
            String  field = _getField( key );
            String  value = params.get( key );

            if (CommonQueryParams.Key.ORDER.equalsIgnoreCase( key )) {
                value = _convertOrderingFields( value );
            }

            handler.build( query, field, value );
        }

        return query;
    }
758727
def basic_query(returns):
    """"""
    return compose(
        reusable,
        map_send(parse_request),
        map_yield(prepare_params, snug.prefix_adder(API_PREFIX)),
        map_return(loads(returns)),
        oneyield,
    )
207028
def _query(method='GET', profile=None, url=None, path='api/v1',
           action=None, api_key=None, service=None, params=None,
           data=None, subdomain=None, verify_ssl=True):
    '''
    

    '''

    if profile:
        creds = __salt__['config.option'](profile)
    else:
        creds = {
            'pagerduty.api_key': api_key,
            'pagerduty.subdomain': subdomain,
        }

    if url is None:
        url = 'https://{0}.pagerduty.com/{1}/{2}'.format(
            creds['pagerduty.subdomain'],
            path,
            action
        )

    if params is None:
        params = {}

    if data is None:
        data = {}

    headers = {
        'Authorization': 'Token token={0}'.format(creds['pagerduty.api_key'])
    }

    if method != 'GET':
        headers['Content-type'] = 'application/json'

    result = requests.request(
        method,
        url,
        headers=headers,
        params=params,
        data=salt.utils.json.dumps(data),
        verify=verify_ssl
    )

    if result.text is None or result.text == '':
        return None
    result_json = result.json()
    # if this query supports pagination, loop and fetch all results, merge them together
    if 'total' in result_json and 'offset' in result_json and 'limit' in result_json:
        offset = result_json['offset']
        limit = result_json['limit']
        total = result_json['total']
        while offset + limit < total:
            offset = offset + limit
            limit = 100
            data['offset'] = offset
            data['limit'] = limit
            next_page_results = requests.request(method,
                                                 url,
                                                 headers=headers,
                                                 params=params,
                                                 data=data,  # Already serialized above, don't do it again
                                                 verify=verify_ssl).json()
            offset = next_page_results['offset']
            limit = next_page_results['limit']
            # merge results
            for k, v in result_json.items():
                if isinstance(v, list):
                    result_json[k] += next_page_results[k]
    return result_json
240534
function Query(server, query, options, token) {
  this.server = server;
  this.query = query;
  // Used to track the presence of r.args (workaround)
  this.originalQuery = util.deepCopy(query);
  this.options = {};
  this.context = {};
  this.frames = [];
  this.nowValue = ReqlDate.now();
  this.complete = false;
  this.token = token;

}
115730
function buildMethodName(req) {
    return [
        req.params.service,
        req.params.subservice
    ].filter(Boolean).join('-');
}
434621
function buildHTTPGetQuery( $request, $queryParams )
    {
        foreach ( $queryParams as $name => $value )
        {
            if ( is_array( $value ) )
            {
                foreach ( $value as $valueKey => $valuePart )
                {
                    $encodedQueryParams[] = urlencode( $name ) . '=' . urlencode( $valuePart );
                }
            }
            else
            {
                $encodedQueryParams[] = urlencode( $name ) . '=' . urlencode( $value );
            }
        }

        return $this->SearchServerURI . $request . '?' . implode( '&', $encodedQueryParams );
    }
1195460
function _http_build_query($data, $prefix=null, $sep=null, $key='', $urlencode=true)
    {
        $ret = array();
    
        foreach ( (array) $data as $k => $v )
        {
            if ( $urlencode)
                $k = urlencode($k);
            if ( is_int($k) && $prefix != null )
                $k = $prefix.$k;
            if ( !empty($key) )
                $k = $key . '%5B' . $k . '%5D';
            if ( $v === NULL )
                continue;
            elseif ( $v === FALSE )
                $v = '0';
    
            if ( is_array($v) || is_object($v) )
                array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
            elseif ( $urlencode )
                array_push($ret, $k.'='.urlencode($v));
            else
                array_push($ret, $k.'='.$v);
        }
    
        if ( NULL === $sep )
            $sep = ini_get('arg_separator.output');
    
        return implode($sep, $ret);
    }
1344916
def make_query(self, *args, **kwargs):
        
        query = Q()  # initial is an empty query
        query_dict = self._build_query_dict(self.cleaned_data)
        if 'negate' in self.cleaned_data and self.cleaned_data['negate']:
            query = query & ~Q(**query_dict)
        else:
            query = query & Q(**query_dict)
        return query
780927
def query(cls, owner=None, name=None, offset=None, limit=None, api=None):
        
        api = api if api else cls._API
        query_params = {}
        if owner:
            url = cls._URL['query'].format(owner=owner)
        else:
            url = cls._URL['query'].format(owner='')
        if name:
            query_params['name'] = name
        return super(Project, cls)._query(
            url=url, offset=offset, limit=limit, fields='_all',
            api=api, **query_params
        )
201210
public function build()
    {
        $query = $this->delegate->build();
        $this->utilityRegistry->addUtility(AdsUtility::SERVICE_QUERY_BUILDER);
        return $query;
    }
983085
protected function assembleQuery() {
		if (empty($this->query)) {
			if ($this->queryRaw === null) {
				return '';
			}
			
			return $this->queryRaw;
		}
		
		return '?' . http_build_query($this->query);
	}
491721
private function buildIndexAction() {
        $api = new Swagger\Api();
        $api->setPath('/' . $this->getClassName());
        $operation = new Swagger\Operation();
        $operation->setMethod('GET');
        $operation->setSummary('Lists all ' . $this->getClassName() . '.');
        $operation->setNotes(
            'Only returns the first 50 by default. Using the actual API you can search by parent fields and any field on the model as opposed to the brief list provided below.'
        );
        $responseMessage = new Swagger\ResponseMessage();
        $responseMessage->setCode(200);
        $responseMessage->setMessage('List of ' . $this->getClassName() . '.');
        $responseMessage->setResponseModel($this->getClassName());
        $operation->addResponseMessage($responseMessage);

        $responseMessage = $this->invalidFieldSpecifiedError();
        $operation->addResponseMessage($responseMessage);

        $responseMessage = $this->notAuthorizedResponse();
        $operation->addResponseMessage($responseMessage);

        $operation->addParameter($this->buildStartParameter());
        $operation->addParameter($this->buildCountParameter());
        $operation->addParameter($this->buildSortParameter());
        $operation->addParameter($this->buildFieldsParameter());
        $searchParameters = $this->buildSearchParameters();
        foreach($searchParameters as $searchParameter) {
            $operation->addParameter($searchParameter);
        }
        $api->addOperation($operation);

        $method = new Object\Method();
        $method->setDescription($api->__toString());
        $method->setReturnType('void');
        $method->setAccess('public');
        $method->setName('indexAction');
        $method->setContent('parent::indexAction();');
        $this->getObject()->addMethod($method);
    }
973253
def search(self, query=None, **kwargs):
        ""
        api_path = "/api/v2/search.json"
        api_query = {}
        if "query" in kwargs.keys():
            api_query.update(kwargs["query"])
            del kwargs["query"]
        if query:
            api_query.update({
                "query": query,
            })
        return self.call(api_path, query=api_query, **kwargs)
1042034
def create_request(query):
    
    yarr_url = app.config.get('YARR_URL', False)

    if not yarr_url:
        raise('No URL to Yarr! server specified in config.')

    api_token = app.config.get('YARR_API_TOKEN', False)
    headers = {'X-API-KEY': api_token} if api_token else {}
    payload = {'q': query}
    url = '%s/search' % yarr_url

    return requests.get(url, params=payload, headers=headers)
1284695
def raw_query(self, query, format=None, pretty=False):
        '''
        '''
        if format:
            format = format
        else:
            format = self.format

        payload = self._payload_builder(query, format=format)
        response = self.execute_query(payload)
        if pretty:
            response = self.response_builder(response)

        return response
1256856
def build_q(fields_dict, params_dict, request=None):
    
    # Building search query
    # queries generated by different search_fields are ANDed
    # if a search field is defined for more than one field, are put together with OR
    and_query = Q()

    for fieldname in fields_dict:
        search_field = fields_dict[fieldname]
        if fieldname in params_dict and params_dict[fieldname] != '' and params_dict[fieldname] != []:
            or_query = None

            if type(search_field) == type(list()):
                field_list = search_field
                search_operator = "__icontains"
                fixed_filters = None
                multiple_values = False
                custom_query_method = None
                value_mapper = None

            else: # dictionary of field definitions
                if search_field.get('ignore', False):
                    continue

                field_list = search_field['fields']
                search_operator = search_field.get('operator', None)
                fixed_filters = search_field.get('fixed_filters', None)
                multiple_values = search_field.get('multiple', False)
                custom_query_method =  search_field.get('custom_query', None)
                value_mapper =  search_field.get('value_mapper', None)

            for model_field in field_list:

                if multiple_values:
                    if hasattr(params_dict, "getlist"):
                        request_field_value = params_dict.getlist(fieldname)
                    elif type(params_dict[fieldname]) == list:
                        request_field_value = params_dict[fieldname]
                    else:
                        request_field_value = [params_dict[fieldname]]
                    if value_mapper:
                        request_field_value = [value_mapper(value) for value in request_field_value]
                else:
                    request_field_value = params_dict[fieldname] if not value_mapper else value_mapper(params_dict[fieldname])

                if not custom_query_method:
                    fieldname_key = model_field + search_operator
                    filter_dict = { fieldname_key : request_field_value}
                    if not or_query:
                        or_query = Q(**filter_dict)
                    else:
                        or_query = or_query | Q(**filter_dict)
                else:
                    #TODO: this is a hack for using request data in custom_query
                    #it would be better to pass ALSO the request to custom_query_method
                    if not request:
                        cf = custom_query_method(model_field, request_field_value, params_dict)
                    else:
                        cf = custom_query_method(model_field, request_field_value, request)

                    if not or_query:
                        or_query = cf
                    else:
                        or_query = or_query | cf

            #fixed_filters
            fixed_filters_q = Q()
            #fixed_filters must return a Q object or None
            if fixed_filters:
                if callable(fixed_filters):
                    fixed_filters_q = fixed_filters(params_dict)
                elif type(fixed_filters) is dict:
                    fixed_filters_q = Q(**fixed_filters)

            and_query = and_query & or_query
            and_query = and_query & fixed_filters_q


    return and_query