Skip to content

Commit

Permalink
extract mex endpoints to reflect api structure
Browse files Browse the repository at this point in the history
  • Loading branch information
michavie committed Jul 28, 2022
1 parent cd1908d commit abd1a7c
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/Api/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Superciety\ElrondSdk\Api\Endpoints\AccountEndpoints;
use Superciety\ElrondSdk\Api\Endpoints\BlockEndpoints;
use Superciety\ElrondSdk\Api\Endpoints\CollectionEndpoints;
use Superciety\ElrondSdk\Api\Endpoints\MexEndpoints;
use Superciety\ElrondSdk\Api\Endpoints\NetworkEndpoints;
use Superciety\ElrondSdk\Api\Endpoints\NftEndpoints;
use Superciety\ElrondSdk\Api\Endpoints\TokenEndpoints;
Expand Down Expand Up @@ -43,6 +44,11 @@ public function collections(): CollectionEndpoints
return new CollectionEndpoints($this->cacheTtl);
}

public function mex(): MexEndpoints
{
return new MexEndpoints($this->cacheTtl);
}

public function nfts(): NftEndpoints
{
return new NftEndpoints($this->cacheTtl);
Expand Down
23 changes: 23 additions & 0 deletions src/Api/Endpoints/MexEndpoints.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Superciety\ElrondSdk\Api\Endpoints;

use Carbon\Carbon;
use Illuminate\Support\Collection;
use Superciety\ElrondSdk\Api\EndpointBase;
use Superciety\ElrondSdk\Api\Entities\MexPair;

class MexEndpoints extends EndpointBase
{
public function __construct(
protected ?Carbon $cacheTtl,
) {
}

public function getPairs(): Collection
{
return MexPair::fromApiResponseMany(
$this->request('GET', "{$this->getApiBaseUrl()}/mex/pairs")
);
}
}
9 changes: 0 additions & 9 deletions src/Api/Endpoints/NetworkEndpoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace Superciety\ElrondSdk\Api\Endpoints;

use Carbon\Carbon;
use Illuminate\Support\Collection;
use Superciety\ElrondSdk\Api\EndpointBase;
use Superciety\ElrondSdk\Api\Entities\MexPair;
use Superciety\ElrondSdk\Api\Entities\Economics;
use Superciety\ElrondSdk\Api\Entities\NetworkConstants;

Expand All @@ -29,11 +27,4 @@ public function getNetworkConstants(): NetworkConstants
$this->request('GET', "{$this->getApiBaseUrl()}/constants")
);
}

public function getMexPairs(): Collection
{
return MexPair::fromApiResponseMany(
$this->request('GET', "{$this->getApiBaseUrl()}/mex-pairs")
);
}
}
13 changes: 13 additions & 0 deletions tests/Api/MexTests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use Superciety\ElrondSdk\Elrond;

it('gets mex pairs', function () {
fakeApiRequestWithResponse('/mex/pairs', 'mex/pairs.json');

$actual = Elrond::api()
->mex()
->getPairs();

assertMatchesResponseSnapshot($actual);
});
10 changes: 0 additions & 10 deletions tests/Api/NetworkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,3 @@

assertMatchesResponseSnapshot($actual);
});

it('gets mex pairs', function () {
fakeApiRequestWithResponse('/mex-pairs', 'network/mex-pairs.json');

$actual = Elrond::api()
->network()
->getMexPairs();

assertMatchesResponseSnapshot($actual);
});
File renamed without changes.
Binary file not shown.

0 comments on commit abd1a7c

Please sign in to comment.