Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,12 @@ This release brings support for the `swarm/peers` command.
- Added the `IPFSClient::getPeers` method, which returns a list of all the node's connected peers.
- Added `Peer`, `PeerIdentity`, `PeerStream` models and corresponding transformers
- Added corresponding tests for the new transformers and methods.

## v1.3.0

This release brings support for the `resolve` command.

#### Additions

- Added the `IPFSClient::resolve` method, which returns the path to a given IPFS name.
- Added corresponding tests for the new method.
18 changes: 18 additions & 0 deletions src/Client/IPFSClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,22 @@ public function getPeers(bool $verbose = false): array
);
return $peerTransformer->transformList($parsedResponse['Peers'] ?? []);
}

public function resolve(string $name, bool $recursive = true): string
{
$response = $this->httpClient->request('POST', '/api/v0/resolve', [
'query' => [
'arg' => $name,
'recursive' => $recursive,
],
]);

$parsedResponse = json_decode($response, true);

if (isset($parsedResponse['Path']) === false) {
throw new \UnexpectedValueException('Unable to resolve path.');
}

return (string) $parsedResponse['Path'];
}
}
25 changes: 25 additions & 0 deletions tests/Client/IPFSClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,29 @@ private function assertPeerResponse(array $data, Peer $peer): void
$this->assertSame($data['Identify']['Addresses'], $identity->addresses);
$this->assertSame($data['Identify']['Protocols'], $identity->protocols);
}

/**
* @covers ::resolve
*/
public function testResolve(): void
{
$mockReturn = [
'Path' => '/ipfs/QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D',
];

$this->httpClient
->expects($this->once())
->method('request')
->with('POST', '/api/v0/resolve', [
'query' => [
'arg' => 'QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D',
'recursive' => true,
],
])
->willReturn(json_encode($mockReturn));

$result = $this->client->resolve('QmSnuWmxptJZdLJpKRarxBMS2Ju2oANVrgbr2xWbie9b2D');

$this->assertSame($mockReturn['Path'], $result);
}
}