55use GuzzleHttp \Client ;
66use GuzzleHttp \Psr7 \Response ;
77use function GuzzleHttp \Psr7 \stream_for ;
8+ use Psr \Http \Message \ResponseInterface ;
89
910class IntercomClient {
1011
@@ -47,6 +48,11 @@ class IntercomClient {
4748 /** @var IntercomBulk $bulk */
4849 public $ bulk ;
4950
51+ /**
52+ * IntercomClient constructor.
53+ * @param string $usernamePart App ID.
54+ * @param string $passwordPart Api Key.
55+ */
5056 public function __construct ($ usernamePart , $ passwordPart )
5157 {
5258 $ this ->setDefaultClient ();
@@ -70,11 +76,21 @@ private function setDefaultClient()
7076 $ this ->http_client = new Client ();
7177 }
7278
79+ /**
80+ * Sets GuzzleHttp client.
81+ * @param Client $client
82+ */
7383 public function setClient ($ client )
7484 {
7585 $ this ->http_client = $ client ;
7686 }
7787
88+ /**
89+ * Sends POST request to Intercom API.
90+ * @param string $endpoint
91+ * @param string $json
92+ * @return mixed
93+ */
7894 public function post ($ endpoint , $ json )
7995 {
8096 $ response = $ this ->http_client ->request ('POST ' , "https://api.intercom.io/ $ endpoint " , [
@@ -87,6 +103,12 @@ public function post($endpoint, $json)
87103 return $ this ->handleResponse ($ response );
88104 }
89105
106+ /**
107+ * Sends DELETE request to Intercom API.
108+ * @param string $endpoint
109+ * @param string $json
110+ * @return mixed
111+ */
90112 public function delete ($ endpoint , $ json )
91113 {
92114 $ response = $ this ->http_client ->request ('DELETE ' , "https://api.intercom.io/ $ endpoint " , [
@@ -99,6 +121,11 @@ public function delete($endpoint, $json)
99121 return $ this ->handleResponse ($ response );
100122 }
101123
124+ /**
125+ * @param string $endpoint
126+ * @param string $query
127+ * @return mixed
128+ */
102129 public function get ($ endpoint , $ query )
103130 {
104131 $ response = $ this ->http_client ->request ('GET ' , "https://api.intercom.io/ $ endpoint " , [
@@ -111,6 +138,11 @@ public function get($endpoint, $query)
111138 return $ this ->handleResponse ($ response );
112139 }
113140
141+ /**
142+ * Returns next page of the result.
143+ * @param array $pages
144+ * @return mixed
145+ */
114146 public function nextPage ($ pages )
115147 {
116148 $ response = $ this ->http_client ->request ('GET ' , $ pages ['next ' ], [
@@ -122,11 +154,19 @@ public function nextPage($pages)
122154 return $ this ->handleResponse ($ response );
123155 }
124156
157+ /**
158+ * Returns authentication parameters.
159+ * @return array
160+ */
125161 public function getAuth ()
126162 {
127163 return [$ this ->usernamePart , $ this ->passwordPart ];
128164 }
129165
166+ /**
167+ * @param Response $response
168+ * @return mixed
169+ */
130170 private function handleResponse (Response $ response ){
131171 $ stream = stream_for ($ response ->getBody ());
132172 $ data = json_decode ($ stream ->getContents ());
0 commit comments