@@ -18,6 +18,9 @@ class IntercomClient
1818 /** @var string API password authentication */
1919 protected $ passwordPart ;
2020
21+ /** @var string Extra Guzzle Requests Options */
22+ protected $ extraGuzzleRequestsOptions ;
23+
2124 /** @var IntercomUsers $users */
2225 public $ users ;
2326
@@ -62,7 +65,7 @@ class IntercomClient
6265 * @param string $usernamePart App ID.
6366 * @param string $passwordPart Api Key.
6467 */
65- public function __construct ($ usernamePart , $ passwordPart )
68+ public function __construct ($ usernamePart , $ passwordPart, $ extraGuzzleRequestsOptions = [] )
6669 {
6770 $ this ->setDefaultClient ();
6871 $ this ->users = new IntercomUsers ($ this );
@@ -81,6 +84,7 @@ public function __construct($usernamePart, $passwordPart)
8184
8285 $ this ->usernamePart = $ usernamePart ;
8386 $ this ->passwordPart = $ passwordPart ;
87+ $ this ->extraGuzzleRequestsOptions = $ extraGuzzleRequestsOptions ;
8488 }
8589
8690 private function setDefaultClient ()
@@ -106,13 +110,14 @@ public function setClient($client)
106110 */
107111 public function post ($ endpoint , $ json )
108112 {
109- $ response = $ this ->http_client -> request ( ' POST ' , " https://api.intercom.io/ $ endpoint " , [
113+ $ guzzleRequestOptions = $ this ->getGuzzleRequestOptions ( [
110114 'json ' => $ json ,
111115 'auth ' => $ this ->getAuth (),
112116 'headers ' => [
113117 'Accept ' => 'application/json '
114- ]
118+ ],
115119 ]);
120+ $ response = $ this ->http_client ->request ('POST ' , "https://api.intercom.io/ $ endpoint " , $ guzzleRequestOptions );
116121 return $ this ->handleResponse ($ response );
117122 }
118123
@@ -125,13 +130,15 @@ public function post($endpoint, $json)
125130 */
126131 public function put ($ endpoint , $ json )
127132 {
128- $ response = $ this ->http_client -> request ( ' PUT ' , " https://api.intercom.io/ $ endpoint " , [
133+ $ guzzleRequestOptions = $ this ->getGuzzleRequestOptions ( [
129134 'json ' => $ json ,
130135 'auth ' => $ this ->getAuth (),
131136 'headers ' => [
132137 'Accept ' => 'application/json '
133- ]
138+ ],
134139 ]);
140+
141+ $ response = $ this ->http_client ->request ('PUT ' , "https://api.intercom.io/ $ endpoint " , $ guzzleRequestOptions );
135142 return $ this ->handleResponse ($ response );
136143 }
137144
@@ -144,13 +151,15 @@ public function put($endpoint, $json)
144151 */
145152 public function delete ($ endpoint , $ json )
146153 {
147- $ response = $ this ->http_client -> request ( ' DELETE ' , " https://api.intercom.io/ $ endpoint " , [
154+ $ guzzleRequestOptions = $ this ->getGuzzleRequestOptions ( [
148155 'json ' => $ json ,
149156 'auth ' => $ this ->getAuth (),
150157 'headers ' => [
151158 'Accept ' => 'application/json '
152- ]
159+ ],
153160 ]);
161+
162+ $ response = $ this ->http_client ->request ('DELETE ' , "https://api.intercom.io/ $ endpoint " , $ guzzleRequestOptions );
154163 return $ this ->handleResponse ($ response );
155164 }
156165
@@ -162,13 +171,15 @@ public function delete($endpoint, $json)
162171 */
163172 public function get ($ endpoint , $ query )
164173 {
165- $ response = $ this ->http_client -> request ( ' GET ' , " https://api.intercom.io/ $ endpoint " , [
174+ $ guzzleRequestOptions = $ this ->getGuzzleRequestOptions ( [
166175 'query ' => $ query ,
167176 'auth ' => $ this ->getAuth (),
168177 'headers ' => [
169178 'Accept ' => 'application/json '
170- ]
179+ ],
171180 ]);
181+
182+ $ response = $ this ->http_client ->request ('GET ' , "https://api.intercom.io/ $ endpoint " , $ guzzleRequestOptions );
172183 return $ this ->handleResponse ($ response );
173184 }
174185
@@ -180,15 +191,27 @@ public function get($endpoint, $query)
180191 */
181192 public function nextPage ($ pages )
182193 {
183- $ response = $ this ->http_client -> request ( ' GET ' , $ pages -> next , [
194+ $ guzzleRequestOptions = $ this ->getGuzzleRequestOptions ( [
184195 'auth ' => $ this ->getAuth (),
185196 'headers ' => [
186197 'Accept ' => 'application/json '
187- ]
198+ ],
188199 ]);
200+
201+ $ response = $ this ->http_client ->request ('GET ' , $ pages ->next , $ guzzleRequestOptions );
189202 return $ this ->handleResponse ($ response );
190203 }
191204
205+ /**
206+ * Returns Guzzle Requests Options Array
207+ * @param array $defaultGuzzleRequestsOptions
208+ * @return array
209+ */
210+ public function getGuzzleRequestOptions ($ defaultGuzzleRequestOptions = [])
211+ {
212+ return array_replace_recursive ($ this ->extraGuzzleRequestsOptions , $ defaultGuzzleRequestOptions );
213+ }
214+
192215 /**
193216 * Returns authentication parameters.
194217 * @return array
0 commit comments