diff --git a/README.md b/README.md index 234b022..6a19fc6 100644 --- a/README.md +++ b/README.md @@ -210,6 +210,43 @@ foreach ($release['images'] as $image) { ``` +### User Collection + +Authorization is required when `folder_id` is not `0`. + +#### Get collection folders + +```php +getCollectionFolders([ + 'username' => 'example' +]); +``` + +#### Get collection folder + + +```php +getCollectionFolder([ + 'username' => 'example', + 'folder_id' => 1 +]); +``` + +#### Get collection items by folder + +```php +getCollectionItemsByFolder([ + 'username' => 'example', + 'folder_id' => 3 +]); +``` + ## Documentation Further documentation can be found at the [Discogs API v2.0 Documentation](http://www.discogs.com/developers/index.html). diff --git a/resources/service.php b/resources/service.php index 3b9108e..8374d92 100644 --- a/resources/service.php +++ b/resources/service.php @@ -400,6 +400,62 @@ 'required' => true ] ] + ], + 'getCollectionFolders' => [ + 'httpMethod' => 'GET', + 'uri' => 'users/{username}/collection/folders', + 'responseModel' => 'GetResponse', + 'parameters' => [ + 'username' => [ + 'type' => 'string', + 'location' => 'uri', + 'required' => true + ] + ] + ], + 'getCollectionFolder' => [ + 'httpMethod' => 'GET', + 'uri' => 'users/{username}/collection/folders/{folder_id}', + 'responseModel' => 'GetResponse', + 'parameters' => [ + 'username' => [ + 'type' => 'string', + 'location' => 'uri', + 'required' => true + ], + 'folder_id' => [ + 'type' => 'string', + 'location' => 'uri', + 'required' => true + ], + ] + ], + 'getCollectionItemsByFolder' => [ + 'httpMethod' => 'GET', + 'uri' => 'users/{username}/collection/folders/{folder_id}/releases', + 'responseModel' => 'GetResponse', + 'parameters' => [ + 'username' => [ + 'type' => 'string', + 'location' => 'uri', + 'required' => true + ], + 'folder_id' => [ + 'type' => 'string', + 'location' => 'uri', + 'required' => true + ], + 'per_page' => [ + 'type' => 'integer', + 'location' => 'query', + 'required' => false + ], + 'page' => [ + 'type' => 'string', + 'location' => 'query', + 'required' => false + ] + ] ] ], 'models' => [ diff --git a/tests/Discogs/Test/ClientTest.php b/tests/Discogs/Test/ClientTest.php index cffcee7..efd7882 100644 --- a/tests/Discogs/Test/ClientTest.php +++ b/tests/Discogs/Test/ClientTest.php @@ -267,6 +267,59 @@ public function testDeleteListing() $this->assertSame('https://api.discogs.com/marketplace/listings/129242581', $history->getLastRequest()->getUrl()); } + public function testGetCollectionFolders() + { + $history = new History(); + $client = $this->createClient('get_collection_folders', $history); + $response = $client->getCollectionFolders([ + 'username' => 'example' + ]); + + $this->assertInternalType('array', $response['folders']); + $this->assertCount(2, $response['folders']); + + $this->assertSame('https://api.discogs.com/users/example/collection/folders', $history->getLastRequest()->getUrl()); + $this->assertSame('GET', $history->getLastRequest()->getMethod()); + } + + public function testGetCollectionFolder() + { + $history = new History(); + $client = $this->createClient('get_collection_folder', $history); + $response = $client->getCollectionFolder([ + 'username' => 'example', + 'folder_id' => 1 + ]); + + $this->assertSame($response['id'], 1); + $this->assertSame($response['count'], 20); + $this->assertSame($response['name'], 'Uncategorized'); + $this->assertSame($response['resource_url'], "https://api.discogs.com/users/example/collection/folders/1"); + + $this->assertSame('https://api.discogs.com/users/example/collection/folders/1', $history->getLastRequest()->getUrl()); + $this->assertSame('GET', $history->getLastRequest()->getMethod()); + } + + public function testGetCollectionItemsByFolder() + { + $history = new History(); + $client = $this->createClient('get_collection_items_by_folder', $history); + $response = $client->getCollectionItemsByFolder([ + 'username' => 'rodneyfool', + 'folder_id' => 3, + 'sort' => 'artist', + 'sort_order' => 'desc', + 'per_page' => 50, + 'page' => 1 + ]); + + $this->assertCount(1, $response['releases']); + $this->assertArrayHasKey('pagination', $response); + $this->assertArrayHasKey('per_page', $response['pagination']); + + $this->assertSame('https://api.discogs.com/users/rodneyfool/collection/folders/3/releases?per_page=50&page=1', $history->getLastRequest()->getUrl()); + $this->assertSame('GET', $history->getLastRequest()->getMethod()); + } protected function createClient($mock, History $history) { diff --git a/tests/fixtures/get_collection_folder b/tests/fixtures/get_collection_folder new file mode 100644 index 0000000..c38b634 --- /dev/null +++ b/tests/fixtures/get_collection_folder @@ -0,0 +1,14 @@ +HTTP/1.1 200 OK +Reproxy-Status: yes +Access-Control-Allow-Origin: * +Cache-Control: public, must-revalidate +Content-Type: application/json +Server: lighttpd +Content-Length: 132 +Date: Wed, 16 Jul 2014 23:20:21 GMT +X-Varnish: 1722533701 +Age: 0 +Via: 1.1 varnish +Connection: keep-alive + +{"id":1,"count":20,"name":"Uncategorized","resource_url":"https://api.discogs.com/users/example/collection/folders/1"} diff --git a/tests/fixtures/get_collection_folders b/tests/fixtures/get_collection_folders new file mode 100644 index 0000000..8059ca9 --- /dev/null +++ b/tests/fixtures/get_collection_folders @@ -0,0 +1,14 @@ +HTTP/1.1 200 OK +Reproxy-Status: yes +Access-Control-Allow-Origin: * +Cache-Control: public, must-revalidate +Content-Type: application/json +Server: lighttpd +Content-Length: 132 +Date: Wed, 16 Jul 2014 23:20:21 GMT +X-Varnish: 1722533701 +Age: 0 +Via: 1.1 varnish +Connection: keep-alive + +{"folders":[{"id":0,"count":23,"name":"All","resource_url":"https://api.discogs.com/users/example/collection/folders/0"},{"id":1,"count":20,"name":"Uncategorized","resource_url":"https://api.discogs.com/users/example/collection/folders/1"}]} diff --git a/tests/fixtures/get_collection_items_by_folder b/tests/fixtures/get_collection_items_by_folder new file mode 100644 index 0000000..14b447c --- /dev/null +++ b/tests/fixtures/get_collection_items_by_folder @@ -0,0 +1,14 @@ +HTTP/1.1 200 OK +Reproxy-Status: yes +Access-Control-Allow-Origin: * +Cache-Control: public, must-revalidate +Content-Type: application/json +Server: lighttpd +Content-Length: 132 +Date: Wed, 16 Jul 2014 23:20:21 GMT +X-Varnish: 1722533701 +Age: 0 +Via: 1.1 varnish +Connection: keep-alive + +{"pagination":{"per_page":1,"pages":14,"page":1,"items":14,"urls":{"next":"https://api.discogs.com/users/example/collection/folders/1/releases?page=2&per_page=1","last":"https://api.discogs.com/users/example/collection/folders/1/releases?page=2&per_page=14"}},"releases":[{"id":2464521,"instance_id":1,"folder_id":1,"rating":0,"basic_information":{"id":2464521,"title":"Information Chase","year":2006,"resource_url":"https://api.discogs.com/releases/2464521","thumb":"https://api-img.discogs.com/vzpYq4_kc52GZFs14c0SCJ0ZE84=/fit-in/150x150/filters:strip_icc():format(jpeg):mode_rgb()/discogs-images/R-2464521-1285519861.jpeg.jpg","cover_image":"https://api-img.discogs.com/vzpYq4_kc52GZFs14c0SCJ0ZE84/fit-in/500x500/filters:strip_icc():format(jpeg):mode_rgb():quality(90)/discogs-images/R-2464521-1285519861.jpeg.jpg","formats":[{"qty":"1","descriptions":["Mini","EP"],"name":"CDr"}],"labels":[{"resource_url":"https://api.discogs.com/labels/11647","entity_type":"","catno":"8BP059","id":11647,"name":"8bitpeoples"}],"artists":[{"id":103906,"name":"Bit Shifter","join":"","resource_url":"https://api.discogs.com/artists/103906","anv":"","tracks":"","role":""}]},"notes":[{"field_id":3,"value":"bleep bloop blorp."}]}]}