Skip to content

Commit

Permalink
add limit param to file list request
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-mukhin committed Jan 23, 2014
1 parent eb8606f commit ff12b7b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 16 deletions.
8 changes: 6 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Changelog

## 1.6
## 1.0.7

- support 'limit' param in Api->getFileList() and Api->getFilePaginationInfo()

## 1.0.6

- deprecate File->file_id, use File->uuid
- fix Api->getFileList()

## 1.5
## 1.0.5

- bump widget version to 0.17.1 (see [widget changelog][widget changelog])
- fix HEAD requests
Expand Down
21 changes: 20 additions & 1 deletion tests/5.2/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,39 @@ public function testPublicKeyValid()
}

/**
* Test that getFilesList mehtod returns array
* Test that getFilesList method returns array
* and each item of array is an object of Uploadcare_File class
*/
public function testFileList()
{
$api = new Uploadcare_Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
$files = $api->getFileList();
$this->assertTrue(is_array($files));
$this->assertEquals(20, count($files));

$files = $api->getFileList(1, 2);
$this->assertTrue(is_array($files));
$this->assertEquals(2, count($files));

foreach ($files as $file) {
$this->assertTrue(get_class($file) == 'Uploadcare_File');
}
}

/**
* Test getFilePaginationInfo method
*/
public function testFileListPaginationInfo()
{
$api = new Uploadcare_Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
$result = $api->getFilePaginationInfo();
$this->assertEquals(20, $result['per_page']);

$result = $api->getFilePaginationInfo(2, 1);
$this->assertEquals(1, $result['per_page']);
$this->assertEquals(2, $result['page']);
}

/**
* Test requests for exceptions to "raw" url
*/
Expand Down
21 changes: 20 additions & 1 deletion tests/5.3/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,39 @@ public function testPublicKeyValid()
}

/**
* Test that getFilesList mehtod returns array
* Test that getFilesList method returns array
* and each item of array is an object of Uploadcare\File class
*/
public function testFileList()
{
$api = new Uploadcare\Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
$files = $api->getFileList();
$this->assertTrue(is_array($files));
$this->assertEquals(20, count($files));

$files = $api->getFileList(1, 2);
$this->assertTrue(is_array($files));
$this->assertEquals(2, count($files));

foreach ($files as $file) {
$this->assertTrue(get_class($file) == 'Uploadcare\File');
}
}

/**
* Test getFilePaginationInfo method
*/
public function testFileListPaginationInfo()
{
$api = new Uploadcare\Api(UC_PUBLIC_KEY, UC_SECRET_KEY);
$result = $api->getFilePaginationInfo();
$this->assertEquals(20, $result['per_page']);

$result = $api->getFilePaginationInfo(2, 1);
$this->assertEquals(1, $result['per_page']);
$this->assertEquals(2, $result['page']);
}

/**
* Test requests for exceptions to "raw" url
*/
Expand Down
12 changes: 6 additions & 6 deletions uploadcare/lib/5.2/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Uploadcare_Api
*
* @var string
**/
public $version = '1.0.6/5.2';
public $version = '1.0.7/5.2';

/**
* Uploadcare rest API version
Expand Down Expand Up @@ -93,9 +93,9 @@ public function getPublicKey()
* @param integer $page Page to be shown.
* @return array
**/
public function getFileList($page = 1)
public function getFileList($page = 1, $limit = 20)
{
$data = $this->__preparedRequest('file_list', 'GET', array('page' => $page));
$data = $this->__preparedRequest('file_list', 'GET', array('page' => $page, 'limit' => $limit));
$files_raw = (array)$data->results;
$result = array();
foreach ($files_raw as $file_raw) {
Expand Down Expand Up @@ -137,9 +137,9 @@ public function getGroup($group_id)
* @param integer $page
* @return array
**/
public function getFilePaginationInfo($page = 1)
public function getFilePaginationInfo($page = 1, $limit = 20)
{
$data = (array)$this->__preparedRequest('file_list', 'GET', array('page' => $page));
$data = (array)$this->__preparedRequest('file_list', 'GET', array('page' => $page, 'limit' => $limit));
unset($data['results']);
return $data;
}
Expand Down Expand Up @@ -232,7 +232,7 @@ private function __getPath($type, $params = array())
case 'account':
return '/account/';
case 'file_list':
return sprintf('/files/?page=%s', $params['page']);
return sprintf('/files/?page=%s&limit=%s', $params['page'], $params['limit']);
case 'file_storage':
if (array_key_exists('uuid', $params) == false) {
throw new Exception('Please provide "uuid" param for request');
Expand Down
12 changes: 6 additions & 6 deletions uploadcare/lib/5.3-5.4/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Api
*
* @var string
*/
public $version = '1.0.6/5.3';
public $version = '1.0.7/5.3';

/**
* Uploadcare rest API version
Expand Down Expand Up @@ -89,9 +89,9 @@ public function getPublicKey()
* @param integer $page Page to be shown.
* @return array
*/
public function getFileList($page = 1)
public function getFileList($page = 1, $limit = 20)
{
$data = $this->__preparedRequest('file_list', 'GET', array('page' => $page));
$data = $this->__preparedRequest('file_list', 'GET', array('page' => $page, 'limit' => $limit));
$files_raw = (array)$data->results;
$result = array();
foreach ($files_raw as $file_raw) {
Expand Down Expand Up @@ -133,9 +133,9 @@ public function getGroup($group_id)
* @param integer $page
* @return array
*/
public function getFilePaginationInfo($page = 1)
public function getFilePaginationInfo($page = 1, $limit = 20)
{
$data = (array)$this->__preparedRequest('file_list', 'GET', array('page' => $page));
$data = (array)$this->__preparedRequest('file_list', 'GET', array('page' => $page, 'limit' => $limit));
unset($data['results']);
return $data;
}
Expand Down Expand Up @@ -228,7 +228,7 @@ private function __getPath($type, $params = array())
case 'account':
return '/account/';
case 'file_list':
return sprintf('/files/?page=%s', $params['page']);
return sprintf('/files/?page=%s&limit=%s', $params['page'], $params['limit']);
case 'file_storage':
if (array_key_exists('uuid', $params) == false) {
throw new \Exception('Please provide "uuid" param for request');
Expand Down

0 comments on commit ff12b7b

Please sign in to comment.