src/UserAttribution.php
public function add($sourceId, $targetId, $roleId)
    {
        $request = (new RequestDescriptor())
            ->setUrl($this->buildUrl(self::IDP_ATTRIBUTIONS_API))
            ->setMethod('POST');

        $request->setBodyParams([
            'data' => json_encode([
                'source_id' => $sourceId,
                'target_id' => $targetId,
                'role_id' => $roleId,
            ])
        ]);

        try {
            $response = json_decode($this->send($request)->getBody(), true);
            return (count($response['added']) > 0 ? reset($response['added']) : null);
        } catch (\Exception $e) {
            $previous = $e->getPrevious();

            if ($previous instanceof BadResponseException) {
                $error = json_decode($previous->getResponse()->getBody(), true);

                throw new UserAttributionException($error['error'], $error['code'], $previous);
            }

            throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
        }
    }
public function add($sourceId, $targetId, $roleId)
    {
        $request = (new RequestDescriptor())
            ->setUrl($this->buildUrl(self::IDP_ATTRIBUTIONS_API))
            ->setMethod('POST');

        $request->setBodyParams([
            'data' => json_encode([
                'source_id' => $sourceId,
                'target_id' => $targetId,
                'role_id' => $roleId,
            ])
        ]);

        try {
            $response = json_decode($this->send($request)->getBody(), true);
            return (count($response['added']) > 0 ? reset($response['added']) : null);
        } catch (\Exception $e) {
            $previous = $e->getPrevious();

            if ($previous instanceof BadResponseException) {
                $error = json_decode($previous->getResponse()->getBody(), true);

                throw new UserAttributionException($error['error'], $error['code'], $previous);
            }

            throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
        }
    }
public function add ( $ sourceId , $ targetId , $ roleId ) { $ request = ( new RequestDescriptor ( ) ) -> setUrl ( $ this -> buildUrl ( self :: IDP_ATTRIBUTIONS_API ) ) -> setMethod ( 'POST' ) ; $ request -> setBodyParams ( [ 'data' => json_encode ( [ 'source_id' => $ sourceId , 'target_id' => $ targetId , 'role_id' => $ roleId , ] ) ] ) ; try { $ response = json_decode ( $ this -> send ( $ request ) -> getBody ( ) , true ) ; return ( count ( $ response [ 'added' ] ) > 0 ? reset ( $ response [ 'added' ] ) : null ) ; } catch ( \ Exception $ e ) { $ previous = $ e -> getPrevious ( ) ; if ( $ previous instanceof BadResponseException ) { $ error = json_decode ( $ previous -> getResponse ( ) -> getBody ( ) , true ) ; throw new UserAttributionException ( $ error [ 'error' ] , $ error [ 'code' ] , $ previous ) ; } throw new UserAttributionException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e -> getPrevious ( ) ) ; } }
Add an Attribution

@param int $sourceId
@param int $targetId
@param int $roleId

@return Attribution|null
Add an Attribution