This repository was archived by the owner on Oct 25, 2023. It is now read-only.
File tree Expand file tree Collapse file tree
tests/Discogs/Test/Integration Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+ /*
3+ * This file is part of the DiscogsAPI PHP SDK.
4+ *
5+ * (c) Richard van den Brand <richard@vandenbrand.org>
6+ *
7+ * For the full copyright and license information, please view the LICENSE
8+ * file that was distributed with this source code.
9+ */
10+
11+ namespace Discogs \Model ;
12+
13+ class Inventory implements \Countable, \IteratorAggregate
14+ {
15+ protected $ pagination ;
16+ protected $ listings ;
17+
18+ public function setPagination ($ pagination )
19+ {
20+ $ this ->pagination = $ pagination ;
21+ }
22+
23+ public function getPagination ()
24+ {
25+ return $ this ->pagination ;
26+ }
27+
28+ public function setListings ($ listings )
29+ {
30+ $ this ->listings = $ listings ;
31+ }
32+
33+ public function getListings ()
34+ {
35+ return $ this ->listings ;
36+ }
37+
38+ public function count ()
39+ {
40+ return $ this ->getPagination ()->getItems ();
41+ }
42+
43+ public function getIterator ()
44+ {
45+ return new \ArrayIterator ($ this ->listings );
46+ }
47+ }
Original file line number Diff line number Diff line change @@ -140,6 +140,8 @@ protected function getClass($path)
140140 $ key = 'resultset ' ;
141141 } else if (preg_match ('#^/(artists|releases|masters|labels)/#i ' , $ path , $ matches )) {
142142 $ key = $ this ->getSingular ($ matches [1 ]);
143+ } else if (preg_match ('#^/users/[\d\w_-]+/inventory#i ' , $ path , $ matches )) {
144+ $ key = 'inventory ' ;
143145 } else {
144146 $ key = '' ;
145147 }
Original file line number Diff line number Diff line change @@ -169,6 +169,17 @@ public function getLabel($labelId)
169169 {
170170 return $ this ->call (sprintf ('/labels/%d ' , $ labelId ));
171171 }
172+ /**
173+ * Implements API users inventory method
174+ *
175+ * @param string $discogsUsername
176+ * @return mixed
177+ * @throws NoResultException
178+ */
179+ public function getInventory ($ discogsUsername )
180+ {
181+ return $ this ->call (sprintf ('/users/%s/inventory ' , $ discogsUsername ));
182+ }
172183
173184 /**
174185 * @param CacherInterface $cacher
Original file line number Diff line number Diff line change @@ -87,6 +87,14 @@ public function testLabel()
8787 $ this ->assertEquals ($ response ->getId (), 1 );
8888 }
8989
90+ public function testInventory (){
91+ $ response = $ this ->service ->getInventory ('buyreggae ' );
92+ $ this ->assertInstanceOf ('Discogs\Model\Pagination ' , $ response ->getPagination ());
93+ $ this ->assertTrue (is_array ($ response ->getListings ()));
94+ $ this ->assertGreaterThan (0 , $ response ->count ());
95+ $ this ->assertInstanceOf ('ArrayIterator ' , $ response ->getIterator ());
96+ }
97+
9098 public function testNext ()
9199 {
92100 $ response = $ this ->service ->search (array ('q ' => 'vibrasphere ' ));
You can’t perform that action at this time.
0 commit comments