Skip to content

Commit

Permalink
add a method to set host
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsobries committed Jul 31, 2024
1 parent 9e8a09e commit a8237d6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/ArkClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,23 @@ public function __call($name, $args)
}
}

/**
* Set the host for the given type.
*
* @param string $host
* @param string $type
*
* @throws InvalidArgumentException if the type is not 'api', 'transactions', or 'evm'
*/
public function setHost(string $host, string $type): void
{
if (! in_array($type, ['api', 'transactions', 'evm'], true)) {
throw new \InvalidArgumentException('Invalid host type.');
}

$this->hosts[$type] = $host;
}

/**
* @return array{
* api: string,
Expand Down
21 changes: 21 additions & 0 deletions tests/ArkClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,27 @@ public function should_accept_custom_handler()
$this->assertSame($handler, $connection->getHttpClient()->getConfig('handler'));
}

/** @test */
public function should_set_host()
{
$client = $this->getClient();

$newHost = 'https://new-host.com/api';
$client->setHost($newHost, 'api');

$this->assertSame($newHost, $client->getHosts()['api']);
}

/** @test */
public function should_throw_exception_if_host_type_is_invalid()
{
$client = $this->getClient();

$this->expectException(\InvalidArgumentException::class);

$client->setHost('https://new-host.com/api', 'other');
}

/**
* Get a new client instance.
*
Expand Down

0 comments on commit a8237d6

Please sign in to comment.