2017 © Pedro Peláez
 

library exchangegroup-api

image

exchangegroup/exchangegroup-api

  • Tuesday, August 4, 2015
  • by exchangegroup
  • Repository
  • 19 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Exchange Group API V1 Client

PHP API client for http://www.bikeexchange.com.au/, http://www.tinitrader.com.au/, http://www.houseofhome.com.au/, http://www.bikeexchange.co.nz, http://www.bikeexchange.de and http://www.bikeexchange.com, (*1)

Requires https://getcomposer.org/, (*2)

All response data is provided as associative arrays for ease of handling, (*3)

<?php

require('vendor/autoload.php');

$client = new ExchangeGroup\Client('username', 'password');

// retrieving more information about one random advert from that list
$adverts = $client->getAdverts();

// updating the title and price of one random advert from that list
$randomAdvert = array_rand($adverts, 1);

$client->updateAdvert(
    $advertToUpdate['id'],
    array('title' => 'New Product Title', 'price' => '12.34')
);

// retrieving a list of variants from the server
$variants = $client->getVariants();

// retrieving more information about one variant advert from that list
$randomVariant =  array_rand($variants, 1);
$variantDetails = $client->getVariant($randomVariant['id']);

// and from the list attached to the advert
foreach($randomAdvert['variant_ids'] as $variantId) {
    var_dump($client->getVariant($variantId));
}

// OR
$advertVariants = array_map(
    function($id) use ($client) { return $client->getVariant($id); },
    $randomAdvert['variant_ids']
);

// updating the count_on_hand and sku of one of those variants
$client->updateVariant(
    $advertVariants[0]['id'],
    array('count_on_hand' => 1, 'sku' => 'A3334C')
);

Handling API Errors

If the API returns an errors object, the client will throw ExchangeGroup\ClientException. This exception has all request errors as a message, but also offers a public errors property for iterating over the errors., (*4)

try {
    $client->updateVariant(
        1234,
        array('count_on_hand' => -3, 'sku' => 'A3334C')
    );
} catch(ExchangeGroup\ClientException $e) {
    // "Errors in API request - count_on_hand: must be greater than zero"
    echo($e->getMessage());
}

The Versions

04/08 2015

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

04/02 2015

v1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires