protected function prepareGuzzleOptions(ServiceRequestInterface $request, $httpMethod = null)
    {
        if ( ! $httpMethod) {
            $httpMethod = $this->determineHttpMethod($request);
        }

        $options = [
            'http_errors' => false,
        ];


        // handle authentication

        $credentials = $request->getCredentials();

        if (    $this->basicAuth
            &&  ! empty($credentials['name'])
            &&  ! empty($credentials['password'])
        ) {
            $options['auth'] = [ $credentials['name'], $credentials['password'] ];
        }


        // handle parameters and body

        switch ($httpMethod) {

            case static::METHOD_PATCH:
            case static::METHOD_POST:
            case static::METHOD_PUT:
                if ($this->multipart) {
                    $options['multipart'] = $this->prepareMultipartData($request->getBody());
                } elseif ($this->sendJson) {
                    $options['json'] = $request->getBody();
                } else {
                    $options['form_params'] = $request->getBody();
                }

                $parameters = $request->getParameters();

                if ( ! empty($parameters)) {
                    $options['query'] = $parameters;
                }
                break;

            case static::METHOD_DELETE:
            case static::METHOD_GET:
                $options['query'] = $request->getBody() ?: [];
                break;

            // default omitted on purpose
        }

        // headers

        $headers = $request->getHeaders();

        if (count($headers)) {
            $options['headers'] = $headers;
        }

        return $options;
    }
protected function prepareGuzzleOptions(ServiceRequestInterface $request, $httpMethod = null)
    {
        if ( ! $httpMethod) {
            $httpMethod = $this->determineHttpMethod($request);
        }

        $options = [
            'http_errors' => false,
        ];


        // handle authentication

        $credentials = $request->getCredentials();

        if (    $this->basicAuth
            &&  ! empty($credentials['name'])
            &&  ! empty($credentials['password'])
        ) {
            $options['auth'] = [ $credentials['name'], $credentials['password'] ];
        }


        // handle parameters and body

        switch ($httpMethod) {

            case static::METHOD_PATCH:
            case static::METHOD_POST:
            case static::METHOD_PUT:
                if ($this->multipart) {
                    $options['multipart'] = $this->prepareMultipartData($request->getBody());
                } elseif ($this->sendJson) {
                    $options['json'] = $request->getBody();
                } else {
                    $options['form_params'] = $request->getBody();
                }

                $parameters = $request->getParameters();

                if ( ! empty($parameters)) {
                    $options['query'] = $parameters;
                }
                break;

            case static::METHOD_DELETE:
            case static::METHOD_GET:
                $options['query'] = $request->getBody() ?: [];
                break;

            // default omitted on purpose
        }

        // headers

        $headers = $request->getHeaders();

        if (count($headers)) {
            $options['headers'] = $headers;
        }

        return $options;
    }
protected function prepareGuzzleOptions ( ServiceRequestInterface $ request , $ httpMethod = null ) { if ( ! $ httpMethod ) { $ httpMethod = $ this -> determineHttpMethod ( $ request ) ; } $ options = [ 'http_errors' => false , ] ; // handle authentication $ credentials = $ request -> getCredentials ( ) ; if ( $ this -> basicAuth && ! empty ( $ credentials [ 'name' ] ) && ! empty ( $ credentials [ 'password' ] ) ) { $ options [ 'auth' ] = [ $ credentials [ 'name' ] , $ credentials [ 'password' ] ] ; } // handle parameters and body switch ( $ httpMethod ) { case static :: METHOD_PATCH : case static :: METHOD_POST : case static :: METHOD_PUT : if ( $ this -> multipart ) { $ options [ 'multipart' ] = $ this -> prepareMultipartData ( $ request -> getBody ( ) ) ; } elseif ( $ this -> sendJson ) { $ options [ 'json' ] = $ request -> getBody ( ) ; } else { $ options [ 'form_params' ] = $ request -> getBody ( ) ; } $ parameters = $ request -> getParameters ( ) ; if ( ! empty ( $ parameters ) ) { $ options [ 'query' ] = $ parameters ; } break ; case static :: METHOD_DELETE : case static :: METHOD_GET : $ options [ 'query' ] = $ request -> getBody ( ) ? : [ ] ; break ; // default omitted on purpose } // headers $ headers = $ request -> getHeaders ( ) ; if ( count ( $ headers ) ) { $ options [ 'headers' ] = $ headers ; } return $ options ; }
Prepares and returns guzzle options array for next call

@param ServiceRequestInterface $request
@param null|string             $httpMethod
@return array
Prepares and returns guzzle options array for next call