Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update card.getAddresses method to retrieve from API #140

Merged
merged 1 commit into from
Sep 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 9 additions & 28 deletions lib/Uphold/Model/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ class Card extends BaseModel implements CardInterface
*/
protected $address;

/**
* List of card addresses.
*
* @var array
*/
protected $addresses;

/**
* Available amount.
*
Expand Down Expand Up @@ -95,14 +88,6 @@ public function getAddress()
return $this->address;
}

/**
* {@inheritdoc}
*/
public function getAddresses()
{
return $this->addresses;
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -159,6 +144,14 @@ public function getSettings()
return $this->settings;
}

/**
* {@inheritdoc}
*/
public function getAddresses()
{
return $this->client->get(sprintf('/me/cards/%s/addresses', $this->id))->getContent();
}

/**
* {@inheritdoc}
*/
Expand All @@ -175,9 +168,7 @@ public function getTransactions()
*/
public function createCryptoAddress($network)
{
$response = $this->client->post(sprintf('/me/cards/%s/addresses', $this->id), array('network' => $network));

$this->addAddress($response->getContent());
$this->client->post(sprintf('/me/cards/%s/addresses', $this->id), array('network' => $network));

return $this;
}
Expand Down Expand Up @@ -214,14 +205,4 @@ public function update(array $data)

return $this;
}

/**
* {@inheritdoc}
*/
private function addAddress($address)
{
$this->addresses[] = $address;

return $this;
}
}
14 changes: 7 additions & 7 deletions lib/Uphold/Model/CardInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ interface CardInterface
*/
public function getAddress();

/**
* Gets list of card addresses.
*
* @return $addresses
*/
public function getAddresses();

/**
* Checks if the card is currently available.
*
Expand Down Expand Up @@ -70,6 +63,13 @@ public function getLastTransactionAt();
*/
public function getSettings();

/**
* Gets list of card addresses.
*
* @return array
*/
public function getAddresses();

/**
* Gets the transactions associated with the card identified by the user.
*
Expand Down
23 changes: 18 additions & 5 deletions test/Uphold/Tests/Unit/Model/CardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,28 @@ public function shouldReturnSettings()
*/
public function shouldReturnAddresses()
{
$data = array('addresses' => array(array('id' => '1GpBtJXXa1NdG94cYPGZTc3DfRY2P7EwzH', 'network' => 'bitcoin')));
$cardData = array('id' => 'ade869d8-7913-4f67-bb4d-72719f0a2be0');
$data = array(array(
'id' => 'a97bb994-6e24-4a89-b653-e0a6d0bcf634',
'status' => 'bitcoin',
), array(
'id' => 'b97bb994-6e24-4a89-b653-e0a6d0bcf635',
'status' => 'foobar',
));

$response = $this->getResponseMock($data);
$client = $this->getUpholdClientMock();

$card = new Card($client, $data);
$client
->expects($this->once())
->method('get')
->with(sprintf('/me/cards/%s/addresses', $cardData['id']))
->will($this->returnValue($response))
;

$card = new Card($client, $cardData);

$this->assertEquals($data['addresses'], $card->getAddresses());
$this->assertEquals($data, $card->getAddresses());
}

/**
Expand Down Expand Up @@ -253,8 +268,6 @@ public function shouldCreateNewCryptoAddress()

$card = new Card($client, $cardData);
$card->createCryptoAddress('foobar');

$this->assertEquals($card->getAddresses(), array($data));
}

/**
Expand Down