common/components/clients/service/Request.php
/**
     * Sends request and returns response instance
     *
     * @return Response
     */
Sends request and returns response instance
@return Response
Sends request and returns response instance @return Response
public function send()
    {
        $request = $this->httpClient->createRequest($this->method, $this->url, ['exceptions' => false]);
        $query = $request->getQuery();
        $query->set('_format', $this->getOption('format', Response::FORMAT_JSON));
        $auth = $this->getOption('auth', null);
        if ($auth !== null) {
            $authType = isset($auth['type']) ? strtolower($auth['type']) : null;
            if ($authType == 'basic') {
                $usrpwd = base64_encode($auth['username'].':'.$auth['password']);
                $request->addHeader('Authorization', "Basic $usrpwd");
            } else if ($authType == 'bearer') {
                $request->addHeader('Authorization', "Bearer {$auth['accessToken']}");
            }
        }
        switch ($this->method) {
            case self::METHOD_GET:
                $query = $request->getQuery();
                foreach ($this->params as $param=>$value) {
                    $query->set($param, $value);
                }
                break;
            case self::METHOD_POST:
            case self::METHOD_PUT:
            case self::METHOD_DELETE:
                $body = $request->getBody();
                foreach ($this->params as $param=>$value) {
                    $body->setField($param, $value);
                }
                break;
        }
        $response = $this->httpClient->send($request);
        return new Response($response, $this->getOption('format', Response::FORMAT_JSON));
    }
public function send ( ) { $ request = $ this -> httpClient -> createRequest ( $ this -> method , $ this -> url , [ 'exceptions' => false ] ) ; $ query = $ request -> getQuery ( ) ; $ query -> set ( '_format' , $ this -> getOption ( 'format' , Response :: FORMAT_JSON ) ) ; $ auth = $ this -> getOption ( 'auth' , null ) ; if ( $ auth !== null ) { $ authType = isset ( $ auth [ 'type' ] ) ? strtolower ( $ auth [ 'type' ] ) : null ; if ( $ authType == 'basic' ) { $ usrpwd = base64_encode ( $ auth [ 'username' ] . ':' . $ auth [ 'password' ] ) ; $ request -> addHeader ( 'Authorization' , " Basic  $ usrpwd " ) ; } else if ( $ authType == 'bearer' ) { $ request -> addHeader ( 'Authorization' , " Bearer  { $ auth [ 'accessToken' ] } " ) ; } } switch ( $ this -> method ) { case self :: METHOD_GET : $ query = $ request -> getQuery ( ) ; foreach ( $ this -> params as $ param => $ value ) { $ query -> set ( $ param , $ value ) ; } break ; case self :: METHOD_POST : case self :: METHOD_PUT : case self :: METHOD_DELETE : $ body = $ request -> getBody ( ) ; foreach ( $ this -> params as $ param => $ value ) { $ body -> setField ( $ param , $ value ) ; } break ; } $ response = $ this -> httpClient -> send ( $ request ) ; return new Response ( $ response , $ this -> getOption ( 'format' , Response :: FORMAT_JSON ) ) ; }
Sends request and returns response instance
 @return Response
Sends request and returns response instance @return Response
//Create request //Set response format //Set auth header //Add params to request //Send request //Construct new Response instance from http client response and return it