rachidlaasri / ycode-php-sdk
PHP and Laravel SDK for working with ycode.
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/rachidlaasri/ycode-php-sdk
Requires
- php: ^8.3.0
- nesbot/carbon: ^3.10
- saloonphp/pagination-plugin: ^2.0
- saloonphp/saloon: ^3.0
Requires (Dev)
- jonpurvis/lawman: ^4.1
- laravel/pint: ^1.24.0
- mockery/mockery: ^1.6
- orchestra/testbench: ^10.8
- peckphp/peck: ^0.1.3
- pestphp/pest: ^4.1.0
- pestphp/pest-plugin-type-coverage: ^4.0.2
- phpstan/phpstan: ^2.1.26
- rector/rector: ^2.1.7
- symfony/var-dumper: ^7.3.3
README
YCODE PHP SDK
This package provides better API for working with YCODE API.
Requires PHP 8.3+
Note: Please refer to the official documentation for more details.
Installation
โก๏ธ Get started by requiring the package using Composer:
composer require rachidlaasri/ycode-php-sdk
Usage
This SDK is framework agnostic, meaning it can be used with any PHP project. But it also provides a fluent API for Laravel integration.
Vanilla PHP
use RashidLaasri\YCODE\Config; use RashidLaasri\YCODE\YCode; $configs = new Config( baseUrl: 'https://app.ycode.com/api/v1', token: '<AUTH-TOKEN>', ); $project = new YCode($configs);
Laravel
If you are using Laravel, you may publish the configuration file with:
php artisan vendor:publish --tag=ycode-config
Then add these two keys to your .env file:
YCODE_BASE_URL=https://app.ycode.com/api/v1 YCODE_TOKEN=<AUTH-TOKEN>
and then you can resolve it from the IoC.
$project = app(Ycode::class);
Table of Contents
Collections
List all collections
$collections = $project->collections()->list();
Returns an array of RashidLaasri\YCODE\DataObjects\Collection
array:1 [
0 => RashidLaasri\YCODE\DataObjects\Collection {
+_ycode_id: "637781341a6f7"
+name: "Blogposts"
+singular_name: "Blogpost"
+created_at: Carbon\Carbon @1668776244
+fields: []
}
]
For more details, please check the official documentation.
Get single collection
$collection = $project->collections()->get('637781341a6f7');
Returns an instance of RashidLaasri\YCODE\DataObjects\Collection with fields array
RashidLaasri\YCODE\DataObjects\Collection { +_ycode_id: "637781341a6f7" +name: "Blogposts" +singular_name: "Blogpost" +created_at: Carbon\Carbon @1668776244 +fields: array:1 [ 0 => RashidLaasri\YCODE\DataObjects\Field{ +id: 1 +name: "ID" +type: "number" +default_value: null } ] }
For more details, please check the official documentation.
Sites
Publishes site
$sites = $project->sites()->publish();
Returns an array of RashidLaasri\YCODE\DataObjects\Doamin
array:1 [ 0 => RashidLaasri\YCODE\DataObjects\Doamin { +name: "example.ycode.site" } ]
For more details, please check the official documentation.
Items
List all items
$list = $project->items()->list('16687860798456377a79fce481', [ 'filters' => [ 'Name' => 'Blog', ], ]);
Returns a pagination instance
foreach($list->items() as $item) { // $item is an instance of RashidLaasri\YCODE\DataObjects\Item }
For more details, please check the official documentation.
Get a single item
$item = $project->items()->get('16687860798456377a79fce481', 'abc123');
Returns an instance of RashidLaasri\YCODE\DataObjects\Item
RashidLaasri\YCODE\DataObjects\Item { +_ycode_id: "16687860798456377a79fce481" +id: 1 +name: "Blogpost title" +slug: "blogpost-slug" +created_at: Carbon\Carbon @1668786123 +updated_at: Carbon\Carbon @1668786123 +created_by: "1669309481596637fa4299184e" +updated_by: "1669309527456637fa4576f6dc" +summary: "Lorem ipsum dolor sit amet, consectetur adipiscing elit..." +main_image: "https://storage.googleapis.com/D46OSM.jpg" +thumbnail: "https://storage.googleapis.com/ifJO0DZv.jpg" +featured: true +author: "16687859744696377a736727d8" +categories: array:2 [ 0 => RashidLaasri\YCODE\DataObjects\Category +name: "1669309639520637fa4c77eea7" } 1 => RashidLaasri\YCODE\DataObjects\Category +name: "1669309662211637fa4de338d6" } ] +body: "<p>Lorem ipsum dolor sit ams purus, semper nec tempor et, tincidunt sed justo....</p>" }
For more details, please check the official documentation.
Create an item
$item = $project->items()->create('16687860798456377a79fce481', [ // payload ]);
Returns an instance of RashidLaasri\YCODE\DataObjects\Item
RashidLaasri\YCODE\DataObjects\Item { +_ycode_id: "16687860798456377a79fce481" +id: 1 +name: "Blogpost title" ... }
For more details, please check the official documentation.
Update an item
$item = $project->items()->update('16687868024636377aa7270ea9', 'abc123', [ // payload ]);
Returns an instance of RashidLaasri\YCODE\DataObjects\Item
RashidLaasri\YCODE\DataObjects\Item { +_ycode_id: "16687860798456377a79fce481" +id: 1 +name: "Blogpost title" ... }
For more details, please check the official documentation.
Patch an
$item = $project->items()->patch('16687868024636377aa7270ea9', 'abc123', [ // payload ]);
Returns an instance of RashidLaasri\YCODE\DataObjects\Item
RashidLaasri\YCODE\DataObjects\Item { +_ycode_id: "16687860798456377a79fce481" +id: 1 +name: "Blogpost title" ... }
For more details, please check the official documentation.
Delete an item
$item = $project->items()->delete('16687868024636377aa7270ea9', 'abc123', [ // payload '_draft' => true, ]);
Returns JSON response
{
"deleted": 1
}
For more details, please check the official documentation.
Development
๐งน Keep a modern codebase with Pint:
composer lint
โ Run refactors using Rector
composer refactor
โ๏ธ Run static analysis using PHPStan:
composer test:types
โ Run unit tests using PEST
composer test:unit
๐ Run the entire test suite:
composer test
License
YCODE PHP SDK was created by Rachid Laasri under the MIT license.