PHPackages                             optilarity/optilarity-sdk - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. optilarity/optilarity-sdk

ActiveLibrary[API Development](/categories/api)

optilarity/optilarity-sdk
=========================

Official PHP SDK for the Optilarity API (License, Membership, Templates)

0774↑611.7%PHP

Since Mar 24Pushed 3mo agoCompare

[ Source](https://github.com/optilarity/optilarity-sdk)[ Packagist](https://packagist.org/packages/optilarity/optilarity-sdk)[ RSS](/packages/optilarity-optilarity-sdk/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Optilarity PHP SDK
==================

[](#optilarity-php-sdk)

[![PHP Version](https://camo.githubusercontent.com/f32695bd6f65b12545162e869707d33dac6bcb5f6e5dc0d48b6d1f8162b6c247/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e302d626c75652e737667)](https://php.net)[![License](https://camo.githubusercontent.com/8bb50fd2278f18fc326bf71f6e88ca8f884f72f179d3e555e20ed30157190d0d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e2e737667)](LICENSE)

Official PHP SDK for integrating with the **Optilarity** ecosystem. This SDK provides a fluent, high-level interface for License Management, Membership (OAuth2), and Template Catalog services.

---

🚀 Installation
--------------

[](#-installation)

Add the SDK to your project via Composer:

```
composer require optilarity/optilarity-sdk
```

---

⚙️ Quick Start
--------------

[](#️-quick-start)

### 1. Initialization

[](#1-initialization)

The SDK uses a **Factory Pattern** for easy instantiation. In a WordPress environment, it automatically uses `wp_remote_request`. In others, it falls back to **cURL**.

```
use Optilarity\Sdk\OptilaritySdk;

$sdk = OptilaritySdk::make('https://api.optilarity.top');
```

---

🔑 License Service
-----------------

[](#-license-service)

Manage activation and status of product licenses.

### Activate a License

[](#activate-a-license)

```
try {
    $result = $sdk->license()->activate('XXXX-XXXX-XXXX', 'user@example.com');
    // $result contains ['success' => true, 'token' => '...', 'licensed_products' => [...]]
} catch (\Optilarity\Sdk\Exceptions\ApiException $e) {
    echo "Activation failed: " . $e->getMessage();
}
```

### Heartbeat (Ping)

[](#heartbeat-ping)

Verify if a previously activated license/token is still valid.

```
$status = $sdk->license()->ping('YOUR_STORED_TOKEN');
```

---

👤 Membership Service (OAuth2)
-----------------------------

[](#-membership-service-oauth2)

Handles the full OAuth2 flow to connect users to the Optilarity Cloud.

### Step 1: Redirect to Authorization

[](#step-1-redirect-to-authorization)

```
$authUrl = $sdk->membership()->authorizeUrl(
    'CLIENT_ID',
    'https://your-site.com/callback',
    ['membership:read'] // Scopes
);

header("Location: $authUrl");
exit;
```

### Step 2: Exchange Code for Token

[](#step-2-exchange-code-for-token)

```
$tokenData = $sdk->membership()->exchangeCode(
    'CLIENT_ID',
    'CLIENT_SECRET',
    $_GET['code'],
    'https://your-site.com/callback'
);
$accessToken = $tokenData['access_token'];
```

### Step 3: Fetch Plan Details

[](#step-3-fetch-plan-details)

```
$plan = $sdk->membership()->plan($accessToken);
echo "Current Plan: " . $plan['name'];
```

---

📦 Template Service
------------------

[](#-template-service)

Browse and download premium resources.

### List Templates

[](#list-templates)

```
$templates = $sdk->templates()->list('landing-page', 1, 20);
```

### Download Asset

[](#download-asset)

```
$asset = $sdk->templates()->download($accessToken, 'template-uuid');
// Returns signed download URL (e.g., from Backblaze B2)
```

---

⚠️ Error Handling
-----------------

[](#️-error-handling)

The SDK provides structured exceptions to catch specific failures:

- `AuthException`: Happens on 401/403 (Invalid token or expired credentials).
- `ApiException`: Generic API errors (400, 404, 500, etc.).

```
use Optilarity\Sdk\Exceptions\AuthException;
use Optilarity\Sdk\Exceptions\ApiException;

try {
    $sdk->license()->ping($token);
} catch (AuthException $e) {
    // Redirect user to login or clear token
} catch (ApiException $e) {
    // Log the error: $e->getStatusCode() and $e->getResponse()
}
```

---

🧪 Development &amp; Testing
---------------------------

[](#-development--testing)

If you are contributing to the SDK, run the unit test suite:

```
./vendor/bin/phpunit tests
```

---

🛠 Design Patterns Used
----------------------

[](#-design-patterns-used)

- **Factory/Singleton**: For flexible instantiation.
- **Fluent Interface**: For readable API service access.
- **Dependency Injection**: Services receive the HTTP client via constructor.
- **Adapter Pattern**: `HttpClient` adapts to WordPress or generic cURL environments.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance55

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/6a609a3b3a36dee9f36ef6f8d3b2b2dc91eebefc7644031e829e65bca4329799?d=identicon)[puleeno](/maintainers/puleeno)

---

Top Contributors

[![puleeno](https://avatars.githubusercontent.com/u/22538657?v=4)](https://github.com/puleeno "puleeno (6 commits)")

### Embed Badge

![Health badge](/badges/optilarity-optilarity-sdk/health.svg)

```
[![Health](https://phpackages.com/badges/optilarity-optilarity-sdk/health.svg)](https://phpackages.com/packages/optilarity-optilarity-sdk)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
