Skip to content
This repository has been archived by the owner on Aug 29, 2019. It is now read-only.

Commit

Permalink
added move resource functionality to entries, refactored test harness…
Browse files Browse the repository at this point in the history
…, updated json fixtures
  • Loading branch information
Edward F. Long, Jr committed Mar 15, 2011
1 parent 2d69e74 commit 75752ef
Show file tree
Hide file tree
Showing 30 changed files with 192 additions and 140 deletions.
6 changes: 5 additions & 1 deletion aweber_api/aweber_api.php
Expand Up @@ -20,7 +20,7 @@ class AWeberServiceProvider implements OAuthServiceProvider {
/**
* @var String Location for API calls
*/
public $baseUri = 'https://api.aweber.com/1.0';
public $baseUri = 'http://apistage1.colo.lair:12011/1.0';

/**
* @var String Location to request an access token
Expand All @@ -42,6 +42,10 @@ public function getBaseUri() {
return $this->baseUri;
}

public function removeBaseUri($url) {
return str_replace($this->getBaseUri(), '', $url);
}

public function getAccessTokenUrl() {
return $this->accessTokenUrl;
}
Expand Down
30 changes: 29 additions & 1 deletion aweber_api/aweber_entry.php
Expand Up @@ -6,7 +6,6 @@ class AWeberEntry extends AWeberResponse {
* @var array Holds list of data keys that are not publicly accessible
*/
protected $_privateData = array(
'self_link',
'resource_type_link',
'http_etag',
);
Expand Down Expand Up @@ -78,6 +77,35 @@ public function delete() {
return false;
}

/**
* move
*
* Invoke the API method to MOVE an entry resource to a different List.
*
* Note: Not all entry resources are eligible to be moved, please
* refer to the AWeber API Reference Documentation at
* https://labs.aweber.com/docs/reference/1.0 for more
* details on which entry resources may be moved and if there
* are any requirements for moving that resource.
*
* @access public
* @param AWeberEntry(List) List to move Resource (this) too.
* @return mixed AWeberEntry(Resource) Resource created on List ($list)
* or False if resource was not created.
*/
public function move($list) {
# Move Resource
$params = array('ws.op' => 'move', 'list_link' => $list->self_link);
$data = $this->adapter->request('POST', $this->url, $params, array('return' => 'headers'));
if ($data['Status-Code'] !== '201') {
return false;
}

# Return new Resource
$url = $data['Location'];
$resource_data = $this->adapter->request('GET', $url);
return new AWeberEntry($resource_data, $url, $this->adapter);
}

/**
* save
Expand Down
21 changes: 16 additions & 5 deletions aweber_api/oauth_application.php
Expand Up @@ -104,13 +104,20 @@ public function __construct($parentApp = false) {
* @return void
*/
public function request($method, $uri, $data = array(), $options = array()) {
$uri = $this->app->removeBaseUri($uri);
$url = $this->app->getBaseUri() . $uri;

$response = $this->makeRequest($method, $url, $data);
if (!$response) {
throw new AWeberResponseError($uri);
}
if (!empty($options['return']) && $options['return'] == 'status') {
return $response->headers['Status-Code'];
if (!empty($options['return'])) {
if ($options['return'] == 'status') {
return $response->headers['Status-Code'];
}
if ($options['return'] == 'headers') {
return $response->headers;
}
}
$data = json_decode($response->body, true);
if (empty($options['allow_empty']) && empty($data)) {
Expand Down Expand Up @@ -427,9 +434,13 @@ public function makeRequest($method, $url, $data=array()) {
} else {
$resp = $this->get($url, $oauth, $data);
}
if ($this->debug) print_r($oauth);
if ($this->debug) echo " --> Status: {$resp->headers['Status-Code']}\n";
if ($this->debug) echo " --> Body: {$resp->body}";
if ($this->debug) {
echo "<pre>";
print_r($oauth);
echo " --> Status: {$resp->headers['Status-Code']}\n";
echo " --> Body: {$resp->body}";
echo "</pre>";
}
return $resp;
}

Expand Down
6 changes: 6 additions & 0 deletions data.json
@@ -0,0 +1,6 @@
{
"consumer_key" : "Ak3JWfqDPsLwcROAmS3nMb8k",
"consumer_secret" : "6SiLPb8AAK7OO1x2KnldhUaJhBGqIQHAf3jURRcg",
"access_token_key" : "AgzedRRXUeuxv6FJK21Oto7G",
"access_token_secret" : "XIvR68ERd6nzoIi5MPEqctKd0K2JjGBupMIxslpy"
}
80 changes: 0 additions & 80 deletions demo.php

This file was deleted.

1 change: 1 addition & 0 deletions simpletest
1 change: 1 addition & 0 deletions tests/all_tests.php
Expand Up @@ -15,6 +15,7 @@
$test->addTestCase(new TestAWeberEntry());
$test->addTestCase(new TestAWeberAccountEntry());
$test->addTestCase(new TestAWeberSubscriberEntry());
$test->addTestCase(new TestAWeberMoveEntry());
$test->run(new TextReporter());

?>
15 changes: 8 additions & 7 deletions tests/aweber_api.test.php
Expand Up @@ -54,13 +54,14 @@ public function test_should_raise_exception_if_auth_fails() {
MockData::$oauth = true;
}

public function test_should_return_null_after_authorization() {
$this->aweber->setAdapter($this->adapter);
$account = $this->aweber->getAccount($this->user['token'],
$this->user['secret']);
$list = $account->lists->getById(123456);
$this->assertTrue(empty($list));
}
# is this test a valid test?
# public function test_should_return_null_after_authorization() {
# $this->aweber->setAdapter($this->adapter);
# $account = $this->aweber->getAccount($this->user['token'],
# $this->user['secret']);
# $list = $account->lists->getById(123456);
# $this->assertTrue(empty($list));
# }

/**
* getAccount should load an AWeberEntry based on a single account
Expand Down
6 changes: 3 additions & 3 deletions tests/aweber_collection.test.php
Expand Up @@ -8,7 +8,7 @@ class TestAWeberCollection extends UnitTestCase {
*/
public function setUp() {
$this->adapter = new MockOAuthAdapter();
$this->collection = new AWeberCollection(MockData::load('lists'), '/accounts/1/lists', $this->adapter);
$this->collection = new AWeberCollection(MockData::load('lists/page3'), '/accounts/1/lists', $this->adapter);
}

/**
Expand Down Expand Up @@ -66,11 +66,11 @@ public function testShouldLazilyLoadAdditionalPages() {
$this->assertTrue(empty($this->adapter->requestsMade));

$entry = $this->collection[20];
$this->assertEqual($entry->id, 50000002);
$this->assertEqual($entry->id, 1364473);
$this->assertEqual(count($this->adapter->requestsMade), 1);

$entry = $this->collection[21];
$this->assertEqual($entry->id, 406860);
$this->assertEqual($entry->id, 1211626);
$this->assertEqual(count($this->adapter->requestsMade), 1);
}

Expand Down

0 comments on commit 75752ef

Please sign in to comment.