Skip to content

Commit

Permalink
Add RetrieveMintedNftRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
sprain committed Jan 20, 2022
1 parent 45110cd commit 4d41efb
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
19 changes: 19 additions & 0 deletions examples/Minting/3-retrieve-minted-nft.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

use Sprain\NftPort\Data\Blockchain;
use Sprain\NftPort\Request\Minting\RetrieveMintedNftRequest;

require_once __DIR__ . '/../../vendor/autoload.php';
require_once __DIR__ . '/../credentials.php';


// Retrieve a minted NFT
// https://docs.nftport.xyz/docs/nftport/b3A6MjE2NjM5MDU-retrieve-a-minted-nft

$response = (new RetrieveMintedNftRequest(
$apiKey,
'0x1a3dfdec04379f3aec147afcbc4548e91ce5e159f7d7aa5d22218097ecaff09c', // See examples/Contracts/2-customizable-mint.php
Blockchain::Polygon->name()
))->execute();

print_r($response);
2 changes: 1 addition & 1 deletion examples/Ownership/1-owned-by-account.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

$response = (new RetrieveOwnedByAccountRequest(
$apiKey,
$ethAddress,
'0x0841c4dcFe6C3D55F3f093cc19D3a2c5e42D2c1e',
Blockchain::Polygon->name(),
))->execute();

Expand Down
31 changes: 31 additions & 0 deletions lib/NftPort/Request/Minting/RetrieveMintedNftRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Sprain\NftPort\Request\Minting;

use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\SerializedName;
use Sprain\NftPort\Request\IdRequestInterface;
use Sprain\NftPort\Request\Request;
use Sprain\NftPort\Request\RequestCommonsTrait;
use Sprain\NftPort\Response\Minting\RetrieveMintedNftResponse;

class RetrieveMintedNftRequest extends Request implements IdRequestInterface
{
use RequestCommonsTrait;

public const API_PATH = '/mints/{id}';
public const RESPONSE_CLASS = RetrieveMintedNftResponse::class;
public const HTTP_METHOD = self::HTTP_METHOD_GET;

public function __construct(
#[Exclude]
protected string $apiKey,
private string $id,
#[SerializedName('chain')]
private string $chain,
) {
parent::__construct($apiKey);
}
}
27 changes: 27 additions & 0 deletions lib/NftPort/Response/Minting/RetrieveMintedNftResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Sprain\NftPort\Response\Minting;

use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\Type;
use Sprain\NftPort\Response\ResponseInterface;

class RetrieveMintedNftResponse implements ResponseInterface
{
#[SerializedName('response')]
public ?string $response = null;

#[SerializedName('chain')]
public ?string $chain = null;

#[SerializedName('contract_address')]
public ?int $contractAddress = null;

#[SerializedName('token_id')]
public ?string $tokenId = null;

#[SerializedName('error')]
public ?string $error = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php declare(strict_types=1);

namespace Sprain\NftPort\Tests\Request\Ownership;

use Sprain\NftPort\Request\Minting\RetrieveMintedNftRequest;
use Sprain\NftPort\Request\Request;
use Sprain\NftPort\Response\Minting\RetrieveMintedNftResponse;
use Sprain\NftPort\Tests\Request\CommonRequestTest;
use Sprain\NftPort\Data\Blockchain;

class RetrieveMintedNftRequestTest extends CommonRequestTest
{
public function testErrorResponse(): void
{
$this->doTestErrorResponse();
}

public function testSuccessfulResponse(): void
{
$this->doTestSuccessfulResponse(
RetrieveMintedNftResponse::class
);
}

protected function getRequest(): Request
{
return new RetrieveMintedNftRequest(
'apiKey',
'someTransactionHash',
Blockchain::Polygon->name()
);
}
}

0 comments on commit 4d41efb

Please sign in to comment.