-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathprojects.php
More file actions
98 lines (75 loc) · 2.49 KB
/
projects.php
File metadata and controls
98 lines (75 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
use Mailtrap\Config;
use Mailtrap\Helper\ResponseHelper;
use Mailtrap\MailtrapSandboxClient;
require __DIR__ . '/../../vendor/autoload.php';
$accountId = $_ENV['MAILTRAP_ACCOUNT_ID'];
$config = new Config($_ENV['MAILTRAP_API_KEY']); #your API token from here https://mailtrap.io/api-tokens
$sandboxProjects = (new MailtrapSandboxClient($config))->projects($accountId); #required parameter is accountId
/**
* List projects and their inboxes to which the API token has access.
*
* GET https://mailtrap.io/api/accounts/{account_id}/projects
*/
try {
$response = $sandboxProjects->getList();
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Get the project and its inboxes.
*
* GET https://mailtrap.io/api/accounts/{account_id}/projects/{project_id}
*/
try {
$projectId = $_ENV['MAILTRAP_PROJECT_ID'];
$response = $sandboxProjects->getById($projectId);
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Create project
* The project name is min 2 characters and max 100 characters long.
*
* POST https://mailtrap.io/api/accounts/{account_id}/projects
*/
try {
$projectName = 'Some project name';
$response = $sandboxProjects->create($projectName);
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Update project
* The project name is min 2 characters and max 100 characters long.
*
* PATCH https://mailtrap.io/api/accounts/{account_id}/projects/{project_id}
*/
try {
$projectId = $_ENV['MAILTRAP_PROJECT_ID'];
$newProjectName = 'New project name';
$response = $sandboxProjects->updateName($projectId, $newProjectName);
// print the response body (array)
var_dump(ResponseHelper::toArray($response));
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
/**
* Delete project and its inboxes.
*
* DELETE https://mailtrap.io/api/accounts/{account_id}/projects/{project_id}
*/
try {
$projectId = $_ENV['MAILTRAP_PROJECT_ID'];
$response = $sandboxProjects->delete($projectId);
// Print the response status code
var_dump($response->getStatusCode());
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}