Skip to content

Commit

Permalink
Rename BigCommerce to Bigcommerce
Browse files Browse the repository at this point in the history
All usages of the API namespace now have correct branding.

Supports autoloading via Composer with legacy 5.2 style namespaces.
  • Loading branch information
maetl committed Nov 15, 2012
1 parent d4f27e2 commit c9881ec
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 164 deletions.
61 changes: 33 additions & 28 deletions BigCommerce/Api.php → Bigcommerce/Api.php
@@ -1,12 +1,17 @@
<?php
require_once dirname(__FILE__).'/Api/Connection.php';
require_once dirname(__FILE__).'/Api/Resources.php';
require_once dirname(__FILE__).'/Api/Filter.php';

if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 3) {
// shim for legacy PEAR installer or manual linking
// (otherwise we assume Composer autoloader)
require_once dirname(__FILE__).'/Api/Connection.php';
require_once dirname(__FILE__).'/Api/Resources.php';
require_once dirname(__FILE__).'/Api/Filter.php';
}

/**
* BigCommerce API wrapper.
* Bigcommerce API wrapper.
*/
class BigCommerce_Api
class Bigcommerce_Api
{

static private $api_path = '/api/v2';
Expand Down Expand Up @@ -107,12 +112,12 @@ public static function getLastError()
* Get an instance of the HTTP connection object. Initializes
* the connection if it is not already active.
*
* @return BigCommerce_Api_Connection
* @return Bigcommerce_Api_Connection
*/
private static function connection()
{
if (!self::$connection) {
self::$connection = new BigCommerce_Api_Connection();
self::$connection = new Bigcommerce_Api_Connection();
self::$connection->authenticate(self::$username, self::$api_key);
}

Expand All @@ -139,7 +144,7 @@ public static function getCollection($path, $resource='Resource')
*
* @param string $path api endpoint
* @param string $resource resource class to map individual items
* @return mixed BigCommerce_ApiResource|string resource object or XML string if useXml is true
* @return mixed Bigcommerce_ApiResource|string resource object or XML string if useXml is true
*/
public static function getResource($path, $resource='Resource')
{
Expand Down Expand Up @@ -219,11 +224,11 @@ private static function mapCollection($resource, $object)
* Callback for mapping collection objects resource classes.
*
* @param stdClass $object
* @return BigCommerce_Api_Resource
* @return Bigcommerce_Api_Resource
*/
private static function mapCollectionObject($object)
{
$class = 'BigCommerce_Api_' . self::$resource;
$class = 'Bigcommerce_Api_' . self::$resource;

return new $class($object);
}
Expand All @@ -233,13 +238,13 @@ private static function mapCollectionObject($object)
*
* @param string $resource name of the resource class
* @param stdClass $object
* @return BigCommerce_Api_Resource
* @return Bigcommerce_Api_Resource
*/
private static function mapResource($resource, $object)
{
if ($object == false || is_string($object)) return $object;

$class = 'BigCommerce_Api_' . $resource;
$class = 'Bigcommerce_Api_' . $resource;

return new $class($object);
}
Expand Down Expand Up @@ -279,7 +284,7 @@ public static function getTime()
*/
public static function getProducts($filter=false)
{
$filter = BigCommerce_Api_Filter::create($filter);
$filter = Bigcommerce_Api_Filter::create($filter);
return self::getCollection('/products' . $filter->toQuery(), 'Product');
}

Expand All @@ -297,7 +302,7 @@ public static function getProductsCount()
* Returns a single product resource by the given id.
*
* @param int $id product id
* @return BigCommerce_Api_Product|string
* @return Bigcommerce_Api_Product|string
*/
public static function getProduct($id)
{
Expand Down Expand Up @@ -343,7 +348,7 @@ public static function deleteProduct($id)
*/
public static function getOptions($filter=false)
{
$filter = BigCommerce_Api_Filter::create($filter);
$filter = Bigcommerce_Api_Filter::create($filter);
return self::getCollection('/options' . $filter->toQuery(), 'Option');
}

Expand All @@ -361,7 +366,7 @@ public static function getOptionsCount()
* Return a single option by given id.
*
* @param int $id option id
* @return BigCommerce_Api_Option
* @return Bigcommerce_Api_Option
*/
public static function getOption($id)
{
Expand All @@ -383,7 +388,7 @@ public static function deleteOption($id)
*
* @param int $option_id option id
* @param int $id value id
* @return BigCommerce_Api_OptionValue
* @return Bigcommerce_Api_OptionValue
*/
public static function getOptionValue($option_id, $id)
{
Expand All @@ -398,7 +403,7 @@ public static function getOptionValue($option_id, $id)
*/
public static function getOptionValues($filter=false)
{
$filter = BigCommerce_Api_Filter::create($filter);
$filter = Bigcommerce_Api_Filter::create($filter);
return self::getCollection('/options/values' . $filter->toQuery(), 'OptionValue');
}

Expand All @@ -410,7 +415,7 @@ public static function getOptionValues($filter=false)
*/
public static function getCategories($filter=false)
{
$filter = BigCommerce_Api_Filter::create($filter);
$filter = Bigcommerce_Api_Filter::create($filter);
return self::getCollection('/categories' . $filter->toQuery(), 'Category');
}

Expand All @@ -428,7 +433,7 @@ public static function getCategoriesCount()
* A single category by given id.
*
* @param int $id category id
* @return BigCommerce_Api_Category
* @return Bigcommerce_Api_Category
*/
public static function getCategory($id)
{
Expand Down Expand Up @@ -474,7 +479,7 @@ public static function deleteCategory($id)
*/
public static function getBrands($filter=false)
{
$filter = BigCommerce_Api_Filter::create($filter);
$filter = Bigcommerce_Api_Filter::create($filter);
return self::getCollection('/brands' . $filter->toQuery(), 'Brand');
}

Expand All @@ -492,7 +497,7 @@ public static function getBrandsCount()
* A single brand by given id.
*
* @param int $id brand id
* @return BigCommerce_Api_Brand
* @return Bigcommerce_Api_Brand
*/
public static function getBrand($id)
{
Expand Down Expand Up @@ -538,7 +543,7 @@ public static function deleteBrand($id)
*/
public static function getOrders($filter=false)
{
$filter = BigCommerce_Api_Filter::create($filter);
$filter = Bigcommerce_Api_Filter::create($filter);
return self::getCollection('/orders' . $filter->toQuery(), 'Order');
}

Expand All @@ -556,7 +561,7 @@ public static function getOrdersCount()
* A single order.
*
* @param int $id order id
* @return BigCommerce_Api_Order
* @return Bigcommerce_Api_Order
*/
public static function getOrder($id)
{
Expand All @@ -583,7 +588,7 @@ public static function deleteOrder($id)
*/
public static function getCustomers($filter=false)
{
$filter = BigCommerce_Api_Filter::create($filter);
$filter = Bigcommerce_Api_Filter::create($filter);
return self::getCollection('/customers' . $filter->toQuery(), 'Customer');
}

Expand All @@ -601,7 +606,7 @@ public static function getCustomersCount()
* A single customer by given id.
*
* @param int $id customer id
* @return BigCommerce_Api_Customer
* @return Bigcommerce_Api_Customer
*/
public static function getCustomer($id)
{
Expand All @@ -627,7 +632,7 @@ public static function getAddresses($id)
*/
public static function getOptionSets($filter=false)
{
$filter = BigCommerce_Api_Filter::create($filter);
$filter = Bigcommerce_Api_Filter::create($filter);
return self::getCollection('/optionsets' . $filter->toQuery(), 'OptionSet');
}

Expand All @@ -645,7 +650,7 @@ public static function getOptionSetsCount()
* A single option set by given id.
*
* @param int $id option set id
* @return BigCommerce_Api_OptionSet
* @return Bigcommerce_Api_OptionSet
*/
public static function getOptionSet($id)
{
Expand Down
Expand Up @@ -3,7 +3,7 @@
/**
* HTTP connection.
*/
class BigCommerce_Api_Connection
class Bigcommerce_Api_Connection
{

/**
Expand Down Expand Up @@ -207,7 +207,7 @@ private function initializeRequest()
private function handleResponse()
{
if (curl_errno($this->curl)) {
throw new BigCommerce_Api_NetworkError(curl_error($this->curl), curl_errno($this->curl));
throw new Bigcommerce_Api_NetworkError(curl_error($this->curl), curl_errno($this->curl));
}

$body = ($this->useXml) ? $this->getBody() : json_decode($this->getBody());
Expand All @@ -216,14 +216,14 @@ private function handleResponse()

if ($status >= 400 && $status <= 499) {
if ($this->failOnError) {
throw new BigCommerce_Api_ClientError($body, $status);
throw new Bigcommerce_Api_ClientError($body, $status);
} else {
$this->lastError = $body;
return false;
}
} elseif ($status >= 500 && $status <= 599) {
if ($this->failOnError) {
throw new BigCommerce_Api_ServerError($body, $status);
throw new Bigcommerce_Api_ServerError($body, $status);
} else {
$this->lastError = $body;
return false;
Expand Down Expand Up @@ -275,7 +275,7 @@ private function followRedirectPath()

} else {
$errorString = "Too many redirects when trying to follow location.";
throw new BigCommerce_Api_NetworkError($errorString, CURLE_TOO_MANY_REDIRECTS);
throw new Bigcommerce_Api_NetworkError($errorString, CURLE_TOO_MANY_REDIRECTS);
}
} else {
$this->redirectsFollowed = 0;
Expand Down Expand Up @@ -458,7 +458,7 @@ public function __destruct()
/**
* Base class for API exceptions. Used if failOnError is true.
*/
class BigCommerce_Api_Error extends Exception
class Bigcommerce_Api_Error extends Exception
{

public function __construct($message, $code)
Expand All @@ -475,15 +475,15 @@ public function __construct($message, $code)
/**
* Raised if a network fault occurs.
*/
class BigCommerce_Api_NetworkError extends BigCommerce_Api_Error
class Bigcommerce_Api_NetworkError extends Bigcommerce_Api_Error
{

}

/**
* Raised when a client error (400+) is returned from the API.
*/
class BigCommerce_Api_ClientError extends BigCommerce_Api_Error
class Bigcommerce_Api_ClientError extends Bigcommerce_Api_Error
{

public function __toString()
Expand All @@ -496,7 +496,7 @@ public function __toString()
/**
* Raised when a server error (500+) is returned from the API.
*/
class BigCommerce_Api_ServerError extends BigCommerce_Api_Error
class Bigcommerce_Api_ServerError extends Bigcommerce_Api_Error
{

}
2 changes: 1 addition & 1 deletion BigCommerce/Api/Filter.php → Bigcommerce/Api/Filter.php
Expand Up @@ -3,7 +3,7 @@
/**
* Builds a query to filter the results of a collection request.
*/
class BigCommerce_Api_Filter
class Bigcommerce_Api_Filter
{
private $parameters;

Expand Down

0 comments on commit c9881ec

Please sign in to comment.