ricbra / php-discogs-api

PHP 5.4 Implementation of the Discogs API
MIT License
152 stars 95 forks source link

result of artist/XX/releases #9

Closed bigbabou closed 10 years ago

bigbabou commented 10 years ago

Hi,

I use the API lib with your bundle wrapper in SF2.

When I try to get the releases http://api.discogs.com/artists/45/releases for example.

Before the transformation from standard class to model I have this :

object(stdClass)[207]
  public 'pagination' => 
    object(stdClass)[245]
      public 'per_page' => int 50
      public 'pages' => int 15
      public 'page' => int 1
      public 'urls' => 
        object(stdClass)[246]
          public 'last' => string 'http://api.discogs.com/artists/45/releases?per_page=50&page=15' (length=62)
          public 'next' => string 'http://api.discogs.com/artists/45/releases?per_page=50&page=2' (length=61)
      public 'items' => int 706
  public 'releases' => 
    array (size=50)
      0 => 
        object(stdClass)[247]
          public 'thumb' => string 'http://api.discogs.com/image/R-150-63114-1148806222.jpeg' (length=56)
          public 'title' => string 'Analog Bubblebath Vol 2' (length=23)
          public 'main_release' => int 63114
          public 'artist' => string 'Aphex Twin' (length=10)
          public 'role' => string 'Main' (length=4)
          public 'year' => int 1991
          public 'resource_url' => string 'http://api.discogs.com/masters/258478' (length=37)
          public 'type' => string 'master' (length=6)
          public 'id' => int 258478
      1 => 
.....

but as result I have only the pagination when I call like this in my controller :

$discogs = $this->container->get('discogs');
$release  = $discogs->getReleases(45);

I only get the pagination and not the releases.

object(Discogs\Model\Resultset)[299]
  protected 'pagination' => 
    object(Discogs\Model\Pagination)[303]
      protected 'perPage' => int 50
      protected 'items' => int 706
      protected 'page' => int 1
      protected 'urls' => 
        object(Discogs\Model\Urls)[310]
          protected 'last' => string 'http://api.discogs.com/artists/45/releases?per_page=50&page=15' (length=62)
          protected 'next' => string 'http://api.discogs.com/artists/45/releases?per_page=50&page=2' (length=61)
          protected 'previous' => null
          protected 'first' => null
      protected 'pages' => int 15
  protected 'results' => null

I think it's because of the ResultSet class which is used and doesn't have a setReleases method.

Hope this help.

ricbra commented 10 years ago

Hi @bigbabou

Thanks for reporting, I'll take a look this evening.

iamdey commented 10 years ago

ok I'm also stuck on this problem and there is others because of the model architecture and the discogs API :

The Release model has one to many Artist relationship. It is ok with /releases/{id} but it won't work with /artists/{id}/releases because the api gives a one-to-one relation between a release and artist

The solution I've found is to use another transformer, Hash or it would be great to have a simple NoopTransformer that gives \StdClass

ricbra commented 10 years ago

Hi @esion

I also discovered the problem you're describing. When I find the time I'm going to rewrite the client so it uses Guzzle (http://docs.guzzlephp.org/en/latest/) and stop using the models at all. The models are nice for type hinting but besides that a pain in the *\ ;). It's much more flexible to use arrays.

For now I suggest to use the Hash transformer. If you have the time I'm open for any PR to fix this problem.

ricbra commented 10 years ago

I'm closing this as the library is completely rewritten. If still actual could you test with 1.0.0 and open a new issue?

iamdey commented 10 years ago

Sounds good. And really good choice to use semver tags.