Skip to content

Commit

Permalink
config/main: updating postman collection; updating namings
Browse files Browse the repository at this point in the history
  • Loading branch information
2amjsouza committed Aug 9, 2023
1 parent a90985b commit 7b3ddce
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 76 deletions.
98 changes: 34 additions & 64 deletions Laravel Mail API.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,102 +1,69 @@
{
"info": {
"_postman_id": "8d2587b3-f023-4ff7-b784-0b6711606aa7",
"_postman_id": "9982cd7f-bcde-4667-a8ef-c09f3f37ed1b",
"name": "Laravel Mail API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "1948434"
},
"item": [
{
"name": "Token",
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "",
"type": "string"
},
{
"key": "username",
"value": "",
"type": "string"
}
]
},
"method": "POST",
"header": [],
"body": {
"mode": "raw",
"raw": "",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8000/api/token",
"protocol": "http",
"host": [
"localhost"
],
"port": "8000",
"path": [
"api",
"token"
]
}
},
"response": []
},
{
"name": "Send Message",
"name": "send-email",
"request": {
"auth": {
"type": "bearer",
"bearer": [
{
"key": "token",
"value": "",
"value": "45b410909034b8f7266cc88a6819174cbeef2079fb2e4fe67a57586af4abec2b",
"type": "string"
}
]
},
"method": "POST",
"header": [],
"header": [
{
"key": "accessKey",
"value": "access-key-user-1",
"type": "text"
},
{
"key": "ts",
"value": "2023-08-09T17:13:58+00:00",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "from",
"value": "user@email.com",
"value": "contato@newenglishbr.com",
"type": "text"
},
{
"key": "sender",
"value": "Test user",
"key": "to",
"value": "[email protected]",
"type": "text"
},
{
"key": "to",
"value": "[email protected]",
"key": "sender",
"value": "New English",
"type": "text"
},
{
"key": "receiver",
"value": "Test user",
"value": "Jonatas S.",
"type": "text"
},
{
"key": "subject",
"value": "testing api",
"value": "test api",
"type": "text"
},
{
"key": "attachments[]",
"type": "file",
"src": [],
"key": "template",
"value": "password",
"type": "text",
"disabled": true
},
{
Expand All @@ -106,23 +73,26 @@
"disabled": true
},
{
"key": "template",
"value": "hello-world",
"type": "text",
"disabled": true
"key": "attachments[]",
"type": "file",
"src": [
"/C:/Users/jonat/Downloads/Sobremesa Lvtetia.pdf",
"/C:/Users/jonat/Downloads/MENU DO BAR VATICANO.pdf"
]
}
]
},
"url": {
"raw": "http://localhost:8000/api/send-message",
"raw": "http://localhost:8000/api/email/send",
"protocol": "http",
"host": [
"localhost"
],
"port": "8000",
"path": [
"api",
"send-message"
"email",
"send"
]
}
},
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Api/SendEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public function __invoke(Request $request): JsonResponse
{
$this->validateRequest($request);

$from = $request->input('from');
$fromEmail = $request->input('from');
$sender = $request->input('sender', '');
$to = $request->input('to');
$toEmail = $request->input('to');
$receiver = $request->input('receiver', '');
$subject = $request->input('subject', '');
$template = $request->input('template', config('laravel-mail-api.template'));
Expand All @@ -31,8 +31,8 @@ public function __invoke(Request $request): JsonResponse

Bus::chain([
new EmailDispatcher(
from: $from,
to: $to,
fromEmail: $fromEmail,
toEmail: $toEmail,
sender: $sender,
receiver: $receiver,
subject: $subject,
Expand Down
14 changes: 7 additions & 7 deletions app/Jobs/EmailDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,28 @@ class EmailDispatcher implements ShouldQueue, ShouldBeUnique

private Mailable $message;

private string $to;
private string $toEmail;

private ?string $receiver;

private ?string $language;

public $backoff = 3;

public function __construct(string $from, string $to, ?string $sender = '', ?string $receiver = '', ?string $subject = '', ?string $template = '', ?string $language = '', ?array $attachments = [])
public function __construct(string $fromEmail, string $toEmail, ?string $sender = '', ?string $receiver = '', ?string $subject = '', ?string $template = '', ?string $language = '', ?array $attachments = [])
{
Log::info('Queueing new massage', [
'to' => $to,
'from' => $from,
'to' => $toEmail,
'from' => $fromEmail,
'template' => $template,
]);

$this->to = $to;
$this->toEmail = $toEmail;
$this->receiver = $receiver;
$this->language = $language;

$this->message = new Message(
sender: ['address' => $from, 'name' => $sender],
sender: ['address' => $fromEmail, 'name' => $sender],
subject: $subject,
template: $this->getTemplate($template),
attachments: $attachments,
Expand All @@ -50,7 +50,7 @@ public function __construct(string $from, string $to, ?string $sender = '', ?str

public function handle()
{
Mail::to($this->to, $this->receiver)
Mail::to($this->toEmail, $this->receiver)
->locale($this->getLanguage($this->language))
->send($this->message);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Providers/AuthorizationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AuthorizationProvider
public static function authorize(Request $request)
{
$accessKey = $request->headers->get('accessKey') ?? '';
$signedKey = $request->bearerToken();
$signedKey = $request->bearerToken() ?? '';
$timeStamp = $request->headers->get('ts') ?? '';

self::checkTokenExpired($timeStamp);
Expand Down

0 comments on commit 7b3ddce

Please sign in to comment.