Skip to content

Commit

Permalink
Fixed cURL errors and SDK instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Wittman committed Jun 15, 2016
1 parent a6ef1dd commit 2ae4784
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 17 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
### 1.0.1 2016-05-10

* Fixed Shopify\Shopify static function error


### 1.0.2 2016-06-15

* Fixed exception when Http\Client calls failed due to non-API causes
* Using uninitialized SDK now throws Exception instead of vague errors
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ $product->update();

### Deleting

To delete an object, simply call the objects static delete() method, passing the ID
To delete an object, simply call the objects delete() method, passing the ID
```php
(new \Shopify\Product(123412341))->delete();
// returns NULL
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.1
1.0.2
13 changes: 6 additions & 7 deletions lib/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use Shopify\Shopify;
use Shopify\Util;
use Shopify\Exception;

class Client
{
Expand Down Expand Up @@ -104,7 +103,7 @@ public function request(Request $request)//$method, $url, $params = array(), $js
}
}
} else {
throw new Exception\ApiException("Unrecognized method {$method}");
throw new \Shopify\Exception\ApiException("Unrecognized method {$method}");
}
$opts[CURLOPT_URL] = $url;
$opts[CURLOPT_RETURNTRANSFER] = TRUE;
Expand Down Expand Up @@ -138,16 +137,16 @@ public function request(Request $request)//$method, $url, $params = array(), $js
$errors = $jsonBody->errors;
if(is_string($errors))
{
throw new Exception\ApiException($errors);
throw new \Shopify\Exception\ApiException($errors);
} else {
$field = key((array) $errors);
$error = $errors->{$field}[0];
throw new Exception\ApiException(ucfirst($field).' '.$error);
throw new \Shopify\Exception\ApiException(ucfirst($field).' '.$error);
}
}
unset($jsonBody);


$this->handleHttpCode($response->getHttpCode());
return $response;
}
Expand Down Expand Up @@ -183,7 +182,7 @@ private function handleHttpCode($code)
break;
default: $msg = "An unknown error code [{$code}] was returned";
}
throw new Exception\ApiException($msg);
throw new \Shopify\Exception\ApiException($msg);
}
}

Expand All @@ -207,7 +206,7 @@ private function handleCurlError($url, $errno, $message)
$msg = "nUnexpected error communicating with Shopify";
}
$msg .= "\n\n(Network error [errno $errno]: $message)";
throw new Exception\CurlException($msg);
throw new \Shopify\Exception\CurlException($msg);
}

/**
Expand Down
8 changes: 6 additions & 2 deletions lib/Shopify.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Shopify
* Singleton instance of the SDK
* @var Shopify
*/
protected static $instance;
protected static $instance = NULL;

/**
* Handle for the HTTP Client
Expand Down Expand Up @@ -57,7 +57,7 @@ class Shopify
* The store we are initializing for
* @var string
*/
public static $store = 'test-shop.myshopify.com';
public static $store = 'localhost.myshopify.com';

/**
* Access token for the given store
Expand Down Expand Up @@ -114,6 +114,10 @@ public static function init(array $opts = array())
*/
public static function instance()
{
if(is_null(static::$instance))
{
throw new \Shopify\Exception\ApiException("SDK has not been intialized. Start with \Shopify\Shopify::init()");
}
return static::$instance;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Http/TestClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TestClientTest extends TestCase
{
private $client;
protected $client;

public function setUp()
{
Expand Down
6 changes: 3 additions & 3 deletions tests/ShopifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class ShopifyTest extends TestCase
'api_secret' => "asdpaosidcoaij23r",
'redirect_uri' => "https://some_randomg_url",
'access_token' => 'asdifpaoisdjpfaoijsdfp',
'store' => 'test-shop.myshopify.com',
'permissions' => "read_products,write_products"
'permissions' => "read_products,write_products",
'store' => "dev.myshopify.com"
];

public function testInit()
Expand Down Expand Up @@ -99,6 +99,6 @@ public function testPermissionsValue()
*/
public function testBaseUrl()
{
$this->assertEquals(Shopify::baseUrl(), sprintf("https://%s/admin/", 'test-shop.myshopify.com'));
$this->assertEquals(Shopify::baseUrl(), sprintf("https://%s/admin/", 'dev.myshopify.com'));
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TestCase extends \PHPUnit_Framework_TestCase
{
private $client;
protected $client;

public function setUp()
{
Expand Down

0 comments on commit 2ae4784

Please sign in to comment.