portatext / php-sdk
Official PHP Client for the PortaText API
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 30 877
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 5
Forks: 3
Open Issues: 1
Requires
- php: >= 5.3.0
- psr/log: >= 1.0.0
Requires (Dev)
- codeclimate/php-test-reporter: 0.3.0
- evert/phpdoc-md: ~0.1.1
- monolog/monolog: 1.*
- phing/phing: 2.*
- phpdocumentor/phpdocumentor: 2.*
- phpmd/phpmd: 2.*
- phpunit/phpunit: 4.*
- satooshi/php-coveralls: 1.0.1
- sebastian/phpcpd: *
- squizlabs/php_codesniffer: 2.5.1
- symfony/dependency-injection: @dev
- dev-master
- v1.6.1
- v1.6.0
- v1.5.22
- v1.5.21
- v1.5.20
- v1.5.19
- v1.5.18
- v1.5.17
- v1.5.16
- v1.5.15
- v1.5.14
- v1.5.13
- v1.5.12
- v1.5.11
- v1.5.10
- v1.5.9
- v1.5.8
- v1.5.7
- v1.5.6
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.12
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- 1.1.1
- 1.1.0
- v1.0.0
This package is not auto-updated.
Last update: 2023-01-04 15:17:52 UTC
README
php-sdk
Official PHP Client for the PortaText API.
Documentation
- Autogenerated documentation for this source can be found in the doc directory.
- The endpoint tests should also serve as good documentation on how to use the API.
- General PortaText documentation (including the REST API) can be found at the PortaText wiki.
Installing
Add this library to your Composer configuration. In composer.json:
"require": { "portatext/php-sdk": "1.*" }
Basic use
Getting a client instance
The first thing is to get a Client instance, for example the Curl implementation:
use PortaText\Client\Curl as Client; $portatext = new Client();
(Optional) Set your logger
You can optionally set a PSR-3 compatible logger:
$portatext->setLogger($logger);
By default, the client will use the NullLogger.
Authenticating
You can authenticate to the endpoints by using your API key or your username/password. This translates to either doing this:
$client->setApiKey($apiKey);
Or this:
$client->setCredentials($username, $password);
When you specify a username and password instead of an api key, the sdk will automatically login and get a session token when needed.
Using the endpoints
All the API commands can be found in the Command/Api directory. The client offers a way to instantiate them by just calling them by their name.
Quick example
As an example, to create a template, you would do:
$result = $client ->templates() // Get an instance of the Templates endpoint. ->text("The text of my template") ->description("My first template") ->name("template1") ->post(); // Call the Templates endpoint with a POST.
To get a template by id:
$result = $client->templates()->id(45)->get();
Or, to get all the templates:
$result = $client->templates()->get();
The result
After calling an endpoint, one of two things can happen:
- A PortaText Exception is thrown.
- A Result instance is returned.
Also, when possible, your PortaText exception will contain a Result
object that
can be retrieved by calling getResult()
on the exception. This is usually useful for the
ClientError exception, where
you will be able to see if a field was missing or different than what was expected.
Testing for success
if ($result->success) { ... }
Getting error strings back from the server
if (!is_null($result->errors)) { foreach ($result->errors as $error) { ... } }
Getting data back from the server
if ($result->success) { $data = $result->data; }
Developers
This project uses phing. Current tasks include:
- test: Runs PHPUnit.
- cs: Runs CodeSniffer.
- doc: Runs PhpDocumentor.
- md: runs PHPMD.
- build: This is the default task, and will run all the other tasks.
Running a phing task
To run a task, just do:
vendor/bin/phing build
Contributing
To contribute:
- Make sure you open a concise and short pull request.
- Throw in any needed unit tests to accomodate the new code or the changes involved.
- Run
phing
and make sure everything is ok before submitting the pull request (make phpmd and CodeSniffer happy, also make sure that phpDocumentor does not throw any warnings, since all our documentation is automatically generated). - Your code must comply with PSR-2, CodeSniffer should take care of that.
- If your code is accepted, it will belong to PortaText and will be published under the Apache2 License.
License
The source code is released under Apache 2 License.
Check LICENSE file for more information.