Skip to content

Commit

Permalink
Merge pull request ricbra#47 from floydian77/pr-floydian77-user-colle…
Browse files Browse the repository at this point in the history
…ction-api

Added user collection api requests
  • Loading branch information
ricbra authored Mar 9, 2018
2 parents 15c64d1 + 0da1b36 commit 9e7d348
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,43 @@ foreach ($release['images'] as $image) {
```

### User Collection

Authorization is required when `folder_id` is not `0`.

#### Get collection folders

```php
<?php

$folders = $service->getCollectionFolders([
'username' => 'example'
]);
```

#### Get collection folder


```php
<?php

$folder = $service->getCollectionFolder([
'username' => 'example',
'folder_id' => 1
]);
```

#### Get collection items by folder

```php
<?php

$items = $service->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).

Expand Down
56 changes: 56 additions & 0 deletions resources/service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down
53 changes: 53 additions & 0 deletions tests/Discogs/Test/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/get_collection_folder
Original file line number Diff line number Diff line change
@@ -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"}
14 changes: 14 additions & 0 deletions tests/fixtures/get_collection_folders
Original file line number Diff line number Diff line change
@@ -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"}]}
14 changes: 14 additions & 0 deletions tests/fixtures/get_collection_items_by_folder
Original file line number Diff line number Diff line change
@@ -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."}]}]}

0 comments on commit 9e7d348

Please sign in to comment.