Skip to content
Browse files

oauth request: return 0 as response err

handle the 0 response to an empty set.
1 parent 0464c4c commit 05efa07b64b57a45eaa353c47beb0239220ccf16 Mike Druger committed with Edward F Long, Jr
Showing with 26 additions and 4 deletions.
  1. +9 −1 .gitignore
  2. +3 −0 README.md
  3. +3 −2 aweber_api/oauth_application.php
  4. +9 −0 tests/OAuthApplicationTest.php
  5. +1 −0 tests/data/empty.json
  6. +1 −1 tests/mock_adapter.php
View
10 .gitignore
@@ -1,2 +1,10 @@
-*.svn
+.DS_Store
+Icon?
+Thumbs.db
+ehthumbs.db
+*.bak
+*.swm
+*.swn
+*.swo
*.swp
+*~
View
3 README.md
@@ -61,6 +61,9 @@ subscriber information.
Changelog:
----------
+2012-12-13: v1.1.8
+ * Fixed a bug that resulted in Exceptions being raised when using collections when the collection size is zero.
+
2012-12-10: v1.1.7
* Added a parameter to the Move Subscriber method for last followup message number sent.
* to support version 1.0.16 of the API. See https://labs.aweber.com/docs/changelog
View
5 aweber_api/oauth_application.php
@@ -117,7 +117,6 @@ public function request($method, $uri, $data = array(), $options = array()) {
}
$response = $this->makeRequest($method, $url, $data);
-
if (!empty($options['return'])) {
if ($options['return'] == 'status') {
return $response->headers['Status-Code'];
@@ -129,8 +128,10 @@ public function request($method, $uri, $data = array(), $options = array()) {
return intval($response->body);
}
}
+
$data = json_decode($response->body, true);
- if (empty($options['allow_empty']) && empty($data)) {
+
+ if (empty($options['allow_empty']) && !isset($data)) {
throw new AWeberResponseError($uri);
}
return $data;
View
9 tests/OAuthApplicationTest.php
@@ -1,5 +1,6 @@
<?php
require_once('aweber_api/aweber_api.php');
+require_once('mock_adapter.php');
if (!class_exists('Object')) {
class Object {}
@@ -293,4 +294,12 @@ public function testParseResponse() {
$this->assertSame($data, $dataShouldBe, 'Data is parsed correctly.');
}
+ public function testRequestReturnValueIsZeroNotInJSONFormat(){
+ $this->adapter = get_mock_adapter();
+ $url = '/accounts/1/lists/303449/subscribers?email=someone%40example.com&ws.show=total_size';
+ $data = $this->adapter->request('GET', $url);
+ $this->assertTrue(isset($data));
+ $this->assertEquals($data,0);
+ }
+
}
View
1 tests/data/empty.json
@@ -0,0 +1 @@
+0
View
2 tests/mock_adapter.php
@@ -35,6 +35,7 @@ function get_mock_adapter() {
$map['GET' ]['/accounts/1?email=joe%40example.com&ws.op=findSubscribers' ] = array(200, 'accounts/findSubscribers');
$map['GET' ]['/accounts/1?ws.op=getWebFormSplitTests' ] = array(200, 'accounts/webFormSplitTests');
$map['GET' ]['/accounts/1?ws.op=getWebForms' ] = array(200, 'accounts/webForms');
+$map['GET' ]['/accounts/1/lists/303449/subscribers?email=someone%40example.com&ws.show=total_size' ] = array(200, 'empty');
$map['PATCH' ]['/accounts/1/lists/303449' ] = array(209, 'lists/303449');
$map['PATCH' ]['/accounts/1/lists/303449/subscribers/1' ] = array(209, 'subscribers/1');
@@ -78,7 +79,6 @@ public function makeRequest($method, $url, $data=array()) {
# load response from fixture and return data
$mock_data = MockData::load($resource);
-
if (!$mock_data) {
$msg = 'Unable to connect to the AWeber API. Please ensure that CURL is enabled and your ';
$msg .= 'firewall allows outbound SSL requests from your web server.';

0 comments on commit 05efa07

Please sign in to comment.
Something went wrong with that request. Please try again.