PHP SDK for Shoporama API only from Shoporama.
Before doing anything you should register yourself with Shoporama and get access credentials.
Simply add a dependency on lsolesen/shoporama-php-sdk to your project's composer.json
file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a dependency on Shoporama PHP SDK 0.1.*:
{
"require": {
"lsolesen/shoporama-php-sdk": "0.1.*"
}
}
After running composer install
, you can take advantage of Composer's autoloader in vendor/autoload.php
.
<?php
$request = new Request($api_key);
return new Client($request);
Now the client can be used to call the diffferent endpoint at Shoporama.
<?php
$client->get($ressource_url);
$client->post($ressource_url, $data);
$client->put($ressource_url, $data);
$client->patch($ressource_url, $data);
$client->delete($ressource_url);
<?php
// POST for creating a product
$data = array('name' => 'My Shoporama Product');
$response = $client->post('/product', $data);
$array = json_decode($response->getBody(), true);
$product_id = $array['product_id'];
<?php
// PUT for updating a Product
$data['name'] = 'PUT Testproduct';
$response = $client->put('/product/' . $product_id, $data);
$array = json_decode($response->getBody(), true);
<?php
// Test PATCH for updating af product.
$patch_data = array('name' => 'PATCH Testproduct');
$response = $client->put('/product/' . $product_id, $patch_data);
$array = json_decode($response->getBody(), true);
<?php
// Testing DELETE - should remove the product
$response = $client->delete('/product/' . $product_id);
$this->assertInstanceOf('Shoporama\Response', $response);
<?php
// Testing GET - product should not exist anymore
$response = $client->get('/product/' . $product_id);
You are more than welcome to contribute using pull requests.