Skip to content
Merged
26 changes: 22 additions & 4 deletions src/Bynder/Api/Impl/AssetBankManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(IOauthRequestHandler $requestHandler)
*/
public function getBrands()
{
return $this->requestHandler->sendRequestAsync('GET', 'api/v4/brands');
return $this->requestHandler->sendRequestAsync('GET', 'api/v4/brands/');
}

/**
Expand All @@ -60,7 +60,7 @@ public function getBrands()
*/
public function getMediaList($query = null)
{
return $this->requestHandler->sendRequestAsync('GET', 'api/v4/media',
return $this->requestHandler->sendRequestAsync('GET', 'api/v4/media/',
array(
'query' => $query
)
Expand Down Expand Up @@ -91,7 +91,7 @@ public function getMediaInfo($mediaId, $query = null)
*/
public function getMetaproperties()
{
return $this->requestHandler->sendRequestAsync('GET', 'api/v4/metaproperties');
return $this->requestHandler->sendRequestAsync('GET', 'api/v4/metaproperties/');
}

/**
Expand All @@ -101,7 +101,7 @@ public function getMetaproperties()
*/
public function getTags()
{
return $this->requestHandler->sendRequestAsync('GET', 'api/v4/tags');
return $this->requestHandler->sendRequestAsync('GET', 'api/v4/tags/');
}

/**
Expand Down Expand Up @@ -136,4 +136,22 @@ public function deleteMedia($mediaId)
return $this->requestHandler->sendRequestAsync('DELETE', 'api/v4/media/' . $mediaId . '/');
}

/**
* Modifies existing assets fields
* @link http://docs.bynder.apiary.io/#reference/assets/specific-asset-operations/modify-asset
*
* @param string $mediaId
* @param array $data File information to be set
* array(
* 'name' => 'Image Name',
* 'description' => 'Image description'
* );
* @return \GuzzleHttp\Promise\Promise
*/
public function modifyMedia($mediaId, array $data)
{
return $this->requestHandler->sendRequestAsync('POST', 'api/v4/media/' . $mediaId . '/', ['form_params' => $data]);
}


}
4 changes: 2 additions & 2 deletions src/Bynder/Api/Impl/Oauth/IOauthRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ interface IOauthRequestHandler
* @param string $uri API call endpoint.
* @param array $query Optional dictionary of params which will be added to the request.
*
* @return Promise
* @throws Exception
* @return \GuzzleHttp\Promise\Promise
* @throws \Exception
*/
public function sendRequestAsync($type, $uri, $query = null);
}
6 changes: 3 additions & 3 deletions src/Bynder/Api/Impl/Oauth/OauthRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class OauthRequestHandler implements IOauthRequestHandler
* Initialises an instance of OauthRequestHandler.
*
* @param Credentials $credentials
* @param type $baseUrl
* @param string $baseUrl
*/
public function __construct(Credentials $credentials, $baseUrl)
{
Expand All @@ -54,8 +54,8 @@ public function __construct(Credentials $credentials, $baseUrl)
* Creates an instance of OauthRequestHandler using the settings provided.
*
*
* @param Credentials The Bynder oauth credentials.
* @param $baseUrl Api base url used for all requests.
* @param Credentials $credentials The Bynder oauth credentials.
* @param string $baseUrl Api base url used for all requests.
*
* @return OauthRequestHandler An instance of the request handler properly configured.
*/
Expand Down
38 changes: 33 additions & 5 deletions tests/AssetBank/AssetBankManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function testGetBrands()

$stub->expects($this->once())
->method('sendRequestAsync')
->with('GET', 'api/v4/brands')
->with('GET', 'api/v4/brands/')
->willReturn(array());

$assetBankManager = new AssetBankManager($stub);
Expand All @@ -44,7 +44,7 @@ public function testGetMediaList()
->getMock();

$stub->method('sendRequestAsync')
->with('GET', 'api/v4/media')
->with('GET', 'api/v4/media/')
->willReturn($returnedMedia);

$assetBankManager = new AssetBankManager($stub);
Expand All @@ -60,7 +60,7 @@ public function testGetMediaList()
'type' => 'image'
);
$stub->method('sendRequestAsync')
->with('GET', 'api/v4/media', array('query' => $query))
->with('GET', 'api/v4/media/', array('query' => $query))
->willReturn($returnedMedia);

$assetBankManager = new AssetBankManager($stub);
Expand Down Expand Up @@ -116,7 +116,7 @@ public function testGetMetaproperties()
->getMock();

$stub->method('sendRequestAsync')
->with('GET', 'api/v4/metaproperties')
->with('GET', 'api/v4/metaproperties/')
->willReturn($returnedMedia);

$assetBankManager = new AssetBankManager($stub);
Expand All @@ -139,7 +139,7 @@ public function testGetTags()
->getMock();

$stub->method('sendRequestAsync')
->with('GET', 'api/v4/tags')
->with('GET', 'api/v4/tags/')
->willReturn($returnedMedia);

$assetBankManager = new AssetBankManager($stub);
Expand Down Expand Up @@ -171,4 +171,32 @@ public function testGetCategories()
self::assertNotNull($categoryList);
self::assertEquals($categoryList, $returnedMedia);
}

/**
* Test if we call modifyMedia it will use the correct params for the request and returns successfully.
* HINT: it is rather skeleton, to use it properly this test requires much more complex mock with configured asset
*
* @covers \Bynder\Api\Impl\AssetBankManager::modifyMedia()
*/
public function testModifyMedia()
{
$return = array();
$stub = $this->getMockBuilder('Bynder\Api\Impl\Oauth\IOauthRequestHandler')
->disableOriginalConstructor()
->getMock();

$mediaId = 1111;
$formData = ['name' => 'test'];

$stub->method('sendRequestAsync')
->with('POST', 'api/v4/media/'.$mediaId.'/', ['form_params' => $formData])
->willReturn($return);

$assetBankManager = new AssetBankManager($stub);
$modifyMediaReturn = $assetBankManager->modifyMedia($mediaId, $formData);

self::assertNotNull($modifyMediaReturn);
self::assertEquals($modifyMediaReturn, $return);
}

}