Skip to content

Partner account #107

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

Merged
merged 2 commits into from
Dec 18, 2019
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
1 change: 0 additions & 1 deletion examples/partner-account-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

$account = new \MessageBird\Objects\PartnerAccount\Account();
$account->name = 'Name Test';
$account->email = '[email protected]';

try {
$partnerAccountResult = $messageBird->partnerAccounts->create($account);
Expand Down
20 changes: 20 additions & 0 deletions examples/partner-account-update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

require_once(__DIR__ . '/../autoload.php');

$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.

$account = new \MessageBird\Objects\PartnerAccount\Account();
$account->name = 'Name Test';

try {
$partnerAccountResult = $messageBird->partnerAccounts->update($account, 1);
var_dump($partnerAccountResult);

} catch (\MessageBird\Exceptions\AuthenticateException $e) {
// That means that your accessKey is unknown
echo 'wrong login';

} catch (\Exception $e) {
echo $e->getMessage();
}
1 change: 0 additions & 1 deletion src/MessageBird/Objects/PartnerAccount/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function loadToJson()
{
return json_encode([
'name' => $this->name,
'email' => $this->email,
]);
}

Expand Down
18 changes: 13 additions & 5 deletions src/MessageBird/Resources/PartnerAccount/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@ public function __construct(HttpClient $httpClient)

public function create($object, $query = null)
{

list($status, , $body) = $this->HttpClient->performHttpRequest(
list(, , $body) = $this->HttpClient->performHttpRequest(
HttpClient::REQUEST_POST,
self::RESOURCE_NAME,
null,
$object->loadToJson()
);

var_dump($status);
var_dump($body);

return $this->processRequest($body);
}

Expand All @@ -55,4 +51,16 @@ public function getList($parameters = [])

return $response;
}

public function update($object, $id)
{
list(, , $body) = $this->HttpClient->performHttpRequest(
HttpClient::REQUEST_PATCH,
sprintf('%s/%s', self::RESOURCE_NAME, $id),
null,
$object->loadToJson()
);

return $this->processRequest($body);
}
}
40 changes: 31 additions & 9 deletions tests/integration/partneraccount/AccountTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public function testCreateSubAccount()
{
$account = new \MessageBird\Objects\PartnerAccount\Account();
$account->name = 'MessageBird';
$account->email = '[email protected]';

$this->mockClient
->expects($this->atLeastOnce())
Expand Down Expand Up @@ -45,7 +44,7 @@ public function testCreateSubAccount()
'POST',
'child-accounts',
null,
'{"name":"MessageBird","email":"[email protected]"}'
'{"name":"MessageBird"}'
);

$response = $this->client->partnerAccounts->create($account);
Expand Down Expand Up @@ -131,23 +130,46 @@ public function testReadSubAccount()
public function testDeleteSubAccount()
{
$this->mockClient
->expects($this->atLeastOnce())
->expects($this->once())
->method('performHttpRequest')
->with(
'DELETE',
'child-accounts/1'
)
->willReturn([
204,
'',
''
]);

$response = $this->client->partnerAccounts->delete(1);

$this->assertTrue($response);
}

public function testEditSubAccount()
{
$account = new \MessageBird\Objects\PartnerAccount\Account();
$account->name = 'MessageBird';

$this->mockClient
->expects($this->once())
->method('performHttpRequest')
->with(
'DELETE',
'child-accounts/1'
);

$response = $this->client->partnerAccounts->delete(1);
'PATCH',
'child-accounts/1',
null,
'{"name":"MessageBird"}'
)
->willReturn([
204,
'',
'{
"id": 6249799,
"name": "Partner Account Sub 1"
}'
]);

$this->assertTrue($response);
$this->client->partnerAccounts->update($account,1);
}
}