Skip to content

Commit c940288

Browse files
authored
Merge pull request #15 from skn-036:v1.0
#17 resolved guzzleHttp request or response
2 parents f2d73d0 + 52cda38 commit c940288

File tree

11 files changed

+145
-60
lines changed

11 files changed

+145
-60
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "skn036/laravel-gmail-api",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Wrapper around gmail api for laravel.",
55
"keywords": [
66
"Muhammad Sajedul Karim",

src/Draft/GmailDraft.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
use Skn036\Gmail\Draft\Sendable\Draft;
55
use Skn036\Gmail\Gmail;
66
use Skn036\Gmail\Facades\Gmail as GmailFacade;
7+
use Skn036\Gmail\Helper\GmailHelpers;
78
use Skn036\Gmail\Message\GmailMessage;
89

910
class GmailDraft
1011
{
12+
use GmailHelpers;
13+
1114
/**
1215
* Draft from gmail
1316
* @var \Google_Service_Gmail_Draft
@@ -75,10 +78,18 @@ public function edit()
7578
public function send(array $optParams = [])
7679
{
7780
$service = $this->client->initiateService();
78-
$message = $service->users_drafts->send('me', $this->draft, $optParams);
81+
$message = $this->executeRequest(
82+
$service->users_drafts->send('me', $this->draft, $optParams),
83+
$this->client,
84+
'Google_Service_Gmail_Message'
85+
);
7986

8087
return new GmailMessage(
81-
$service->users_messages->get('me', $message->getId()),
88+
$this->executeRequest(
89+
$service->users_messages->get('me', $message->getId()),
90+
$this->client,
91+
'Google_Service_Gmail_Message'
92+
),
8293
$this->client
8394
);
8495
}
@@ -93,7 +104,10 @@ public function send(array $optParams = [])
93104
public function delete(array $optParams = [])
94105
{
95106
$service = $this->client->initiateService();
96-
$service->users_drafts->delete('me', $this->id, $optParams);
107+
$this->executeRequest(
108+
$service->users_drafts->delete('me', $this->id, $optParams),
109+
$this->client
110+
);
97111
}
98112

99113
/**

src/Draft/GmailDraftResponse.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
use Skn036\Gmail\Draft\Sendable\Draft;
77
use Skn036\Gmail\Facades\Gmail as GmailFacade;
88
use Skn036\Gmail\Exceptions\TokenNotValidException;
9+
use Skn036\Gmail\Helper\GmailHelpers;
910

1011
class GmailDraftResponse extends GmailFilter
1112
{
13+
use GmailHelpers;
14+
1215
/**
1316
* Gmail Client
1417
* @var Gmail|GmailFacade
@@ -114,7 +117,8 @@ public function edit(GmailDraft|string $draftOrDraftId)
114117
public function delete(GmailDraft|string $draftOrDraftId, array $optParams = [])
115118
{
116119
$draftId = $draftOrDraftId instanceof GmailDraft ? $draftOrDraftId->id : $draftOrDraftId;
117-
$this->service->users_drafts->delete('me', $draftId, $optParams);
120+
$responseOrRequest = $this->service->users_drafts->delete('me', $draftId, $optParams);
121+
$this->executeRequest($responseOrRequest, $this->client);
118122
}
119123

120124
/**
@@ -128,14 +132,11 @@ public function delete(GmailDraft|string $draftOrDraftId, array $optParams = [])
128132
protected function getGmailDraftListResponse($optParams = [])
129133
{
130134
$responseOrRequest = $this->service->users_drafts->listUsersDrafts('me', $optParams);
131-
132-
if (get_class($responseOrRequest) === 'GuzzleHttp\Psr7\Request') {
133-
$responseOrRequest = $this->service
134-
->getClient()
135-
->execute($responseOrRequest, 'Google_Service_Gmail_ListDraftsResponse');
136-
}
137-
138-
return $responseOrRequest;
135+
return $this->executeRequest(
136+
$responseOrRequest,
137+
$this->client,
138+
'Google_Service_Gmail_ListDraftsResponse'
139+
);
139140
}
140141

141142
/**

src/Label/GmailLabelResponse.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ public function list(array $optParams = [])
7070
*/
7171
public function get(string $labelId, array $optParams = [])
7272
{
73-
$label = $this->service->users_labels->get('me', $labelId, $optParams);
73+
$responseOrRequest = $this->service->users_labels->get('me', $labelId, $optParams);
74+
$label = $this->executeRequest(
75+
$responseOrRequest,
76+
$this->client,
77+
'Google_Service_Gmail_Label'
78+
);
7479
return new GmailLabel($label);
7580
}
7681

@@ -184,12 +189,7 @@ protected function getGmailLabelListResponse($optParams = [])
184189
*/
185190
protected function getGmailLabelResponse($id)
186191
{
187-
$responseOrRequest = $this->service->users_labels->get('me', $id);
188-
return $this->executeRequest(
189-
$responseOrRequest,
190-
$this->client,
191-
'Google_Service_Gmail_Label'
192-
);
192+
return $this->service->users_labels->get('me', $id);
193193
}
194194

195195
/**

src/Message/GmailMessage.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
use Illuminate\Support\Carbon;
55
use Illuminate\Support\Collection;
66
use Skn036\Gmail\Draft\Sendable\Draft;
7+
use Skn036\Gmail\Helper\GmailHelpers;
78
use Skn036\Gmail\Message\Sendable\Email;
89
use Skn036\Gmail\Message\Traits\ExtractMessage;
910
use Skn036\Gmail\Gmail;
1011
use Skn036\Gmail\Facades\Gmail as GmailFacade;
1112

1213
class GmailMessage
1314
{
14-
use ExtractMessage;
15+
use ExtractMessage, GmailHelpers;
1516

1617
/**
1718
* Message from gmail
@@ -323,7 +324,11 @@ public function modifyLabels(
323324
}
324325

325326
$service = $this->client->initiateService();
326-
$message = $service->users_messages->modify('me', $this->id, $modify, $optParams);
327+
$message = $this->executeRequest(
328+
$service->users_messages->modify('me', $this->id, $modify, $optParams),
329+
$this->client,
330+
'Google_Service_Gmail_Message'
331+
);
327332
$this->setLabels($message->getLabelIds());
328333

329334
return $this;
@@ -365,7 +370,11 @@ public function removeLabels(array|string $labelIds = [], array $optParams = [])
365370
public function trash($optParams = [])
366371
{
367372
$service = $this->client->initiateService();
368-
$message = $service->users_messages->trash('me', $this->id, $optParams);
373+
$message = $this->executeRequest(
374+
$service->users_messages->trash('me', $this->id, $optParams),
375+
$this->client,
376+
'Google_Service_Gmail_Message'
377+
);
369378
$this->setLabels($message->getLabelIds());
370379
return $this;
371380
}
@@ -380,7 +389,11 @@ public function trash($optParams = [])
380389
public function untrash($optParams = [])
381390
{
382391
$service = $this->client->initiateService();
383-
$message = $service->users_messages->untrash('me', $this->id, $optParams);
392+
$message = $this->executeRequest(
393+
$service->users_messages->untrash('me', $this->id, $optParams),
394+
$this->client,
395+
'Google_Service_Gmail_Message'
396+
);
384397
$this->setLabels($message->getLabelIds());
385398
return $this;
386399
}
@@ -397,7 +410,10 @@ public function untrash($optParams = [])
397410
public function delete($optParams = [])
398411
{
399412
$service = $this->client->initiateService();
400-
$service->users_messages->delete('me', $this->id, $optParams);
413+
$this->executeRequest(
414+
$service->users_messages->delete('me', $this->id, $optParams),
415+
$this->client
416+
);
401417
}
402418

403419
/**

src/Message/GmailMessageAttachment.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
use Illuminate\Support\Facades\File;
66
use Illuminate\Support\Facades\Storage;
77
use Skn036\Gmail\Facades\Gmail as GmailFacade;
8+
use Skn036\Gmail\Helper\GmailHelpers;
89

910
class GmailMessageAttachment
1011
{
12+
use GmailHelpers;
13+
1114
/**
1215
* Attachment MessagePart or id of the attachment
1316
* @var \Google_Service_Gmail_MessagePart
@@ -110,12 +113,17 @@ public function getData(array $optParams = [])
110113
}
111114

112115
$service = $this->client->initiateService();
113-
$part = $service->users_messages_attachments->get(
114-
'me',
115-
$this->messageId,
116-
$this->id,
117-
$optParams
116+
$part = $this->executeRequest(
117+
$service->users_messages_attachments->get(
118+
'me',
119+
$this->messageId,
120+
$this->id,
121+
$optParams
122+
),
123+
$this->client,
124+
'Google_Service_Gmail_MessagePart'
118125
);
126+
119127
if ($part->data) {
120128
$this->data = $part->data;
121129
}

src/Message/GmailMessageResponse.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
use Illuminate\Support\Collection;
66
use Skn036\Gmail\Filters\GmailFilter;
77
use Skn036\Gmail\Draft\Sendable\Draft;
8+
use Skn036\Gmail\Helper\GmailHelpers;
89
use Skn036\Gmail\Message\Sendable\Email;
910
use Skn036\Gmail\Facades\Gmail as GmailFacade;
1011
use Skn036\Gmail\Exceptions\TokenNotValidException;
1112

1213
class GmailMessageResponse extends GmailFilter
1314
{
15+
use GmailHelpers;
16+
1417
/**
1518
* Gmail Client
1619
* @var Gmail|GmailFacade
@@ -78,7 +81,11 @@ public function next()
7881
*/
7982
public function get(string $id)
8083
{
81-
$message = $this->getGmailMessageResponse($id);
84+
$message = $this->executeRequest(
85+
$this->getGmailMessageResponse($id),
86+
$this->client,
87+
'Google_Service_Gmail_Message'
88+
);
8289
return new GmailMessage($message, $this->client);
8390
}
8491

@@ -303,7 +310,10 @@ public function batchModifyLabels(
303310
$batchModifyRequest->setAddLabelIds($addLabelIds);
304311
$batchModifyRequest->setRemoveLabelIds($removeLabelIds);
305312

306-
return $this->service->users_messages->batchModify('me', $batchModifyRequest, $optParams);
313+
return $this->executeRequest(
314+
$this->service->users_messages->batchModify('me', $batchModifyRequest, $optParams),
315+
$this->client
316+
);
307317
}
308318

309319
/**
@@ -355,7 +365,10 @@ public function batchDelete(Collection|array $messagesOrMessageIds, array $optPa
355365
$batchDeleteRequest = new \Google_Service_Gmail_BatchDeleteMessagesRequest();
356366
$batchDeleteRequest->setIds($messageIds);
357367

358-
return $this->service->users_messages->batchDelete('me', $batchDeleteRequest, $optParams);
368+
return $this->executeRequest(
369+
$this->service->users_messages->batchDelete('me', $batchDeleteRequest, $optParams),
370+
$this->client
371+
);
359372
}
360373

361374
/**
@@ -368,15 +381,11 @@ public function batchDelete(Collection|array $messagesOrMessageIds, array $optPa
368381
*/
369382
protected function getGmailMessageListResponse($optParams = [])
370383
{
371-
$responseOrRequest = $this->service->users_messages->listUsersMessages('me', $optParams);
372-
373-
if (get_class($responseOrRequest) === 'GuzzleHttp\Psr7\Request') {
374-
$responseOrRequest = $this->service
375-
->getClient()
376-
->execute($responseOrRequest, 'Google_Service_Gmail_ListMessagesResponse');
377-
}
378-
379-
return $responseOrRequest;
384+
return $this->executeRequest(
385+
$this->service->users_messages->listUsersMessages('me', $optParams),
386+
$this->client,
387+
'Google_Service_Gmail_ListMessagesResponse'
388+
);
380389
}
381390

382391
/**

src/Message/Sendable/Email.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33

44
use Skn036\Gmail\Gmail;
55
use Skn036\Gmail\Facades\Gmail as GmailFacade;
6+
use Skn036\Gmail\Helper\GmailHelpers;
67
use Skn036\Gmail\Message\GmailMessage;
78
use Skn036\Gmail\Message\GmailMessageResponse;
89

910
class Email extends Sendable
1011
{
12+
use GmailHelpers;
13+
1114
/**
1215
* Summary of __construct
1316
*
@@ -31,7 +34,11 @@ public function send(array $optParams = [])
3134
$postBody = $this->setGmailMessageBody();
3235
$service = $this->client->initiateService();
3336

34-
$message = $service->users_messages->send('me', $postBody, $optParams);
37+
$message = $this->executeRequest(
38+
$service->users_messages->send('me', $postBody, $optParams),
39+
$this->client,
40+
'Google_Service_Gmail_Message'
41+
);
3542
return (new GmailMessageResponse($this->client))->get($message->getId());
3643
}
3744

0 commit comments

Comments
 (0)