44use Skn036 \Gmail \Gmail ;
55use Skn036 \Gmail \Facades \Gmail as GmailFacade ;
66use Skn036 \Gmail \Exceptions \TokenNotValidException ;
7+ use Skn036 \Gmail \Helper \GmailHelpers ;
78
89class GmailLabelResponse
910{
11+ use GmailHelpers;
12+
1013 /**
1114 * Gmail Client
1215 * @var Gmail|GmailFacade
@@ -67,7 +70,13 @@ public function list(array $optParams = [])
6770 */
6871 public function get (string $ labelId , array $ optParams = [])
6972 {
70- $ 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+ );
79+
7180 return new GmailLabel ($ label );
7281 }
7382
@@ -91,7 +100,14 @@ public function get(string $labelId, array $optParams = [])
91100 public function create (array $ params , array $ optParams = [])
92101 {
93102 $ label = $ this ->paramsToLabelPayload ($ params );
94- $ createdLabel = $ this ->service ->users_labels ->create ('me ' , $ label , $ optParams );
103+
104+ $ responseOrRequest = $ this ->service ->users_labels ->create ('me ' , $ label , $ optParams );
105+ $ createdLabel = $ this ->executeRequest (
106+ $ responseOrRequest ,
107+ $ this ->client ,
108+ 'Google_Service_Gmail_Label '
109+ );
110+
95111 return $ this ->get ($ createdLabel ->getId ());
96112 }
97113
@@ -116,7 +132,19 @@ public function create(array $params, array $optParams = [])
116132 public function update (string $ labelId , array $ params , array $ optParams = [])
117133 {
118134 $ label = $ this ->paramsToLabelPayload ($ params );
119- $ updatedLabel = $ this ->service ->users_labels ->update ('me ' , $ labelId , $ label , $ optParams );
135+
136+ $ responseOrRequest = $ this ->service ->users_labels ->update (
137+ 'me ' ,
138+ $ labelId ,
139+ $ label ,
140+ $ optParams
141+ );
142+ $ updatedLabel = $ this ->executeRequest (
143+ $ responseOrRequest ,
144+ $ this ->client ,
145+ 'Google_Service_Gmail_Label '
146+ );
147+
120148 return $ this ->get ($ updatedLabel ->getId ());
121149 }
122150
@@ -132,28 +160,26 @@ public function update(string $labelId, array $params, array $optParams = [])
132160 */
133161 public function delete (string $ labelId , array $ optParams = [])
134162 {
135- $ this ->service ->users_labels ->delete ('me ' , $ labelId , $ optParams );
163+ $ responseOrRequest = $ this ->service ->users_labels ->delete ('me ' , $ labelId , $ optParams );
164+ $ this ->executeRequest ($ responseOrRequest , $ this ->client );
136165 }
137166
138167 /**
139168 * List labels request to gmail
140169 *
141170 * @param array $optParams
142171 *
143- * @return \Google_Service_Gmail_ListLabelsResponse|\GuzzleHttp\Psr7\Request
172+ * @return \Google_Service_Gmail_ListLabelsResponse
144173 * @throws \Google\Service\Exception
145174 */
146175 protected function getGmailLabelListResponse ($ optParams = [])
147176 {
148177 $ responseOrRequest = $ this ->service ->users_labels ->listUsersLabels ('me ' , $ optParams );
149-
150- if (get_class ($ responseOrRequest ) === 'GuzzleHttp\Psr7\Request ' ) {
151- $ responseOrRequest = $ this ->service
152- ->getClient ()
153- ->execute ($ responseOrRequest , 'Google_Service_Gmail_ListLabelsResponse ' );
154- }
155-
156- return $ responseOrRequest ;
178+ return $ this ->executeRequest (
179+ $ responseOrRequest ,
180+ $ this ->client ,
181+ 'Google_Service_Gmail_ListLabelsResponse '
182+ );
157183 }
158184
159185 /**
@@ -164,7 +190,12 @@ protected function getGmailLabelListResponse($optParams = [])
164190 */
165191 protected function getGmailLabelResponse ($ id )
166192 {
167- return $ this ->service ->users_labels ->get ('me ' , $ id );
193+ $ responseOrRequest = $ this ->service ->users_labels ->get ('me ' , $ id );
194+ return $ this ->executeRequest (
195+ $ responseOrRequest ,
196+ $ this ->client ,
197+ 'Google_Service_Gmail_Label '
198+ );
168199 }
169200
170201 /**
0 commit comments