devkind / writesonic-php
Requires
- php: ^7.4|^8.0
- guzzlehttp/guzzle: ^7.2
- guzzlehttp/promises: ^1.3.1
- guzzlehttp/psr7: ^2.4.1
- nesbot/carbon: ^1.26.3 || ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.0
README
WritesonicPhp is a simple SDK implementation of Writesonic API. It helps accessing the API in an object oriented way.
Getting the API key
please register an account and request an api key at Writesonic.
Please check out the tutorials section for more information
Installation
You can install the package via composer:
composer require devkind/writesonic-php
Usage
Initialization:
use Devkind\WritesonicPhp; /** @var \Devkind\WritesonicPhp */ $writesonic = new WritesonicPhp(API_KEY);
alternatively we can initialize static
/** @var \Devkind\WritesonicPhp */ $writesonic = \Devkind\WritesonicPhp::make(API_KEY);
Endpoint:
Endpoints are basically the type of content that is supported by Writesonic.
Each endpoint requireds an $engine
and $language
parameter to query from writesonic.
/** @var string $language */
protected $language = 'en';
/** @var string $engine */
protected $engine = 'economy';
it supports following engines :
economy, business
and it supports following languages :
en, nl, fr, de, it, pl, es, pt-pt, pt-br, ru, ja, zh, bg, cs, da, el, hu, lt, lv, ro, sk, sl, sv, fi, et
in order to change the language or engine we can call the setter methods, which is available on all the endpoints.
to set the language
/** @var \Devkind\WritesonicPhp\Endpoints\GenerateImage */ $endpoint = $writesonic->GenerateImage->setLanguage('br');
to set the engine
/** @var \Devkind\WritesonicPhp\Endpoints\GenerateImage */ $endpoint = $writesonic->GenerateImage->setEngine('business');
alternatively:
/** @var \Devkind\WritesonicPhp\Endpoints\GenerateImage */ $endpoint = $writesonic->GenerateImage->setEngine('br')->setLanguage('br');
Supported Objects / Endpoints and Usage detail:
All the endpoints can be called into three different ways
as a payload
$object = new WritesonicPhp('test123'); /** @var \Devkind\WritesonicPhp\Endpoints\GoogleAds */ $endpoint = $object->GoogleAds; $array = $endpoint->setPayload([ "product_name" => 'test', "product_description" => 'test', "search_term" => 'test', ])->get();
through the setter methods
$object = new WritesonicPhp('test123'); /** @var \Devkind\WritesonicPhp\Endpoints\GoogleAds */ $endpoint = $object->GoogleAds; /** @var array */ $array = $endpoint->setProductName('test') ->setProductDescription('test') ->setSearchTerm('test') ->get();
through the generate
method
/** @var \Devkind\WritesonicPhp\Endpoints\GoogleAds */ $endpoint = $writesonic->GoogleAds; /** @var array */ $endpoint->generate( $product_name, $product_description, $search_term );
through the get
method
/** @var array */ $endpoint = $writesonic->GoogleAds->get([ "product_name" => 'test', "product_description" => 'test', "search_term" => 'test', ]);
Click here to view the entire documentation of supported endpoints
Testing
composer test
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email backend@devkind.com.au instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.