Skip to content

Commit

Permalink
change lookupByFingerPrint args
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfeathers committed Jan 21, 2018
1 parent 4bcaf08 commit 2547dfc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ So, acoustid.org has some available actions, that are represented in the package
Meta::RECORDINGS,
Meta::RELEASES,
];

$fingerPrint = new FingerPrint($fingerPrintContent, $fingerPrintDuration);
$resultCollection = $acoustidClient->lookupByFingerPrint($fingerPrint, $meta);

$resultCollection = $acoustidClient->lookupByFingerPrint($fingerPrintContent, $fingerPrintDuration, $meta);
```
You will get an instance of class `ResultCollection`, contains several (or one) objects of `Result` class.
`ResultCollection` is iterable, so you can just use it as array:
Expand Down
11 changes: 6 additions & 5 deletions src/AcoustidClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use AcoustidApi\DataCompressor\DataCompressorInterface;
use AcoustidApi\Exception\{AcoustidApiException, AcoustidException};
use AcoustidApi\FingerPrint\{FingerPrint, FingerPrintCollection, FingerPrintCollectionNormalizer};
use AcoustidApi\FingerPrint\{FingerPrintCollection, FingerPrintCollectionNormalizer};
use AcoustidApi\Request\{Request, RequestFactory};
use AcoustidApi\ResponseModel\Collection\{CollectionModel, MBIdCollection, SubmissionCollection, TrackCollection};
use AcoustidApi\ResponseModel\Collection\ResultCollection;
Expand Down Expand Up @@ -82,20 +82,21 @@ private function checkApiKey(): void
}

/**
* @param FingerPrint $fingerPrint
* @param string $fingerprint
* @param int $duration
* @param array $meta - all meta values are available in AcoustidApi/Meta class
*
* @return ResultCollection
* @throws AcoustidException
*/
public function lookupByFingerPrint(FingerPrint $fingerPrint, array $meta = []): ResultCollection
public function lookupByFingerPrint(string $fingerprint, int $duration, array $meta = []): ResultCollection
{
$this->checkApiKey();

$request = $this->requestFactory->createCompressedPostRequest($this->compressor, Actions::LOOKUP, $this->apiKey)
->addParameters([
'fingerprint' => $fingerPrint->getFingerprint(),
'duration' => $fingerPrint->getDuration(),
'fingerprint' => $fingerprint,
'duration' => $duration,
'meta' => $meta,
'format' => self::FORMAT,
]
Expand Down
2 changes: 1 addition & 1 deletion tests/Client/AcoustidMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private function createHttpClient(): ClientInterface
public function methodsProvider()
{
return [
['lookupByFingerPrint', [new FingerPrint('', 0)]],
['lookupByFingerPrint', ['', 0]],
['lookupByTrackId', ['']],
['submit', [new FingerPrintCollection([]), '']],
['getSubmissionStatus', [0]],
Expand Down
12 changes: 2 additions & 10 deletions tests/Client/LookupByFingerprintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function getMockedResponses(): array

public function testLookUpByFingerPrint()
{
$result = $this->clientWithKey->lookupByFingerPrint($this->createFingerPrint());
$result = $this->clientWithKey->lookupByFingerPrint('fingerprint', 10);

$this->assertInstanceOf(self::EXPECTED_RETURN_TYPE, $result);
}
Expand All @@ -33,14 +33,6 @@ public function testLookUpByFingerPrint()
public function shouldThrowExceptionIfNoApiKey()
{
$this->expectException(AcoustidException::class);
$this->clientWithoutKey->lookupByFingerPrint($this->createFingerPrint());
}

/**
* @return FingerPrint
*/
private function createFingerPrint(): FingerPrint
{
return new FingerPrint('fingerprint', 10);
$this->clientWithoutKey->lookupByFingerPrint('fingerprint', 10);
}
}

0 comments on commit 2547dfc

Please sign in to comment.