-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathTempMailSo.php
More file actions
113 lines (95 loc) · 2.83 KB
/
Copy pathTempMailSo.php
File metadata and controls
113 lines (95 loc) · 2.83 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* TempMailAPI SDK
*
* This PHP SDK provides methods to interact with the TempMail.so API.
* Features include managing temporary email inboxes, retrieving mails,
* and performing actions such as inbox or mail deletion.
*
* Usage:
* - Initialize the class with your RapidAPI key and authentication token.
* - Call the provided methods to utilize TempMail.so API functionalities.
*
* Note: Replace `YOUR_RAPIDAPI_KEY` and `YOUR_AUTH_TOKEN` with your actual credentials.
*
* Author: TempMail.so
* License: TempMail.so
*/
class TempMailAPI
{
private $apiKey;
private $authToken;
private $baseUrl = 'https://tempmail-so.p.rapidapi.com';
public function __construct($apiKey, $authToken)
{
$this->apiKey = $apiKey;
$this->authToken = $authToken;
}
private function request($method, $endpoint, $data = null)
{
$url = $this->baseUrl . $endpoint;
$headers = [
'x-rapidapi-key: ' . $this->apiKey,
'Authorization: Bearer ' . $this->authToken,
'Content-Type: application/json'
];
$options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers
];
if ($data) {
$options[CURLOPT_POSTFIELDS] = json_encode($data);
}
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
if ($error) {
throw new Exception('Request Error: ' . $error);
}
return json_decode($response, true);
}
// Get available domains
public function listDomains()
{
return $this->request('GET', '/domains');
}
// Create a new inbox
public function createInbox($name, $domain, $lifespan)
{
$data = [
'name' => $name,
'domain' => $domain,
'lifespan' => $lifespan
];
return $this->request('POST', '/inboxes', $data);
}
// Retrieve all inboxes
public function listInboxes()
{
return $this->request('GET', '/inboxes');
}
// Delete an inbox
public function deleteInbox($inboxId)
{
return $this->request('DELETE', '/inboxes/' . $inboxId);
}
// Get the list of mails in an inbox
public function listMails($inboxId)
{
return $this->request('GET', '/inboxes/' . $inboxId . '/mails');
}
// Retrieve details of a specific mail
public function getMail($inboxId, $mailId)
{
return $this->request('GET', '/inboxes/' . $inboxId . '/mails/' . $mailId);
}
// Delete a mail
public function deleteMail($inboxId, $mailId)
{
return $this->request('DELETE', '/inboxes/' . $inboxId . '/mails/' . $mailId);
}
}
?>