diff --git a/BigCommerce/Api.php b/Bigcommerce/Api.php similarity index 90% rename from BigCommerce/Api.php rename to Bigcommerce/Api.php index bb92a145..e6807050 100644 --- a/BigCommerce/Api.php +++ b/Bigcommerce/Api.php @@ -1,12 +1,17 @@ authenticate(self::$username, self::$api_key); } @@ -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') { @@ -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); } @@ -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); } @@ -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'); } @@ -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) { @@ -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'); } @@ -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) { @@ -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) { @@ -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'); } @@ -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'); } @@ -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) { @@ -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'); } @@ -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) { @@ -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'); } @@ -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) { @@ -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'); } @@ -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) { @@ -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'); } @@ -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) { diff --git a/BigCommerce/Api/Connection.php b/Bigcommerce/Api/Connection.php similarity index 95% rename from BigCommerce/Api/Connection.php rename to Bigcommerce/Api/Connection.php index 8302aaf8..315f83e2 100644 --- a/BigCommerce/Api/Connection.php +++ b/Bigcommerce/Api/Connection.php @@ -3,7 +3,7 @@ /** * HTTP connection. */ -class BigCommerce_Api_Connection +class Bigcommerce_Api_Connection { /** @@ -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()); @@ -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; @@ -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; @@ -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) @@ -475,7 +475,7 @@ 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 { } @@ -483,7 +483,7 @@ 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() @@ -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 { } diff --git a/BigCommerce/Api/Filter.php b/Bigcommerce/Api/Filter.php similarity index 96% rename from BigCommerce/Api/Filter.php rename to Bigcommerce/Api/Filter.php index fc61d50f..4535ff78 100644 --- a/BigCommerce/Api/Filter.php +++ b/Bigcommerce/Api/Filter.php @@ -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; diff --git a/BigCommerce/Api/Resources.php b/Bigcommerce/Api/Resources.php similarity index 64% rename from BigCommerce/Api/Resources.php rename to Bigcommerce/Api/Resources.php index 52023309..7a15b7de 100644 --- a/BigCommerce/Api/Resources.php +++ b/Bigcommerce/Api/Resources.php @@ -1,6 +1,6 @@ fields->brand->resource, 'Brand'); + return Bigcommerce_Api::getResource($this->fields->brand->resource, 'Brand'); } public function images() { - return BigCommerce_Api::getCollection($this->fields->images->resource, 'ProductImage'); + return Bigcommerce_Api::getCollection($this->fields->images->resource, 'ProductImage'); } public function skus() { - return BigCommerce_Api::getCollection($this->fields->skus->resource, 'Sku'); + return Bigcommerce_Api::getCollection($this->fields->skus->resource, 'Sku'); } public function rules() { - return BigCommerce_Api::getCollection($this->fields->rules->resource, 'Rule'); + return Bigcommerce_Api::getCollection($this->fields->rules->resource, 'Rule'); } public function videos() { - return BigCommerce_Api::getCollection($this->fields->videos->resource, 'Video'); + return Bigcommerce_Api::getCollection($this->fields->videos->resource, 'Video'); } public function custom_fields() { - return BigCommerce_Api::getCollection($this->fields->custom_fields->resource, 'CustomField'); + return Bigcommerce_Api::getCollection($this->fields->custom_fields->resource, 'CustomField'); } public function configurable_fields() { - return BigCommerce_Api::getCollection($this->fields->configurable_fields->resource, 'ConfigurableField'); + return Bigcommerce_Api::getCollection($this->fields->configurable_fields->resource, 'ConfigurableField'); } public function discount_rules() { - return BigCommerce_Api::getCollection($this->fields->discount_rules->resource, 'DiscountRule'); + return Bigcommerce_Api::getCollection($this->fields->discount_rules->resource, 'DiscountRule'); } public function option_set() { - return BigCommerce_Api::getResource($this->fields->option_set->resource, 'OptionSet'); + return Bigcommerce_Api::getResource($this->fields->option_set->resource, 'OptionSet'); } public function options() { - return BigCommerce_Api::getCollection('/products/' . $this->id . '/options', 'ProductOption'); + return Bigcommerce_Api::getCollection('/products/' . $this->id . '/options', 'ProductOption'); } public function create() { - return BigCommerce_Api::createProduct($this->getCreateFields()); + return Bigcommerce_Api::createProduct($this->getCreateFields()); } public function update() { - return BigCommerce_Api::updateProduct($this->id, $this->getUpdateFields()); + return Bigcommerce_Api::updateProduct($this->id, $this->getUpdateFields()); } public function delete() { - return BigCommerce_Api::deleteProduct($this->id); + return Bigcommerce_Api::deleteProduct($this->id); } } @@ -199,7 +199,7 @@ public function delete() /** * An image which is displayed on the storefront for a product. */ -class BigCommerce_Api_ProductImage extends BigCommerce_Api_Resource +class Bigcommerce_Api_ProductImage extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -216,12 +216,12 @@ class BigCommerce_Api_ProductImage extends BigCommerce_Api_Resource public function create() { - return BigCommerce_Api::createResource('/products/' . $this->product_id . '/images' , $this->getCreateFields()); + return Bigcommerce_Api::createResource('/products/' . $this->product_id . '/images' , $this->getCreateFields()); } public function update() { - BigCommerce_Api::updateResource('/products/' . $this->product_id . '/images/' . $this->id , $this->getUpdateFields()); + Bigcommerce_Api::updateResource('/products/' . $this->product_id . '/images/' . $this->id , $this->getUpdateFields()); } } @@ -229,7 +229,7 @@ public function update() /** * A stock keeping unit for a product. */ -class BigCommerce_Api_Sku extends BigCommerce_Api_Resource +class Bigcommerce_Api_Sku extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -243,7 +243,7 @@ class BigCommerce_Api_Sku extends BigCommerce_Api_Resource public function options() { - $options = BigCommerce_Api::getCollection($this->fields->options->resource, 'SkuOption'); + $options = Bigcommerce_Api::getCollection($this->fields->options->resource, 'SkuOption'); foreach($options as $option) { $option->product_id = $this->product_id; @@ -254,12 +254,12 @@ public function options() public function create() { - return BigCommerce_Api::createResource('/products/' . $this->product_id . '/skus' , $this->getCreateFields()); + return Bigcommerce_Api::createResource('/products/' . $this->product_id . '/skus' , $this->getCreateFields()); } public function update() { - BigCommerce_Api::updateResource('/products/' . $this->product_id . '/skus/' . $this->id , $this->getUpdateFields()); + Bigcommerce_Api::updateResource('/products/' . $this->product_id . '/skus/' . $this->id , $this->getUpdateFields()); } } @@ -267,7 +267,7 @@ public function update() /** * A relationship between a product SKU and an option. */ -class BigCommerce_Api_SkuOption extends BigCommerce_Api_Resource +class Bigcommerce_Api_SkuOption extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -283,12 +283,12 @@ class BigCommerce_Api_SkuOption extends BigCommerce_Api_Resource public function create() { - return BigCommerce_Api::createResource('/products/' . $this->product_id . '/skus/' . $this->sku_id . '/options' , $this->getCreateFields()); + return Bigcommerce_Api::createResource('/products/' . $this->product_id . '/skus/' . $this->sku_id . '/options' , $this->getCreateFields()); } public function update() { - BigCommerce_Api::updateResource('/products/' . $this->product_id . '/skus/' . $this->sku_id . '/options/' .$this->id , $this->getUpdateFields()); + Bigcommerce_Api::updateResource('/products/' . $this->product_id . '/skus/' . $this->sku_id . '/options/' .$this->id , $this->getUpdateFields()); } } @@ -296,7 +296,7 @@ public function update() /** * Relationship between a product and an option applied from an option set. */ -class BigCommerce_Api_ProductOption extends BigCommerce_Api_Resource +class Bigcommerce_Api_ProductOption extends Bigcommerce_Api_Resource { public function option() @@ -309,12 +309,12 @@ public function option() /** * An option. */ -class BigCommerce_Api_Option extends BigCommerce_Api_Resource +class Bigcommerce_Api_Option extends Bigcommerce_Api_Resource { public function values() { - return BigCommerce_Api::getCollection($this->fields->values->resource, 'OptionValue'); + return Bigcommerce_Api::getCollection($this->fields->values->resource, 'OptionValue'); } } @@ -322,7 +322,7 @@ public function values() /** * Selectable value of an option. */ -class BigCommerce_Api_OptionValue extends BigCommerce_Api_Resource +class Bigcommerce_Api_OptionValue extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -342,12 +342,12 @@ public function option() public function create() { - return BigCommerce_Api::createResource('/options/' . $this->option_id . '/values', $this->getCreateFields()); + return Bigcommerce_Api::createResource('/options/' . $this->option_id . '/values', $this->getCreateFields()); } public function update() { - BigCommerce_Api::updateResource('/options/' . $this->option_id . '/values/' . $this->id, $this->getUpdateFields()); + Bigcommerce_Api::updateResource('/options/' . $this->option_id . '/values/' . $this->id, $this->getUpdateFields()); } } @@ -355,7 +355,7 @@ public function update() /** * A custom field on a product. */ -class BigCommerce_Api_CustomField extends BigCommerce_Api_Resource +class Bigcommerce_Api_CustomField extends Bigcommerce_Api_Resource { } @@ -363,7 +363,7 @@ class BigCommerce_Api_CustomField extends BigCommerce_Api_Resource /** * A configurable field on a product. */ -class BigCommerce_Api_ConfigurableField extends BigCommerce_Api_Resource +class Bigcommerce_Api_ConfigurableField extends Bigcommerce_Api_Resource { } @@ -371,7 +371,7 @@ class BigCommerce_Api_ConfigurableField extends BigCommerce_Api_Resource /** * A bulk discount rule. */ -class BigCommerce_Api_DiscountRule extends BigCommerce_Api_Resource +class Bigcommerce_Api_DiscountRule extends Bigcommerce_Api_Resource { } @@ -379,7 +379,7 @@ class BigCommerce_Api_DiscountRule extends BigCommerce_Api_Resource /** * A product video. */ -class BigCommerce_Api_Video extends BigCommerce_Api_Resource +class Bigcommerce_Api_Video extends Bigcommerce_Api_Resource { } @@ -387,7 +387,7 @@ class BigCommerce_Api_Video extends BigCommerce_Api_Resource /** * A product option rule. */ -class BigCommerce_Api_Rule extends BigCommerce_Api_Resource +class Bigcommerce_Api_Rule extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -402,7 +402,7 @@ class BigCommerce_Api_Rule extends BigCommerce_Api_Resource public function conditions() { - $conditions = BigCommerce_Api::getCollection($this->fields->conditions->resource, 'RuleCondition'); + $conditions = Bigcommerce_Api::getCollection($this->fields->conditions->resource, 'RuleCondition'); foreach($conditions as $condition) { $condition->product_id = $this->product_id; @@ -413,12 +413,12 @@ public function conditions() public function create() { - return BigCommerce_Api::createResource('/products/' . $this->product_id . '/rules', $this->getCreateFields()); + return Bigcommerce_Api::createResource('/products/' . $this->product_id . '/rules', $this->getCreateFields()); } public function update() { - BigCommerce_Api::updateResource('/products/' . $this->product_id . '/rules/' . $this->id, $this->getUpdateFields()); + Bigcommerce_Api::updateResource('/products/' . $this->product_id . '/rules/' . $this->id, $this->getUpdateFields()); } } @@ -426,7 +426,7 @@ public function update() /** * Conditions that will be applied to a product based on the rule. */ -class BigCommerce_Api_RuleCondition extends BigCommerce_Api_Resource +class Bigcommerce_Api_RuleCondition extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -442,16 +442,16 @@ class BigCommerce_Api_RuleCondition extends BigCommerce_Api_Resource public function create() { - return BigCommerce_Api::createResource('/products/' . $this->product_id . '/rules/' . $this->rule_id . '/conditions' , $this->getCreateFields()); + return Bigcommerce_Api::createResource('/products/' . $this->product_id . '/rules/' . $this->rule_id . '/conditions' , $this->getCreateFields()); } public function update() { - BigCommerce_Api::updateResource('/products/' . $this->product_id . '/rules/' . $this->rule_id . '/conditions/' .$this->id , $this->getUpdateFields()); + Bigcommerce_Api::updateResource('/products/' . $this->product_id . '/rules/' . $this->rule_id . '/conditions/' .$this->id , $this->getUpdateFields()); } } -class BigCommerce_Api_Category extends BigCommerce_Api_Resource +class Bigcommerce_Api_Category extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -466,37 +466,37 @@ class BigCommerce_Api_Category extends BigCommerce_Api_Resource public function create() { - return BigCommerce_Api::createCategory($this->getCreateFields()); + return Bigcommerce_Api::createCategory($this->getCreateFields()); } public function update() { - return BigCommerce_Api::updateCategory($this->id, $this->getUpdateFields()); + return Bigcommerce_Api::updateCategory($this->id, $this->getUpdateFields()); } } -class BigCommerce_Api_Order extends BigCommerce_Api_Resource +class Bigcommerce_Api_Order extends Bigcommerce_Api_Resource { public function shipments() { - return BigCommerce_Api::getCollection('/orders/'. $this->id . '/shipments', 'Shipment'); + return Bigcommerce_Api::getCollection('/orders/'. $this->id . '/shipments', 'Shipment'); } public function products() { - return BigCommerce_Api::getCollection($this->fields->products->resource, 'OrderProduct'); + return Bigcommerce_Api::getCollection($this->fields->products->resource, 'OrderProduct'); } public function shipping_addresses() { - return BigCommerce_Api::getCollection($this->fields->shipping_addresses->resource, 'Address'); + return Bigcommerce_Api::getCollection($this->fields->shipping_addresses->resource, 'Address'); } public function coupons() { - return BigCommerce_Api::getCollection($this->fields->coupons->resource, 'Coupon'); + return Bigcommerce_Api::getCollection($this->fields->coupons->resource, 'Coupon'); } public function update() @@ -505,17 +505,17 @@ public function update() $order->status_id = $this->status_id; $order->is_deleted = $this->is_deleted; - BigCommerce_Api::updateResource('/orders/' . $this->id, $order); + Bigcommerce_Api::updateResource('/orders/' . $this->id, $order); } } -class BigCommerce_Api_OrderProduct extends BigCommerce_Api_Resource +class Bigcommerce_Api_OrderProduct extends Bigcommerce_Api_Resource { } -class BigCommerce_Api_Shipment extends BigCommerce_Api_Resource +class Bigcommerce_Api_Shipment extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -537,37 +537,37 @@ class BigCommerce_Api_Shipment extends BigCommerce_Api_Resource public function create() { - return BigCommerce_Api::createResource('/orders/' . $this->order_id . '/shipments', $this->getCreateFields()); + return Bigcommerce_Api::createResource('/orders/' . $this->order_id . '/shipments', $this->getCreateFields()); } public function update() { - return BigCommerce_Api::createResource('/orders/' . $this->order_id . '/shipments' . $this->id, $this->getCreateFields()); + return Bigcommerce_Api::createResource('/orders/' . $this->order_id . '/shipments' . $this->id, $this->getCreateFields()); } } -class BigCommerce_Api_Coupon extends BigCommerce_Api_Resource +class Bigcommerce_Api_Coupon extends Bigcommerce_Api_Resource { } -class BigCommerce_Api_Customer extends BigCommerce_Api_Resource +class Bigcommerce_Api_Customer extends Bigcommerce_Api_Resource { public function addresses() { - return BigCommerce_Api::getCollection($this->fields->addresses->resource, 'Address'); + return Bigcommerce_Api::getCollection($this->fields->addresses->resource, 'Address'); } } -class BigCommerce_Api_Address extends BigCommerce_Api_Resource +class Bigcommerce_Api_Address extends Bigcommerce_Api_Resource { } -class BigCommerce_Api_OptionSet extends BigCommerce_Api_Resource +class Bigcommerce_Api_OptionSet extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -580,22 +580,22 @@ class BigCommerce_Api_OptionSet extends BigCommerce_Api_Resource public function options() { - return BigCommerce_Api::getCollection($this->fields->options->resource, 'OptionSetOption'); + return Bigcommerce_Api::getCollection($this->fields->options->resource, 'OptionSetOption'); } public function create() { - return BigCommerce_Api::createResource('/optionsets', $this->getCreateFields()); + return Bigcommerce_Api::createResource('/optionsets', $this->getCreateFields()); } public function update() { - BigCommerce_Api::updateResource('/optionsets/' . $this->id, $this->getUpdateFields()); + Bigcommerce_Api::updateResource('/optionsets/' . $this->id, $this->getUpdateFields()); } } -class BigCommerce_Api_OptionSetOption extends BigCommerce_Api_Resource +class Bigcommerce_Api_OptionSetOption extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -611,22 +611,22 @@ class BigCommerce_Api_OptionSetOption extends BigCommerce_Api_Resource public function option() { - return BigCommerce_Api::getCollection($this->fields->option->resource); + return Bigcommerce_Api::getCollection($this->fields->option->resource); } public function create() { - return BigCommerce_Api::createResource('/optionsets/options', $this->getCreateFields()); + return Bigcommerce_Api::createResource('/optionsets/options', $this->getCreateFields()); } public function update() { - BigCommerce_Api::updateResource('/optionsets/options/' . $this->id, $this->getUpdateFields()); + Bigcommerce_Api::updateResource('/optionsets/options/' . $this->id, $this->getUpdateFields()); } } -class BigCommerce_Api_Brand extends BigCommerce_Api_Resource +class Bigcommerce_Api_Brand extends Bigcommerce_Api_Resource { protected $ignoreOnCreate = array( @@ -639,17 +639,17 @@ class BigCommerce_Api_Brand extends BigCommerce_Api_Resource public function create() { - return BigCommerce_Api::createBrand($this->getCreateFields()); + return Bigcommerce_Api::createBrand($this->getCreateFields()); } public function update() { - return BigCommerce_Api::updateBrand($this->id, $this->getUpdateFields()); + return Bigcommerce_Api::updateBrand($this->id, $this->getUpdateFields()); } } -class BigCommerce_Api_OrderStatus extends BigCommerce_Api_Resource +class Bigcommerce_Api_OrderStatus extends Bigcommerce_Api_Resource { } @@ -657,7 +657,7 @@ class BigCommerce_Api_OrderStatus extends BigCommerce_Api_Resource /** * Represents a request to the API. */ -class BigCommerce_Api_RequestLog extends BigCommerce_Api_Resource +class Bigcommerce_Api_RequestLog extends Bigcommerce_Api_Resource { } \ No newline at end of file diff --git a/LICENSE b/LICENSE index 6b1c1945..1a0fd247 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (C) BigCommerce, 2011. +Copyright (C) Bigcommerce, 2011. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/README.md b/README.md index 52f1a358..e80b0e3e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -BigCommerce REST API V2 +Bigcommerce REST API V2 ======================= -PHP package for connecting to the BigCommerce REST API. +PHP package for connecting to the Bigcommerce V2 REST API. To find out more, visit the official documentation website: http://developer.bigcommerce.com/ @@ -14,7 +14,7 @@ Requirements To connect to the API, you need the following credentials: -- Secure URL pointing to a BigCommerce store +- Secure URL pointing to a Bigcommerce store - Username of an authorized admin user of the store - API key for the user @@ -24,13 +24,13 @@ the 'Enable the XML API?' is ticked. Installation ------------ -Download the required PHP code for the BigCommerce REST API client and copy it +Download the required PHP code for the Bigcommerce REST API client and copy it to your PHP include path, or use the following command to install the package directly (note: you may need to use sudo): ``` $ pear channel-discover bigcommerce.github.com/bigcommerce-api-php - $ pear install bigcommerce/BigCommerce_Api-beta + $ pear install bigcommerce/Bigcommerce_Api-beta ``` Configuration @@ -40,9 +40,9 @@ To use the API client in your PHP code, require the package from your include path and provide the required credentials as follows: ``` -require_once 'BigCommerce/Api.php'; +require_once 'Bigcommerce/Api.php'; -BigCommerce_Api::configure(array( +Bigcommerce_Api::configure(array( 'store_url' => 'https://store.mybigcommerce.com', 'username' => 'admin', 'api_key' => 'd81aada4c19c34d913e18f07fd7f36ca' @@ -58,7 +58,7 @@ representing the current timestamp of the store if successful or false if unsuccessful: ``` -$ping = BigCommerce_Api::getTime(); +$ping = Bigcommerce_Api::getTime(); if ($ping) echo $ping->format('H:i:s'); ``` @@ -69,7 +69,7 @@ Accessing collections and resources (GET) To list all the resources in a collection: ``` -$products = BigCommerce_Api::getProducts(); +$products = Bigcommerce_Api::getProducts(); foreach($products as $product) { echo $product->name; @@ -80,7 +80,7 @@ foreach($products as $product) { To access a single resource and its connected sub-resources: ``` -$product = BigCommerce_Api::getProduct(11); +$product = Bigcommerce_Api::getProduct(11); echo $product->name; echo $product->price; @@ -89,7 +89,7 @@ echo $product->price; To view the total count of resources in a collection: ``` -$count = BigCommerce_Api::getProductsCount(); +$count = Bigcommerce_Api::getProductsCount(); echo $count; ``` @@ -100,7 +100,7 @@ All the default collection methods support paging, by passing the page number to the method as an integer: ``` -$products = BigCommerce_Api::getProducts(3); +$products = Bigcommerce_Api::getProducts(3); ``` If you require more specific numbering and paging, you can explicitly specify a limit parameter: @@ -108,7 +108,7 @@ a limit parameter: ``` $filter = array("page" => 3, "limit" => 30); -$products = BigCommerce_Api::getProducts($filter); +$products = Bigcommerce_Api::getProducts($filter); ``` To filter a collection, you can also pass parameters to filter by as key-value @@ -117,7 +117,7 @@ pairs: ``` $filter = array("is_featured" => true); -$featured = BigCommerce_Api::getProducts($filter); +$featured = Bigcommerce_Api::getProducts($filter); ``` See the API documentation for each resource for a list of supported filter parameters. @@ -128,7 +128,7 @@ Updating existing resources (PUT) To update a single resource: ``` -$product = BigCommerce_Api::getProduct(11); +$product = Bigcommerce_Api::getProduct(11); $product->name = "MacBook Air"; $product->price = 99.95; @@ -144,7 +144,7 @@ $fields = array( "price" => 999.95 ); -BigCommerce_Api::updateProduct(11, $fields); +Bigcommerce_Api::updateProduct(11, $fields); ``` Creating new resources (POST) @@ -159,14 +159,14 @@ $fields = array( "name" => "Apple" ); -BigCommerce_Api::createBrand($fields); +Bigcommerce_Api::createBrand($fields); ``` You can also create a resource by making a new instance of the resource class and calling the create method once you have set the fields you want to save: ``` -$brand = new BigCommerce_Api_Brand(); +$brand = new Bigcommerce_Api_Brand(); $brand->name = "Apple"; $brand->create(); @@ -178,21 +178,21 @@ Deleting resources and collections (DELETE) To delete a single resource you can call the delete method on the resource object: ``` -$category = BigCommerce_Api::getCategory(22); +$category = Bigcommerce_Api::getCategory(22); $category->delete(); ``` You can also delete resources by calling the global wrapper method: ``` -BigCommerce_Api::deleteCategory(22); +Bigcommerce_Api::deleteCategory(22); ``` Some resources support deletion of the entire collection. You can use the deleteAll methods to do this: ``` -BigCommerce_Api::deleteAllOptionSets(); +Bigcommerce_Api::deleteAllOptionSets(); ``` Using The XML API @@ -203,7 +203,7 @@ JSON strings and their PHP object representations. If you need to work with XML you can switch the API into XML mode with the useXml method: ``` -BigCommerce_Api::useXml(); +Bigcommerce_Api::useXml(); ``` This will configure the API client to use XML for all subsequent requests. Note @@ -214,7 +214,7 @@ containing valid XML, and all responses from collection and resource methods objects. An example transaction using XML would look like: ``` -BigCommerce_Api::useXml(); +Bigcommerce_Api::useXml(); $xml = " @@ -222,7 +222,7 @@ $xml = " computers laptops "; -$result = BigCommerce_Api::createBrand($xml); +$result = Bigcommerce_Api::createBrand($xml); ``` Handling Errors And Timeouts @@ -239,10 +239,10 @@ This would most often be when you tried to save some data that did not validate correctly. ``` -$orders = BigCommerce_Api::getOrders(); +$orders = Bigcommerce_Api::getOrders(); if (!$orders) { - $error = BigCommerce_Api::getLastError(); + $error = Bigcommerce_Api::getLastError(); echo $error->code; echo $error->message; } @@ -258,18 +258,18 @@ need to catch and handle the exception in code yourself. The exception throwing behavior of the client is controlled using the failOnError method: ``` -BigCommerce_Api::failOnError(); +Bigcommerce_Api::failOnError(); try { - $orders = BigCommerce_Api::getOrders(); + $orders = Bigcommerce_Api::getOrders(); -} catch(BigCommerce_Api_Error $error) { +} catch(Bigcommerce_Api_Error $error) { echo $error->getCode(); echo $error->getMessage(); } ``` -The exceptions thrown are subclasses of BigCommerce_Api_Error, representing +The exceptions thrown are subclasses of Bigcommerce_Api_Error, representing client errors and server errors. The API documentation for response codes contains a list of all the possible error conditions the client may encounter. @@ -282,19 +282,19 @@ The client will set this cipher to be used by default. The setCipher method can be used to override this setting if required. ``` -BigCommerce_Api::setCipher('RC4-SHA'); +Bigcommerce_Api::setCipher('RC4-SHA'); ``` Verifying SSL certificates -------------------------- By default, the client will attempt to verify the SSL certificate used by the -BigCommerce store. In cases where this is undesirable, or where an unsigned +Bigcommerce store. In cases where this is undesirable, or where an unsigned certificate is being used, you can turn off this behavior using the verifyPeer switch, which will disable certificate checking on all subsequent requests: ``` -BigCommerce_Api::verifyPeer(false); +Bigcommerce_Api::verifyPeer(false); ``` Connecting through a proxy server @@ -305,5 +305,5 @@ need to configure the client to recognize this. Provide the URL of the proxy server and (optionally) a port to the useProxy method: ``` -BigCommerce_Api::useProxy("http://proxy.example.com", 81); +Bigcommerce_Api::useProxy("http://proxy.example.com", 81); ``` diff --git a/Tests/ApiTest.php b/Tests/ApiTest.php index 21bf9709..b06fedd7 100644 --- a/Tests/ApiTest.php +++ b/Tests/ApiTest.php @@ -1,38 +1,38 @@ TEST_STORE_URL, 'username' => TEST_STORE_USER, 'api_key' => TEST_STORE_API_KEY, )); -BigCommerce_Api::failOnError(true); +Bigcommerce_Api::failOnError(true); -class BigCommerce_Api_TimeTest extends PHPUnit_Framework_TestCase +class Bigcommerce_Api_TimeTest extends PHPUnit_Framework_TestCase { public function testTimestampPing() { - $time = BigCommerce_Api::getTime(); + $time = Bigcommerce_Api::getTime(); $this->assertTrue($time instanceOf DateTime); } } -class BigCommerce_Api_ProductTest extends PHPUnit_Framework_TestCase +class Bigcommerce_Api_ProductTest extends PHPUnit_Framework_TestCase { public function testProductCollection() { - $products = BigCommerce_Api::getProducts(); + $products = Bigcommerce_Api::getProducts(); $this->assertTrue(is_array($products)); } public function testProductResource() { - $product = BigCommerce_Api::getProduct(1); + $product = Bigcommerce_Api::getProduct(1); $this->assertEquals(1, $product->id); } diff --git a/Tests/FilterTest.php b/Tests/FilterTest.php index 628f8d08..51a3f9cd 100644 --- a/Tests/FilterTest.php +++ b/Tests/FilterTest.php @@ -1,31 +1,31 @@ assertEquals("", $filter->toQuery()); } public function testFactoryWithEmptyParam() { - $filter = BigCommerce_Api_Filter::create(array()); + $filter = Bigcommerce_Api_Filter::create(array()); $this->assertEquals("", $filter->toQuery()); } public function testFactoryWithSingleParam() { - $filter = BigCommerce_Api_Filter::create(array("key"=>"value")); + $filter = Bigcommerce_Api_Filter::create(array("key"=>"value")); $this->assertEquals("?key=value", $filter->toQuery()); } public function testFactoryWithMultipleParams() { - $filter = BigCommerce_Api_Filter::create(array("one"=>"1", "two"=>"2")); + $filter = Bigcommerce_Api_Filter::create(array("one"=>"1", "two"=>"2")); $this->assertEquals("?one=1&two=2", $filter->toQuery()); } diff --git a/composer.json b/composer.json new file mode 100644 index 00000000..fa7f31c6 --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "bigcommerce/api-v2", + "type": "library", + "description": "Enables PHP applications to communicate with the Bigcommerce V2 API.", + "keywords": ["api","http","rest","ecommerce","business"], + "homepage": "http://developer.bigcommerce.com", + "license": "MIT", + "authors": [ + { + "name": "Bigcommerce", + "homepage": "http://www.bigcommerce.com", + } + ], + "require": { + "php": ">=5.3.0" + }, + "autoload": { + "psr-0": { + "Bigcommerce_": "Bigcommerce" + } + } +} \ No newline at end of file diff --git a/package.xml b/package.xml index 81d658bf..f053e4c2 100644 --- a/package.xml +++ b/package.xml @@ -6,12 +6,12 @@ http://pear.php.net/dtd/tasks-1.0.xsd http://pear.php.net/dtd/package-2.0 http://pear.php.net/dtd/package-2.0.xsd"> - BigCommerce_Api + Bigcommerce_Api bigcommerce.github.com/bigcommerce-api-php - Enables PHP applications to communicate with the BigCommerce API. - Enables PHP applications to communicate with the BigCommerce API. + Enables PHP applications to communicate with the Bigcommerce API. + Enables PHP applications to communicate with the Bigcommerce API. - BigCommerce + Bigcommerce bigcommerce dev-accounts@bigcommerce.com yes @@ -32,7 +32,7 @@ - +