Skip to content

Commit f75a887

Browse files
authored
Merge pull request #107 from felipecoppola/partner-account
Partner account
2 parents 29afe94 + e233ccf commit f75a887

File tree

5 files changed

+64
-16
lines changed

5 files changed

+64
-16
lines changed

examples/partner-account-create.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

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

1110
try {
1211
$partnerAccountResult = $messageBird->partnerAccounts->create($account);

examples/partner-account-update.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
require_once(__DIR__ . '/../autoload.php');
4+
5+
$messageBird = new \MessageBird\Client('YOUR_ACCESS_KEY'); // Set your own API access key here.
6+
7+
$account = new \MessageBird\Objects\PartnerAccount\Account();
8+
$account->name = 'Name Test';
9+
10+
try {
11+
$partnerAccountResult = $messageBird->partnerAccounts->update($account, 1);
12+
var_dump($partnerAccountResult);
13+
14+
} catch (\MessageBird\Exceptions\AuthenticateException $e) {
15+
// That means that your accessKey is unknown
16+
echo 'wrong login';
17+
18+
} catch (\Exception $e) {
19+
echo $e->getMessage();
20+
}

src/MessageBird/Objects/PartnerAccount/Account.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function loadToJson()
2020
{
2121
return json_encode([
2222
'name' => $this->name,
23-
'email' => $this->email,
2423
]);
2524
}
2625

src/MessageBird/Resources/PartnerAccount/Accounts.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,13 @@ public function __construct(HttpClient $httpClient)
2020

2121
public function create($object, $query = null)
2222
{
23-
24-
list($status, , $body) = $this->HttpClient->performHttpRequest(
23+
list(, , $body) = $this->HttpClient->performHttpRequest(
2524
HttpClient::REQUEST_POST,
2625
self::RESOURCE_NAME,
2726
null,
2827
$object->loadToJson()
2928
);
3029

31-
var_dump($status);
32-
var_dump($body);
33-
3430
return $this->processRequest($body);
3531
}
3632

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

5652
return $response;
5753
}
54+
55+
public function update($object, $id)
56+
{
57+
list(, , $body) = $this->HttpClient->performHttpRequest(
58+
HttpClient::REQUEST_PATCH,
59+
sprintf('%s/%s', self::RESOURCE_NAME, $id),
60+
null,
61+
$object->loadToJson()
62+
);
63+
64+
return $this->processRequest($body);
65+
}
5866
}

tests/integration/partneraccount/AccountTest.php

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public function testCreateSubAccount()
1212
{
1313
$account = new \MessageBird\Objects\PartnerAccount\Account();
1414
$account->name = 'MessageBird';
15-
$account->email = '[email protected]';
1615

1716
$this->mockClient
1817
->expects($this->atLeastOnce())
@@ -45,7 +44,7 @@ public function testCreateSubAccount()
4544
'POST',
4645
'child-accounts',
4746
null,
48-
'{"name":"MessageBird","email":"[email protected]"}'
47+
'{"name":"MessageBird"}'
4948
);
5049

5150
$response = $this->client->partnerAccounts->create($account);
@@ -131,23 +130,46 @@ public function testReadSubAccount()
131130
public function testDeleteSubAccount()
132131
{
133132
$this->mockClient
134-
->expects($this->atLeastOnce())
133+
->expects($this->once())
135134
->method('performHttpRequest')
135+
->with(
136+
'DELETE',
137+
'child-accounts/1'
138+
)
136139
->willReturn([
137140
204,
138141
'',
139142
''
140143
]);
144+
145+
$response = $this->client->partnerAccounts->delete(1);
146+
147+
$this->assertTrue($response);
148+
}
149+
150+
public function testEditSubAccount()
151+
{
152+
$account = new \MessageBird\Objects\PartnerAccount\Account();
153+
$account->name = 'MessageBird';
154+
141155
$this->mockClient
142156
->expects($this->once())
143157
->method('performHttpRequest')
144158
->with(
145-
'DELETE',
146-
'child-accounts/1'
147-
);
148-
149-
$response = $this->client->partnerAccounts->delete(1);
159+
'PATCH',
160+
'child-accounts/1',
161+
null,
162+
'{"name":"MessageBird"}'
163+
)
164+
->willReturn([
165+
204,
166+
'',
167+
'{
168+
"id": 6249799,
169+
"name": "Partner Account Sub 1"
170+
}'
171+
]);
150172

151-
$this->assertTrue($response);
173+
$this->client->partnerAccounts->update($account,1);
152174
}
153175
}

0 commit comments

Comments
 (0)