poorcoder / php-sdk

API interface and SDK

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP SDK

The Moltin php-sdk is a simple to use interface for the API to help you get off the ground quickly and efficiently.

Installation

Download and install composer from http://www.getcomposer.org/download

Run the following command:

$ composer require moltin/php-sdk

Usage

Below is a basic usage guide for this package.

Instantiating the Package

Before you begin you will need to instantiate the package.

use Moltin\SDK\Request\CURL as Request;
use Moltin\SDK\Storage\Session as Storage;

$moltin = new \Moltin\SDK\SDK(new Storage(), new Request());

If you wish to use another storage or request method simply change the relevant use statement to reflect your preferences.

Authorisation

Before you can use the API you will need to authorise, there are a number of ways to this. The simplest of which is to use the "client credentials" method. You can do this as follows:

$result = \Moltin::Authenticate('ClientCredentials', [
        'client_id'     => '<YOUR CLIENT ID>',
        'client_secret' => '<YOUR CLIENT SECRET>',
]);

Once this is done your token will be stored in your selected storage method and passed automatically to all subsequent calls.

Making a Call

After authorising you can start to make calls to the API, there are four simple calls to use: GET, PUT, POST and DELETE.

Note: The following example shows the products API, for other end-points please check our Documentation

	// Create a product
	$result = \Product::Create($_POST);

	// Update a product
	$result = \Product::Update('<ID>', array('title' => 'Updated!'));

	// Get a product
	$result = Product::Get('<ID>');

	// Delete a product
	$result = Product::Delete('<ID>');

Building a Form

To help with the usual CRUD forms we've included an automated form builder to take care of the messy bits for you.

	// Get fields (create)
	fields = \Product::Fields();

	// Get fields (edit product 1)
	fields = \Product::Fields('<ID>');

	// Show form
	foreach ($fields as $field) {
		echo '<label for="'.$field['slug'].'">'.$field['name'].'</label>';
		echo $field['input'];
	}

Testing

$ phpunit

Contributing

Please see CONTRIBUTING for details.

Credits

License

Please see License File for more information.

About

API interface and SDK

License:MIT License


Languages

Language:PHP 99.4%Language:Batchfile 0.6%