Skip to content

Commit 2ae4784

Browse files
author
Robert Wittman
committed
Fixed cURL errors and SDK instance
1 parent a6ef1dd commit 2ae4784

File tree

8 files changed

+24
-17
lines changed

8 files changed

+24
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
### 1.0.1 2016-05-10
88

99
* Fixed Shopify\Shopify static function error
10-
10+
11+
### 1.0.2 2016-06-15
12+
13+
* Fixed exception when Http\Client calls failed due to non-API causes
14+
* Using uninitialized SDK now throws Exception instead of vague errors

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ $product->update();
128128

129129
### Deleting
130130

131-
To delete an object, simply call the objects static delete() method, passing the ID
131+
To delete an object, simply call the objects delete() method, passing the ID
132132
```php
133133
(new \Shopify\Product(123412341))->delete();
134134
// returns NULL

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.1
1+
1.0.2

lib/Http/Client.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
use Shopify\Shopify;
1111
use Shopify\Util;
12-
use Shopify\Exception;
1312

1413
class Client
1514
{
@@ -104,7 +103,7 @@ public function request(Request $request)//$method, $url, $params = array(), $js
104103
}
105104
}
106105
} else {
107-
throw new Exception\ApiException("Unrecognized method {$method}");
106+
throw new \Shopify\Exception\ApiException("Unrecognized method {$method}");
108107
}
109108
$opts[CURLOPT_URL] = $url;
110109
$opts[CURLOPT_RETURNTRANSFER] = TRUE;
@@ -138,16 +137,16 @@ public function request(Request $request)//$method, $url, $params = array(), $js
138137
$errors = $jsonBody->errors;
139138
if(is_string($errors))
140139
{
141-
throw new Exception\ApiException($errors);
140+
throw new \Shopify\Exception\ApiException($errors);
142141
} else {
143142
$field = key((array) $errors);
144143
$error = $errors->{$field}[0];
145-
throw new Exception\ApiException(ucfirst($field).' '.$error);
144+
throw new \Shopify\Exception\ApiException(ucfirst($field).' '.$error);
146145
}
147146
}
148147
unset($jsonBody);
149148

150-
149+
151150
$this->handleHttpCode($response->getHttpCode());
152151
return $response;
153152
}
@@ -183,7 +182,7 @@ private function handleHttpCode($code)
183182
break;
184183
default: $msg = "An unknown error code [{$code}] was returned";
185184
}
186-
throw new Exception\ApiException($msg);
185+
throw new \Shopify\Exception\ApiException($msg);
187186
}
188187
}
189188

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

213212
/**

lib/Shopify.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Shopify
2121
* Singleton instance of the SDK
2222
* @var Shopify
2323
*/
24-
protected static $instance;
24+
protected static $instance = NULL;
2525

2626
/**
2727
* Handle for the HTTP Client
@@ -57,7 +57,7 @@ class Shopify
5757
* The store we are initializing for
5858
* @var string
5959
*/
60-
public static $store = 'test-shop.myshopify.com';
60+
public static $store = 'localhost.myshopify.com';
6161

6262
/**
6363
* Access token for the given store
@@ -114,6 +114,10 @@ public static function init(array $opts = array())
114114
*/
115115
public static function instance()
116116
{
117+
if(is_null(static::$instance))
118+
{
119+
throw new \Shopify\Exception\ApiException("SDK has not been intialized. Start with \Shopify\Shopify::init()");
120+
}
117121
return static::$instance;
118122
}
119123

tests/Http/TestClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class TestClientTest extends TestCase
66
{
7-
private $client;
7+
protected $client;
88

99
public function setUp()
1010
{

tests/ShopifyTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ class ShopifyTest extends TestCase
1212
'api_secret' => "asdpaosidcoaij23r",
1313
'redirect_uri' => "https://some_randomg_url",
1414
'access_token' => 'asdifpaoisdjpfaoijsdfp',
15-
'store' => 'test-shop.myshopify.com',
16-
'permissions' => "read_products,write_products"
15+
'permissions' => "read_products,write_products",
16+
'store' => "dev.myshopify.com"
1717
];
1818

1919
public function testInit()
@@ -99,6 +99,6 @@ public function testPermissionsValue()
9999
*/
100100
public function testBaseUrl()
101101
{
102-
$this->assertEquals(Shopify::baseUrl(), sprintf("https://%s/admin/", 'test-shop.myshopify.com'));
102+
$this->assertEquals(Shopify::baseUrl(), sprintf("https://%s/admin/", 'dev.myshopify.com'));
103103
}
104104
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class TestCase extends \PHPUnit_Framework_TestCase
66
{
7-
private $client;
7+
protected $client;
88

99
public function setUp()
1010
{

0 commit comments

Comments
 (0)