Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit d8f45f2

Browse files
committed
Merge pull request #15 from ricbra/guzzle
Guzzle 4 rewrite
2 parents 98bca84 + cbae589 commit d8f45f2

70 files changed

Lines changed: 772 additions & 6656 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
language: php
22

33
php:
4-
- 5.3
54
- 5.4
5+
- 5.5
66

77
notifications:
88
email:
99
- richard@vandenbrand.org
1010

1111
before_script:
1212
- wget http://getcomposer.org/composer.phar
13-
- php composer.phar install
13+
- php composer.phar install

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2010-2011 Richard van den Brand
1+
Copyright (c) 2010-2014 Richard van den Brand
22

33
Permission is hereby granted, free of charge, to any person obtaining a copy
44
of this software and associated documentation files (the "Software"), to deal
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1616
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1717
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1818
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
THE SOFTWARE.
19+
THE SOFTWARE.

README.md

Lines changed: 88 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,154 @@
11
## Discogs Api
22

33
[![Build Status](https://secure.travis-ci.org/ricbra/php-discogs-api.png)](http://travis-ci.org/ricbra/php-discogs-api)
4+
[![Latest Stable Version](https://poser.pugx.org/ricbra/php-discogs-api/v/stable.svg)](https://packagist.org/packages/ricbra/php-discogs-api)
5+
[![Total Downloads](https://poser.pugx.org/ricbra/php-discogs-api/downloads.png)](https://packagist.org/packages/ricbra/php-discogs-api)
6+
[![License](https://poser.pugx.org/ricbra/php-discogs-api/license.png)](https://packagist.org/packages/ricbra/php-discogs-api)
7+
[![Quality](https://scrutinizer-ci.com/g/ricbra/php-discogs-api/badges/quality-score.png)](https://scrutinizer-ci.com/g/ricbra/php-discogs-api/)
48

5-
This library is an PHP 5.3 implementation of the [Discogs API v2.0.](http://www.discogs.com/developers/index.html)
9+
This library is a PHP 5.4 implementation of the [Discogs API v2.0.](http://www.discogs.com/developers/index.html)
610
The Discogs API is a REST-based interface. By using this library you don't have to worry about communicating with the
711
API: all the hard work has already be done.
812

13+
This API is build upon the shoulders of a giant: [Guzzle 4.0](http://guzzle.readthedocs.org/en/latest/). This is an absolutely awesome library.
14+
915
## License
1016
This library is released under the MIT license. See the complete license in the LICENSE file.
1117

1218
## Installation
13-
Start by [installing composer](http://getcomposer.org/doc/01-basic-usage.md#installation) and finally
14-
[install the dependencies](http://getcomposer.org/doc/01-basic-usage.md#installing-dependencies).
19+
Start by [installing composer](http://getcomposer.org/doc/01-basic-usage.md#installation).
20+
Next do:
21+
22+
$ composer require ricbra/php-discogs-api ~1.0.0
1523

1624
## Requirements
17-
PHP >=5.3.0
25+
PHP >=5.4.0
1826

1927
## Usage
2028
Creating a new instance is as simple as:
2129

2230
```php
2331
<?php
24-
$service = new \Discogs\Service();
32+
$client = Discogs\ClientFactory::factory([]);
2533
```
2634

27-
### Perform a search:
35+
### OAuth
36+
There a lot of endpoints which require OAuth. Lucky for you using Guzzle this is peanuts.
2837

2938
```php
3039
<?php
3140

32-
$resultset = $service->search(array(
33-
'q' => 'Meagashira',
34-
'label' => 'Enzyme'
35-
));
36-
37-
// Total results
38-
echo count($resultset)."\n";
39-
// Total pages
40-
$pagination = $resultset->getPagination();
41-
echo count($pagination)."\n";
42-
43-
// Fetch all results (use on your own risk, only one request per second allowed)
44-
do {
45-
$pagination = $resultset->getPagination();
46-
echo $pagination->getPage().'<br />';
47-
foreach ($resultset as $result) {
48-
echo get_class($result).'<br />';
49-
}
50-
} while($resultset = $service->next($resultset));
41+
$client = Discogs\ClientFactory::factory([]);
42+
$oauth = new GuzzleHttp\Subscriber\Oauth\Oauth1([
43+
'consumer_key' => $consumerKey, // from Discogs developer page
44+
'consumer_secret' => $consumerSecret, // from Discogs developer page
45+
'token' => $token['oauth_token'], // get this using a OAuth library
46+
'token_secret' => $token['oauth_token_secret'] // get this using a OAuth library
47+
]);
48+
$client->getHttpClient()->getEmitter()->attach($oauth);
49+
50+
$response = $client->search([
51+
'q' => 'searchstring'
52+
]);
5153
```
5254

53-
### Get information about a label:
55+
### History
56+
Another cool plugin is the History plugin:
5457

5558
```php
5659
<?php
5760

58-
$label = $service->getLabel(1);
61+
$client = Discogs\ClientFactory::factory([]);
62+
$history = new GuzzleHttp\Subscriber\History();
63+
$client->getHttpClient()->getEmitter()->attach($history);
64+
65+
$response = $client->search([
66+
'q' => 'searchstring'
67+
]);
68+
69+
foreach ($history as $row) {
70+
print (string) $row['request'];
71+
print (string) $row['response'];
72+
}
5973

60-
echo $label->getName()."\n";
6174
```
6275

63-
### Get information about an artist:
76+
### More info and plugins
77+
For more information about Guzzle and its plugins checkout [the docs.](http://guzzle.readthedocs.org/en/latest/)
78+
79+
### Perform a search:
80+
Per august 2014 an signed OAuth request is required for this endpoint.
6481

6582
```php
6683
<?php
6784

68-
$artist = $service->getArtist(1);
85+
$response = $client->search([
86+
'q' => 'Meagashira'
87+
]);
88+
// Loop through results
89+
foreach ($response['results'] as $result) {
90+
var_dump($result['title']);
91+
}
92+
// Pagination data
93+
var_dump($response['pagination']);
94+
95+
// Dump all data
96+
var_dump($response->toArray());
6997

70-
echo $artist->getName()."\n";
7198
```
7299

73-
### Get information about a release:
100+
### Get information about a label:
74101

75102
```php
76103
<?php
77104

78-
$release = $service->getRelease(1);
105+
$label = $service->getLabel([
106+
'id' => 1
107+
]);
79108

80-
echo $release->getTitle()."\n";
81109
```
82110

83-
### Get information about a master release:
111+
### Get information about an artist:
84112

85113
```php
86114
<?php
87115

88-
$master = $service->getMaster(1);
116+
$artist = $service->getArtist([
117+
'id' => 1
118+
]);
89119

90-
echo $master->getTitle()."\n";
91120
```
92121

93-
### Response transformation
122+
### Get information about a release:
94123

95-
You have two options in which form to receive formatted response: as object using supplied models, or as plain array.
96-
By default (if nothing has been set via setter) Model response transformer is chosen. You can manipulate it via
97-
the `setResponseTransfomer` setter:
124+
```php
125+
<?php
98126

99-
``` php
100-
$discogs->setResponseTransformer(new \Discogs\ResponseTransformer\Model());
101-
// or
102-
$discogs->setResponseTransformer(new \Discogs\ResponseTransformer\Hash());
127+
$release = $service->getRelease([
128+
'id' => 1
129+
]);
130+
131+
echo $release['title']."\n";
103132
```
104133

105-
You can also set your own response transformer which need to implement the `ResponseTransformerInterface`
134+
### Get information about a master release:
106135

107-
**NOTE** At this moment only the "Database" resource has been implemented. The "Marketplace" and "User" are missing.
136+
```php
137+
<?php
138+
139+
$master = $service->getMaster([
140+
'id' => 1
141+
]);
142+
143+
echo $master['title']."\n";
144+
```
108145

109146
## Documentation
110147
Further documentation can be found at the [Discogs API v2.0 Documentation](http://www.discogs.com/developers/index.html).
111148

149+
## Contributing
150+
Implemented a missing call? PR's are welcome!
151+
152+
112153
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/ricbra/php-discogs-api/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
113154

UPGRADE.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Upgrade from 0.x.x to 1.0.0
2+
===========================
3+
4+
API calls
5+
---------
6+
7+
All API calls signatures have changed. Old situation:
8+
9+
<?php
10+
11+
$service->getArtist(1);
12+
13+
New situation is always using arrays:
14+
15+
<?php
16+
17+
$service->getArtist([
18+
'id' => 1
19+
]);
20+
21+
In the <code>resources/service.php</code> file you can find all the implemented calls and their signatures and responses.
22+
23+
Iterator removed
24+
----------------
25+
26+
It's not yet possible to iterate over the responses. Perhaps this will be added in the near future. It should be
27+
easy to implement an <code>Iterator</code> yourself. PR's are welcome :).
28+
29+
Caching removed
30+
---------------
31+
32+
Caching in the library itself is removed. This can be achieved by creating or using a cache plugin. At the moment of
33+
writing the plugin for Guzzle isn't refactored yet for version 4.0.
34+
35+
No more models
36+
--------------
37+
38+
Models have been replaced with plain old arrays. Models were nice for typing but a hell to manage. All responses will
39+
return an array. When you want to debug the output use <code>$response->toArray()</code>.
40+

composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
"keywords": ["discogs", "api"],
66
"license": "MIT",
77
"require": {
8-
"kriswallsmith/buzz": ">=0.5",
9-
"php": ">=5.3.0"
8+
"php": ">=5.4.0",
9+
"guzzlehttp/guzzle": "~4.0",
10+
"guzzlehttp/guzzle-services": "~0.3.0",
11+
"guzzlehttp/oauth-subscriber": "~0.1.2"
1012
},
1113
"require-dev": {
1214
"phpunit/phpunit": "~4"
@@ -19,5 +21,7 @@
1921
],
2022
"autoload": {
2123
"psr-0": { "Discogs": "lib/" }
22-
}
23-
}
24+
},
25+
"minimum-stability": "dev",
26+
"prefer-stable": true
27+
}

lib/Discogs/CacherInterface.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)