Skip to content

Commit

Permalink
Update ThinkificService.php
Browse files Browse the repository at this point in the history
  • Loading branch information
MCKLtech committed Jan 24, 2024
1 parent 2220e2a commit ab6e73e
Showing 1 changed file with 52 additions and 8 deletions.
60 changes: 52 additions & 8 deletions src/Services/ThinkificService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace WooNinja\ThinkificSaloon\Services;

use Saloon\Contracts\Authenticator;
use WooNinja\ThinkificSaloon\Auth\ThinkificAuthenticator;
use WooNinja\ThinkificSaloon\Connectors\ThinkificConnector;
use WooNinja\ThinkificSaloon\Interfaces\Thinkific;
Expand All @@ -15,6 +16,7 @@ final class ThinkificService implements Thinkific
private string $api_key;
public string $subdomain;
public bool $is_oauth;

public BundleService $bundles;

//CategoriesService
Expand All @@ -35,7 +37,6 @@ final class ThinkificService implements Thinkific
public GroupService $groups;

public InstructorService $instructors;

public OrderService $orders;

//ProductPublishRequestService
Expand All @@ -46,9 +47,13 @@ final class ThinkificService implements Thinkific
public SiteScriptService $site_scripts;

public UserService $users;

public WebhookService $webhooks;
public OAuthService $oauth;

private ThinkificConnector|bool $connector = false;

private Authenticator|bool $authenticator = false;

public function __construct(string $api_key, string $subdomain, bool $is_oauth = false)
{
Expand Down Expand Up @@ -80,15 +85,54 @@ public function __construct(string $api_key, string $subdomain, bool $is_oauth =
*/
public function connector(): ThinkificConnector
{
if ($this->connector) {
return $this->connector;
}

/**
* Default Connector
*/
return (new ThinkificConnector($this->subdomain))
->authenticate(
new ThinkificAuthenticator(
$this->api_key,
$this->subdomain,
$this->is_oauth
)
);
->authenticate($this->authenticator());

}

/**
* @return Authenticator
*/
public function authenticator(): Authenticator
{
if ($this->authenticator) {
return $this->authenticator;
}

return new ThinkificAuthenticator(
$this->api_key,
$this->subdomain,
$this->is_oauth
);
}

/**
* Dynamically set the Connector
*
* @param ThinkificConnector $connector
* @return void
*/
public function setConnector(ThinkificConnector $connector): void
{
$this->connector = $connector;
}

/**
* Dynamically set the Authenticator
*
* @param Authenticator $authenticator
* @return void
*/
public function setAuthenticator(Authenticator $authenticator): void
{
$this->authenticator = $authenticator;
}

}

0 comments on commit ab6e73e

Please sign in to comment.