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
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Client {
*/
public function __construct( $token = '' ) {
$config = Configuration::getDefaultConfiguration()->setUsername( 'WordPress' )->setPassword(
$token ?: Helpers::get_settings()[ 'api_token' ]
$token
)->setHost( Helpers::get_hosted_domain_url() );
$this->api_instance = new DefaultApi( new GuzzleClient(), $config );
}
Expand Down
8 changes: 8 additions & 0 deletions src/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public function build() {
return false; // @codeCoverageIgnore
}

if ( ! $this->token ) {
$this->token = Helpers::get_settings()[ 'api_token' ];
}

if ( ! $this->token ) {
return false;
}

return new Client( $this->token );
}

Expand Down
5 changes: 5 additions & 0 deletions tests/unit/ClientFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public function testBuild() {
$clientFactory = new ClientFactory();
$client = $clientFactory->build();

$this->assertFalse( $client );

$clientFactory = new ClientFactory( 'test' );
$client = $clientFactory->build();

$this->assertInstanceOf( Client::class, $client );
}
}