Giter Club home page Giter Club logo

php-sdk's Introduction

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.

php-sdk's People

Contributors

anthonysterling avatar axhini avatar chrisnharvey avatar outrunthewolf avatar philipbrown avatar zot24 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.