From e25833a313d0bb1c86864e2f43292249ec422fdf Mon Sep 17 00:00:00 2001 From: jsklan Date: Tue, 7 Oct 2025 18:15:54 -0400 Subject: [PATCH 1/9] initial src file inclusion --- src/Legacy/IntercomAdmins.php | 48 +++ src/Legacy/IntercomBulk.php | 33 ++ src/Legacy/IntercomClient.php | 441 +++++++++++++++++++++++++++ src/Legacy/IntercomCompanies.php | 149 +++++++++ src/Legacy/IntercomContacts.php | 133 ++++++++ src/Legacy/IntercomConversations.php | 145 +++++++++ src/Legacy/IntercomCounts.php | 22 ++ src/Legacy/IntercomEvents.php | 35 +++ src/Legacy/IntercomLeads.php | 115 +++++++ src/Legacy/IntercomMessages.php | 22 ++ src/Legacy/IntercomNotes.php | 48 +++ src/Legacy/IntercomResource.php | 21 ++ src/Legacy/IntercomSegments.php | 36 +++ src/Legacy/IntercomTags.php | 35 +++ src/Legacy/IntercomTeams.php | 48 +++ src/Legacy/IntercomUsers.php | 129 ++++++++ src/Legacy/IntercomVisitors.php | 77 +++++ 17 files changed, 1537 insertions(+) create mode 100644 src/Legacy/IntercomAdmins.php create mode 100644 src/Legacy/IntercomBulk.php create mode 100644 src/Legacy/IntercomClient.php create mode 100644 src/Legacy/IntercomCompanies.php create mode 100644 src/Legacy/IntercomContacts.php create mode 100644 src/Legacy/IntercomConversations.php create mode 100644 src/Legacy/IntercomCounts.php create mode 100644 src/Legacy/IntercomEvents.php create mode 100644 src/Legacy/IntercomLeads.php create mode 100644 src/Legacy/IntercomMessages.php create mode 100644 src/Legacy/IntercomNotes.php create mode 100644 src/Legacy/IntercomResource.php create mode 100644 src/Legacy/IntercomSegments.php create mode 100644 src/Legacy/IntercomTags.php create mode 100644 src/Legacy/IntercomTeams.php create mode 100644 src/Legacy/IntercomUsers.php create mode 100644 src/Legacy/IntercomVisitors.php diff --git a/src/Legacy/IntercomAdmins.php b/src/Legacy/IntercomAdmins.php new file mode 100644 index 00000000..fc2b977e --- /dev/null +++ b/src/Legacy/IntercomAdmins.php @@ -0,0 +1,48 @@ +client->get("admins", $options); + } + + /** + * Gets a single Admin based on the Intercom ID. + * + * @see https://developers.intercom.com/v2.0/reference#view-an-admin + * @param integer $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getAdmin($id, $options = []) + { + $path = $this->adminPath($id); + return $this->client->get($path, $options); + } + + /** + * Returns endpoint path to Admin with given ID. + * + * @param string $id + * @return string + */ + public function adminPath($id) + { + return 'admins/' . $id; + } +} diff --git a/src/Legacy/IntercomBulk.php b/src/Legacy/IntercomBulk.php new file mode 100644 index 00000000..6f97d560 --- /dev/null +++ b/src/Legacy/IntercomBulk.php @@ -0,0 +1,33 @@ +client->post("bulk/users", $options); + } + + /** + * Creates Events in bulk. + * + * @param array $options + * @return stdClass + * @throws Exception + */ + public function events($options) + { + return $this->client->post("bulk/events", $options); + } +} diff --git a/src/Legacy/IntercomClient.php b/src/Legacy/IntercomClient.php new file mode 100644 index 00000000..b303b79d --- /dev/null +++ b/src/Legacy/IntercomClient.php @@ -0,0 +1,441 @@ +users = new IntercomUsers($this); + $this->contacts = new IntercomContacts($this); + $this->events = new IntercomEvents($this); + $this->companies = new IntercomCompanies($this); + $this->messages = new IntercomMessages($this); + $this->conversations = new IntercomConversations($this); + $this->leads = new IntercomLeads($this); + $this->visitors = new IntercomVisitors($this); + $this->admins = new IntercomAdmins($this); + $this->tags = new IntercomTags($this); + $this->segments = new IntercomSegments($this); + $this->counts = new IntercomCounts($this); + $this->bulk = new IntercomBulk($this); + $this->notes = new IntercomNotes($this); + $this->teams = new IntercomTeams($this); + + $this->appIdOrToken = $appIdOrToken; + $this->passwordPart = $password; + $this->extraRequestHeaders = $extraRequestHeaders; + + $this->httpClient = $this->getDefaultHttpClient(); + $this->requestFactory = Psr17FactoryDiscovery::findRequestFactory(); + $this->uriFactory = Psr17FactoryDiscovery::findUriFactory(); + $this->streamFactory = Psr17FactoryDiscovery::findStreamFactory(); + } + + /** + * Sets the HTTP client. + * + * @param ClientInterface $httpClient + */ + public function setHttpClient(ClientInterface $httpClient) + { + $this->httpClient = $httpClient; + } + + /** + * Sets the request factory. + * + * @param RequestFactoryInterface $requestFactory + */ + public function setRequestFactory(RequestFactoryInterface $requestFactory) + { + $this->requestFactory = $requestFactory; + } + + /** + * Sets the URI factory. + * + * @param UriFactoryInterface $uriFactory + */ + public function setUriFactory(UriFactoryInterface $uriFactory) + { + $this->uriFactory = $uriFactory; + } + + /** + * Sets the stream factory. + * + * @param StreamFactoryInterface $streamFactory + */ + public function setStreamFactory(StreamFactoryInterface $streamFactory) + { + $this->streamFactory = $streamFactory; + } + + /** + * Sends POST request to Intercom API. + * + * @param string $endpoint + * @param array $json + * @return stdClass + */ + public function post($endpoint, $json) + { + $response = $this->sendRequest('POST', "https://api.intercom.io/$endpoint", $json); + return $this->handleResponse($response); + } + + /** + * Sends PUT request to Intercom API. + * + * @param string $endpoint + * @param array $json + * @return stdClass + */ + public function put($endpoint, $json) + { + $response = $this->sendRequest('PUT', "https://api.intercom.io/$endpoint", $json); + return $this->handleResponse($response); + } + + /** + * Sends DELETE request to Intercom API. + * + * @param string $endpoint + * @param array $json + * @return stdClass + */ + public function delete($endpoint, $json) + { + $response = $this->sendRequest('DELETE', "https://api.intercom.io/$endpoint", $json); + return $this->handleResponse($response); + } + + /** + * Sends GET request to Intercom API. + * + * @param string $endpoint + * @param array $queryParams + * @return stdClass + */ + public function get($endpoint, $queryParams = []) + { + $uri = $this->uriFactory->createUri("https://api.intercom.io/$endpoint"); + if (!empty($queryParams)) { + $uri = $uri->withQuery(http_build_query($queryParams)); + } + + $response = $this->sendRequest('GET', $uri); + + return $this->handleResponse($response); + } + + /** + * Returns the next page of the result. + * + * @param stdClass $pages + * @return stdClass + */ + public function nextPage($pages) + { + $response = $this->sendRequest('GET', $pages->next); + return $this->handleResponse($response); + } + + /** + * Returns the next page of the result for a search query. + * + * @param string $path + * @param array $query + * @param stdClass $pages + * @return stdClass + */ + public function nextSearchPage(string $path, array $query, $pages) + { + $options = [ + "query" => $query, + "pagination" => [ + "per_page" => $pages->per_page, + "starting_after" => $pages->next->starting_after, + ] + ]; + return $this->post($path, $options); + } + + /** + * Returns the next page of the result for a cursor based search. + * + * @param string $path + * @param string $startingAfter + * @return stdClass + */ + public function nextCursorPage(string $path, string $startingAfter) + { + return $this->get($path . "?starting_after=" . $startingAfter); + } + + /** + * Gets the rate limit details. + * + * @return array + */ + public function getRateLimitDetails() + { + return $this->rateLimitDetails; + } + + /** + * @return ClientInterface + */ + private function getDefaultHttpClient() + { + return new PluginClient( + Psr18ClientDiscovery::find(), + [new ErrorPlugin()] + ); + } + + /** + * @return array + */ + private function getRequestHeaders() + { + return array_merge( + [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'User-Agent' => 'Intercom-PHP/' . self::SDK_VERSION, + ], + $this->extraRequestHeaders + ); + } + + /** + * Returns authentication parameters + * + * @return Authentication + */ + private function getAuth() + { + if (!empty($this->appIdOrToken) && !empty($this->passwordPart)) { + return new BasicAuth($this->appIdOrToken, $this->passwordPart); + } elseif (!empty($this->appIdOrToken)) { + return new Bearer($this->appIdOrToken); + } + return null; + } + + /** + * Authenticates a request object + * @param RequestInterface $request + * + * @return RequestInterface + */ + private function authenticateRequest(RequestInterface $request) + { + $auth = $this->getAuth(); + return $auth ? $auth->authenticate($request) : $request; + } + + /** + * @param string $method + * @param string|UriInterface $uri + * @param array|string|null $body + * + * @return ResponseInterface + * @throws ClientExceptionInterface + */ + private function sendRequest($method, $uri, $body = null) + { + $body = is_array($body) ? json_encode($body) : $body; + $request = $this->requestFactory + ->createRequest($method, $uri); + + if ($body !== null) { + $request = $request + ->withBody($this->streamFactory->createStream($body)); + } + + foreach ($this->getRequestHeaders() as $name => $value) { + $request = $request + ->withHeader($name, $value); + } + + $request = $this->authenticateRequest($request); + + return $this->httpClient->sendRequest($request); + } + + /** + * @param ResponseInterface $response + * + * @return stdClass + */ + private function handleResponse(ResponseInterface $response) + { + $this->setRateLimitDetails($response); + + $stream = $response->getBody()->getContents(); + + return json_decode($stream); + } + + /** + * @param ResponseInterface $response + */ + private function setRateLimitDetails(ResponseInterface $response) + { + $this->rateLimitDetails = [ + 'limit' => $response->hasHeader('X-RateLimit-Limit') + ? (int)$response->getHeader('X-RateLimit-Limit')[0] + : null, + 'remaining' => $response->hasHeader('X-RateLimit-Remaining') + ? (int)$response->getHeader('X-RateLimit-Remaining')[0] + : null, + 'reset_at' => $response->hasHeader('X-RateLimit-Reset') + ? (new \DateTimeImmutable())->setTimestamp((int)$response->getHeader('X-RateLimit-Reset')[0]) + : null, + ]; + } +} diff --git a/src/Legacy/IntercomCompanies.php b/src/Legacy/IntercomCompanies.php new file mode 100644 index 00000000..97290285 --- /dev/null +++ b/src/Legacy/IntercomCompanies.php @@ -0,0 +1,149 @@ +client->post("companies", $options); + } + + /** + * Updates a Company. + * + * @see https://developers.intercom.io/reference#create-or-update-company + * @param array $options + * @return stdClass + * @throws Exception + */ + public function update($options) + { + return $this->create($options); + } + + /** + * Attaches a Contact to a Company. + * + * @see https://developers.intercom.io/reference#attach-contact-to-company + * @param string $contactId + * @param string $companyId + * @param array $options + * @return stdClass + * @throws Exception + */ + public function attachContact(string $contactId, string $companyId, array $options = []) + { + $path = $this->companyAttachPath($contactId); + $options = array_merge($options, ["id" => $companyId]); + return $this->client->post($path, $options); + } + + /** + * Detaches a Contact from a Company. + * + * @see https://developers.intercom.io/reference#detach-contact-from-company + * @param string $contactId + * @param string $companyId + * @param array $options + * @return stdClass + * @throws Exception + */ + public function detachContact(string $contactId, string $companyId, array $options = []) + { + $path = $this->companyDetachPath($contactId, $companyId); + return $this->client->delete($path, $options); + } + + /** + * Returns list of Companies. + * + * @see https://developers.intercom.io/reference#list-companies + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getCompanies($options) + { + return $this->client->get("companies", $options); + } + + /** + * Gets a single Company based on the Intercom ID. + * + * @see https://developers.intercom.com/reference#view-a-company + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getCompany($id, $options = []) + { + $path = $this->companyPath($id); + return $this->client->get($path, $options); + } + + + /** + * Returns a list of Users belonging to a single Company based on the Intercom ID. + * + * @see https://developers.intercom.com/reference#list-company-users + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getCompanyUsers($id, $options = []) + { + $path = $this->companyUsersPath($id); + return $this->client->get($path, $options); + } + + /** + * @param string $id + * @return string + */ + public function companyPath($id) + { + return 'companies/' . $id; + } + + /** + * @param string $id + * @return string + */ + public function companyUsersPath($id) + { + return 'companies/' . $id . '/users'; + } + + /** + * @param string $contactId + * @return string + */ + public function companyAttachPath(string $contactId) + { + return 'contacts/' . $contactId . '/companies'; + } + + /** + * @param string $contactId + * @param string $companyId + * @return string + */ + public function companyDetachPath(string $contactId, string $companyId) + { + return 'contacts/' . $contactId . '/companies/' . $companyId; + } +} diff --git a/src/Legacy/IntercomContacts.php b/src/Legacy/IntercomContacts.php new file mode 100644 index 00000000..1f0de82e --- /dev/null +++ b/src/Legacy/IntercomContacts.php @@ -0,0 +1,133 @@ +client->post("contacts", $options); + } + + /** + * Updates a Contact. + * + * @see https://developers.intercom.com/intercom-api-reference/reference#update-contact + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function update(string $id, array $options) + { + $path = $this->contactPath($id); + return $this->client->put($path, $options); + } + + /** + * Lists Contacts. + * + * @see https://developers.intercom.com/intercom-api-reference/reference#list-contacts + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getContacts(array $options = []) + { + return $this->client->get('contacts', $options); + } + + /** + * Gets a single Contact based on the Intercom ID. + * + * @see https://developers.intercom.com/intercom-api-reference/reference#get-contact + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getContact(string $id, array $options = []) + { + $path = $this->contactPath($id); + return $this->client->get($path, $options); + } + + /** + * Permenently Deletes a single Contact based on the Intercom ID. + * + * @see https://developers.intercom.com/intercom-api-reference/reference#delete-contact + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function deleteContact(string $id, array $options = []) + { + $path = $this->contactPath($id); + return $this->client->delete($path, $options); + } + + /** + * Returns list of Contacts that match search query. + * + * @see https://developers.intercom.com/reference#search-for-contacts + * @param array $options + * @return stdClass + * @throws Exception + */ + public function search(array $options) + { + $path = 'contacts/search'; + return $this->client->post($path, $options); + } + + /** + * Returns next page of Contacts that match search query. + * + * @see https://developers.intercom.com/intercom-api-reference/reference#pagination-search + * @param array $query + * @param stdClass $pages + * @return stdClass + * @throws Exception + */ + public function nextSearch(array $query, $pages) + { + $path = 'contacts/search'; + return $this->client->nextSearchPage($path, $query, $pages); + } + + /** + * Returns next page of a Contacts list. + * + * @see https://developers.intercom.com/intercom-api-reference/reference#pagination + * @param stdClass $pages + * @return stdClass + * @throws Exception + */ + public function nextCursor($pages) + { + $path = 'contacts'; + $starting_after = $pages->next->starting_after; + return $this->client->nextCursorPage($path, $starting_after); + } + + /** + * @param string $id + * @return string + */ + public function contactPath(string $id) + { + return 'contacts/' . $id; + } +} diff --git a/src/Legacy/IntercomConversations.php b/src/Legacy/IntercomConversations.php new file mode 100644 index 00000000..e5f6de4a --- /dev/null +++ b/src/Legacy/IntercomConversations.php @@ -0,0 +1,145 @@ +client->post('conversations', $options); + } + + /** + * Returns list of Conversations. + * + * @see https://developers.intercom.io/reference#list-conversations + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getConversations($options) + { + return $this->client->get('conversations', $options); + } + + /** + * Returns single Conversation. + * + * @see https://developers.intercom.io/reference#get-a-single-conversation + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getConversation($id, $options = []) + { + $path = $this->conversationPath($id); + return $this->client->get($path, $options); + } + + /** + * Returns list of Conversations that match search query. + * + * @see https://developers.intercom.com/intercom-api-reference/reference#search-for-conversations + * @param array $options + * @return stdClass + * @throws Exception + */ + public function search(array $options) + { + $path = 'conversations/search'; + return $this->client->post($path, $options); + } + + /** + * Returns next page of Conversations that match search query. + * + * @see https://developers.intercom.com/intercom-api-reference/reference#pagination-search + * @param array $query + * @param stdClass $pages + * @return stdClass + * @throws Exception + */ + public function nextSearch(array $query, $pages) + { + $path = 'conversations/search'; + return $this->client->nextSearchPage($path, $query, $pages); + } + + /** + * Creates Conversation Reply to Conversation with given ID. + * + * @see https://developers.intercom.io/reference#replying-to-a-conversation + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function replyToConversation($id, $options) + { + $path = $this->conversationReplyPath($id); + return $this->client->post($path, $options); + } + + /** + * Creates Conversation Reply to last conversation. (no need to specify Conversation ID.) + * + * @see https://developers.intercom.io/reference#replying-to-users-last-conversation + * @param array $options + * @return stdClass + * @throws Exception + */ + public function replyToLastConversation($options) + { + $path = 'conversations/last/reply'; + return $this->client->post($path, $options); + } + + /** + * Marks a Conversation as read based on the given Conversation ID. + * + * @see https://developers.intercom.io/reference#marking-a-conversation-as-read + * @param string $id + * @return stdClass + * @throws Exception + */ + public function markConversationAsRead($id) + { + $path = $this->conversationPath($id); + $data = ['read' => true]; + return $this->client->put($path, $data); + } + + /** + * Returns endpoint path to Conversation with given ID. + * + * @param string $id + * @return string + */ + public function conversationPath($id) + { + return 'conversations/' . $id; + } + + /** + * Returns endpoint path to Conversation Reply for Conversation with given ID. + * + * @param string $id + * @return string + */ + public function conversationReplyPath($id) + { + return 'conversations/' . $id . '/reply'; + } +} diff --git a/src/Legacy/IntercomCounts.php b/src/Legacy/IntercomCounts.php new file mode 100644 index 00000000..440df671 --- /dev/null +++ b/src/Legacy/IntercomCounts.php @@ -0,0 +1,22 @@ +client->get("counts", $options); + } +} diff --git a/src/Legacy/IntercomEvents.php b/src/Legacy/IntercomEvents.php new file mode 100644 index 00000000..0edf024a --- /dev/null +++ b/src/Legacy/IntercomEvents.php @@ -0,0 +1,35 @@ +client->post("events", $options); + } + + /** + * Lists User Events. + * + * @see https://developers.intercom.io/reference#list-user-events + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getEvents($options) + { + return $this->client->get("events", array_merge(["type" => "user"], $options)); + } +} diff --git a/src/Legacy/IntercomLeads.php b/src/Legacy/IntercomLeads.php new file mode 100644 index 00000000..330ccd08 --- /dev/null +++ b/src/Legacy/IntercomLeads.php @@ -0,0 +1,115 @@ +client->post("contacts", $options); + } + + /** + * Creates Lead. + * + * @see https://developers.intercom.io/reference#create-lead + * @param array $options + * @return stdClass + * @throws Exception + */ + public function update($options) + { + return $this->create($options); + } + + /** + * Lists Leads. + * + * @see https://developers.intercom.io/reference#list-leads + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getLeads($options) + { + return $this->client->get("contacts", $options); + } + + /** + * Returns single Lead. + * + * @see https://developers.intercom.io/reference#view-a-lead + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getLead($id, $options = []) + { + $path = $this->leadPath($id); + return $this->client->get($path, $options); + } + + /** + * Deletes Lead. + * + * @see https://developers.intercom.io/reference#delete-a-lead + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function deleteLead($id, $options = []) + { + $path = $this->leadPath($id); + return $this->client->delete($path, $options); + } + + /** + * Converts Lead. + * + * @see https://developers.intercom.io/reference#convert-a-lead + * @param $options + * @return stdClass + * @throws Exception + */ + public function convertLead($options) + { + return $this->client->post("contacts/convert", $options); + } + + /** + * Returns endpoint path to Lead with given ID. + * + * @param string $id + * @return string + */ + public function leadPath($id) + { + return "contacts/" . $id; + } + + /** + * Gets a list of Leads through the contacts scroll API. + * + * @see https://developers.intercom.com/v2.0/reference#iterating-over-all-leads + * @param array $options + * @return stdClass + * @throws Exception + */ + public function scrollLeads($options = []) + { + return $this->client->get('contacts/scroll', $options); + } +} diff --git a/src/Legacy/IntercomMessages.php b/src/Legacy/IntercomMessages.php new file mode 100644 index 00000000..834d18e9 --- /dev/null +++ b/src/Legacy/IntercomMessages.php @@ -0,0 +1,22 @@ +client->post("messages", $options); + } +} diff --git a/src/Legacy/IntercomNotes.php b/src/Legacy/IntercomNotes.php new file mode 100644 index 00000000..f3f8dd42 --- /dev/null +++ b/src/Legacy/IntercomNotes.php @@ -0,0 +1,48 @@ +client->post("notes", $options); + } + + /** + * Lists Notes. + * + * @see https://developers.intercom.io/reference#list-notes-for-a-user + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getNotes($options) + { + return $this->client->get("notes", $options); + } + + /** + * Returns single Note. + * + * @see https://developers.intercom.io/reference#view-a-note + * @param string $id + * @return stdClass + * @throws Exception + */ + public function getNote($id) + { + return $this->client->get("notes/" . $id, []); + } +} diff --git a/src/Legacy/IntercomResource.php b/src/Legacy/IntercomResource.php new file mode 100644 index 00000000..5895ebfd --- /dev/null +++ b/src/Legacy/IntercomResource.php @@ -0,0 +1,21 @@ +client = $client; + } +} diff --git a/src/Legacy/IntercomSegments.php b/src/Legacy/IntercomSegments.php new file mode 100644 index 00000000..458fa160 --- /dev/null +++ b/src/Legacy/IntercomSegments.php @@ -0,0 +1,36 @@ +client->get('segments/' . $id, $options); + } + + /** + * Lists Segments. + * + * @see https://developers.intercom.com/reference#list-segments + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getSegments($options = []) + { + return $this->client->get("segments", $options); + } +} diff --git a/src/Legacy/IntercomTags.php b/src/Legacy/IntercomTags.php new file mode 100644 index 00000000..a9c30ad9 --- /dev/null +++ b/src/Legacy/IntercomTags.php @@ -0,0 +1,35 @@ +client->post("tags", $options); + } + + /** + * Lists Tags. + * + * @see https://developers.intercom.io/reference#list-tags-for-an-app + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getTags($options = []) + { + return $this->client->get("tags", $options); + } +} diff --git a/src/Legacy/IntercomTeams.php b/src/Legacy/IntercomTeams.php new file mode 100644 index 00000000..ed35060f --- /dev/null +++ b/src/Legacy/IntercomTeams.php @@ -0,0 +1,48 @@ +client->get("teams", $options); + } + + /** + * Gets a single Team based on the Intercom ID. + * + * @see https://developers.intercom.com/reference#view-a-team + * @param integer $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getTeam($id, $options = []) + { + $path = $this->teamPath($id); + return $this->client->get($path, $options); + } + + /** + * Returns endpoint path to Team with given ID. + * + * @param string $id + * @return string + */ + public function teamPath($id) + { + return 'teams/' . $id; + } +} diff --git a/src/Legacy/IntercomUsers.php b/src/Legacy/IntercomUsers.php new file mode 100644 index 00000000..27659673 --- /dev/null +++ b/src/Legacy/IntercomUsers.php @@ -0,0 +1,129 @@ +client->post("users", $options); + } + + /** + * Creates a User. + * + * @see https://developers.intercom.io/reference#create-or-update-user + * @param array $options + * @return stdClass + * @throws Exception + */ + public function update(array $options) + { + return $this->create($options); + } + + /** + * Lists Users. + * + * @see https://developers.intercom.io/reference#list-users + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getUsers(array $options) + { + return $this->client->get('users', $options); + } + + /** + * Gets a single User based on the Intercom ID. + * + * @see https://developers.intercom.com/reference#view-a-user + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getUser($id, $options = []) + { + $path = $this->userPath($id); + return $this->client->get($path, $options); + } + + /** + * Gets a list of Users through the user scroll API. + * + * @see https://developers.intercom.com/reference#iterating-over-all-users + * @param array $options + * @return stdClass + * @throws Exception + */ + public function scrollUsers(array $options = []) + { + return $this->client->get('users/scroll', $options); + } + + /** + * Deletes a single User based on the Intercom ID. + * + * @see https://developers.intercom.com/reference#archive-a-user + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function archiveUser(string $id, array $options = []) + { + $path = $this->userPath($id); + return $this->client->delete($path, $options); + } + + /** + * Deletes a single User based on the Intercom ID. + * + * @see https://developers.intercom.com/reference#archive-a-user + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function deleteUser(string $id, array $options = []) + { + return $this->archiveUser($id, $options); + } + + /** + * Permanently deletes a single User based on the Intercom ID. + * + * @see https://developers.intercom.com/reference#delete-users + * @param string $id + * @return stdClass + * @throws Exception + */ + public function permanentlyDeleteUser(string $id) + { + return $this->client->post('user_delete_requests', [ + 'intercom_user_id' => $id + ]); + } + + /** + * @param string $id + * @return string + */ + public function userPath(string $id) + { + return 'users/' . $id; + } +} diff --git a/src/Legacy/IntercomVisitors.php b/src/Legacy/IntercomVisitors.php new file mode 100644 index 00000000..d44f493f --- /dev/null +++ b/src/Legacy/IntercomVisitors.php @@ -0,0 +1,77 @@ +client->put("visitors", $options); + } + + + /** + * Returns single Visitor. + * + * @see https://developers.intercom.com/reference#view-a-visitor + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getVisitor($id, $options = []) + { + $path = $this->visitorPath($id); + return $this->client->get($path, $options); + } + + /** + * Deletes Visitor. + * + * @see https://developers.intercom.com/reference#delete-a-visitor + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function deleteVisitor($id, $options = []) + { + $path = $this->visitorPath($id); + return $this->client->delete($path, $options); + } + + /** + * Converts Visitor. + * + * @see https://developers.intercom.io/reference#convert-a-lead + * @param $options + * @return stdClass + * @throws Exception + */ + public function convertVisitor($options) + { + return $this->client->post("visitors/convert", $options); + } + + /** + * Returns endpoint path to Visitor with given ID. + * + * @param string $id + * @return string + */ + public function visitorPath($id) + { + return "visitors/" . $id; + } +} From f0c097f1f9ba16402d6122a856f1703d22bd5bf5 Mon Sep 17 00:00:00 2001 From: jsklan Date: Tue, 7 Oct 2025 18:38:03 -0400 Subject: [PATCH 2/9] add depts to composer.json --- .fernignore | 2 ++ composer.json | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/.fernignore b/.fernignore index 084a8ebb..ce0b2661 100644 --- a/.fernignore +++ b/.fernignore @@ -1 +1,3 @@ # Specify files that shouldn't be modified by Fern +src/Legacy +composer.json diff --git a/composer.json b/composer.json index e69df79e..22c1ba3e 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,12 @@ "require": { "php": "^8.1", "ext-json": "*", + "php-http/client-common": "^2.0", + "php-http/discovery": "^1.0", + "php-http/message": "^1.0", + "psr/http-client": "^1.0", + "psr/http-message": "^1.0 || ^2.0", + "nyholm/psr7": "^1.0", "guzzlehttp/guzzle": "^7.4" }, "require-dev": { From 012f89697fd9c44dae61b0cb8f7776cfa46bb5e5 Mon Sep 17 00:00:00 2001 From: jsklan Date: Tue, 7 Oct 2025 19:00:03 -0400 Subject: [PATCH 3/9] raw copy tests --- tests/Legacy/IntercomAdminsTest.php | 30 ++++ tests/Legacy/IntercomBulkTest.php | 24 ++++ tests/Legacy/IntercomClientTest.php | 157 +++++++++++++++++++++ tests/Legacy/IntercomCompaniesTest.php | 60 ++++++++ tests/Legacy/IntercomContactsTest.php | 82 +++++++++++ tests/Legacy/IntercomConversationsTest.php | 74 ++++++++++ tests/Legacy/IntercomCountsTest.php | 16 +++ tests/Legacy/IntercomEventsTest.php | 24 ++++ tests/Legacy/IntercomLeadsTest.php | 71 ++++++++++ tests/Legacy/IntercomMessagesTest.php | 16 +++ tests/Legacy/IntercomNotesTest.php | 32 +++++ tests/Legacy/IntercomSegmentsTest.php | 16 +++ tests/Legacy/IntercomTagsTest.php | 24 ++++ tests/Legacy/IntercomTeamsTest.php | 30 ++++ tests/Legacy/IntercomUsersTest.php | 56 ++++++++ tests/Legacy/IntercomVisitorsTest.php | 47 ++++++ tests/Legacy/TestCase.php | 21 +++ 17 files changed, 780 insertions(+) create mode 100644 tests/Legacy/IntercomAdminsTest.php create mode 100644 tests/Legacy/IntercomBulkTest.php create mode 100644 tests/Legacy/IntercomClientTest.php create mode 100644 tests/Legacy/IntercomCompaniesTest.php create mode 100644 tests/Legacy/IntercomContactsTest.php create mode 100644 tests/Legacy/IntercomConversationsTest.php create mode 100644 tests/Legacy/IntercomCountsTest.php create mode 100644 tests/Legacy/IntercomEventsTest.php create mode 100644 tests/Legacy/IntercomLeadsTest.php create mode 100644 tests/Legacy/IntercomMessagesTest.php create mode 100644 tests/Legacy/IntercomNotesTest.php create mode 100644 tests/Legacy/IntercomSegmentsTest.php create mode 100644 tests/Legacy/IntercomTagsTest.php create mode 100644 tests/Legacy/IntercomTeamsTest.php create mode 100644 tests/Legacy/IntercomUsersTest.php create mode 100644 tests/Legacy/IntercomVisitorsTest.php create mode 100644 tests/Legacy/TestCase.php diff --git a/tests/Legacy/IntercomAdminsTest.php b/tests/Legacy/IntercomAdminsTest.php new file mode 100644 index 00000000..89137993 --- /dev/null +++ b/tests/Legacy/IntercomAdminsTest.php @@ -0,0 +1,30 @@ +client->method('get')->willReturn('foo'); + + $users = new IntercomAdmins($this->client); + $this->assertSame('foo', $users->getAdmins()); + } + + public function testAdminsGet() + { + $this->client->method('get')->willReturn('foo'); + + $users = new IntercomAdmins($this->client); + $this->assertSame('foo', $users->getAdmin(1)); + } + + public function testAdminsGetPath() + { + $users = new IntercomAdmins($this->client); + $this->assertSame('admins/1', $users->adminPath(1)); + } +} diff --git a/tests/Legacy/IntercomBulkTest.php b/tests/Legacy/IntercomBulkTest.php new file mode 100644 index 00000000..97de766c --- /dev/null +++ b/tests/Legacy/IntercomBulkTest.php @@ -0,0 +1,24 @@ +client->method('post')->will($this->returnArgument(0)); + + $bulk = new IntercomBulk($this->client); + $this->assertSame('bulk/users', $bulk->users([])); + } + + public function testBulkEvents() + { + $this->client->method('post')->will($this->returnArgument(0)); + + $bulk = new IntercomBulk($this->client); + $this->assertSame('bulk/events', $bulk->events([])); + } +} diff --git a/tests/Legacy/IntercomClientTest.php b/tests/Legacy/IntercomClientTest.php new file mode 100644 index 00000000..f5a244c4 --- /dev/null +++ b/tests/Legacy/IntercomClientTest.php @@ -0,0 +1,157 @@ +addResponse( + new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}") + ); + + $client = new IntercomClient('u', 'p'); + $client->setHttpClient($httpClient); + + $client->users->create([ + 'email' => 'test@intercom.io' + ]); + + foreach ($httpClient->getRequests() as $request) { + $basic = $request->getHeaders()['Authorization'][0]; + $this->assertSame("Basic dTpw", $basic); + } + } + + public function testClientWithExtraHeaders() + { + $httpClient = new Client(); + $httpClient->addResponse( + new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}") + ); + + $client = new IntercomClient('u', 'p', ['Custom-Header' => 'value']); + $client->setHttpClient($httpClient); + + $client->users->create([ + 'email' => 'test@intercom.io' + ]); + + foreach ($httpClient->getRequests() as $request) { + $headers = $request->getHeaders(); + $this->assertSame('application/json', $headers['Accept'][0]); + $this->assertSame('application/json', $headers['Content-Type'][0]); + $this->assertSame('value', $headers['Custom-Header'][0]); + } + } + + public function testClientErrorHandling() + { + $httpClient = new Client(); + $httpClient->addResponse( + new Response(404) + ); + $httpClient = new PluginClient($httpClient, [new ErrorPlugin()]); + + $client = new IntercomClient('u', 'p'); + $client->setHttpClient($httpClient); + + $this->expectException(Exception::class); + $client->users->create([ + 'email' => 'test@intercom.io' + ]); + } + + public function testServerErrorHandling() + { + $httpClient = new Client(); + $httpClient->addResponse( + new Response(500) + ); + $httpClient = new PluginClient($httpClient, [new ErrorPlugin()]); + + $client = new IntercomClient('u', 'p'); + $client->setHttpClient($httpClient); + + $this->expectException(Exception::class); + $client->users->create([ + 'email' => 'test@intercom.io' + ]); + } + + public function testPaginationHelper() + { + $httpClient = new Client(); + $httpClient->addResponse( + new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}") + ); + + $client = new IntercomClient('u', 'p'); + $client->setHttpClient($httpClient); + + $pages = new stdClass; + $pages->next = 'https://foo.com'; + + $client->nextPage($pages); + + foreach ($httpClient->getRequests() as $request) { + $host = $request->getUri()->getHost(); + $this->assertSame("foo.com", $host); + } + } + + public function testRateLimitDetails() + { + date_default_timezone_set('UTC'); + $time = time() + 7; + + $httpClient = new Client(); + $httpClient->addResponse( + new Response( + 200, + [ + 'X-RateLimit-Limit' => '83', + 'X-RateLimit-Remaining' => '2', + 'X-RateLimit-Reset' => $time + ], + "{\"foo\":\"bar\"}" + ) + ); + + $client = new IntercomClient('u', 'p'); + $client->setHttpClient($httpClient); + + $client->users->create([ + 'email' => 'test@intercom.io' + ]); + + $rateLimitDetails = $client->getRateLimitDetails(); + $this->assertIsArray($rateLimitDetails); + $this->assertArrayHasKey('limit', $rateLimitDetails); + $this->assertArrayHasKey('remaining', $rateLimitDetails); + $this->assertArrayHasKey('reset_at', $rateLimitDetails); + $this->assertSame(83, $rateLimitDetails['limit']); + $this->assertSame(2, $rateLimitDetails['remaining']); + $this->assertSame( + (new DateTimeImmutable)->setTimestamp($time)->getTimestamp(), + $rateLimitDetails['reset_at']->getTimestamp() + ); + } +} diff --git a/tests/Legacy/IntercomCompaniesTest.php b/tests/Legacy/IntercomCompaniesTest.php new file mode 100644 index 00000000..7c3bd1d9 --- /dev/null +++ b/tests/Legacy/IntercomCompaniesTest.php @@ -0,0 +1,60 @@ +client->method('post')->willReturn('foo'); + + $companies = new IntercomCompanies($this->client); + $this->assertSame('foo', $companies->create([])); + } + + public function testCompanyUpdate() + { + $this->client->method('post')->willReturn('foo'); + + $companies = new IntercomCompanies($this->client); + $this->assertSame('foo', $companies->update([])); + } + + public function testCompanyGet() + { + $this->client->method('get')->willReturn('foo'); + + $companies = new IntercomCompanies($this->client); + $this->assertSame('foo', $companies->getCompanies([])); + } + + public function testCompanyPath() + { + $users = new IntercomCompanies($this->client); + $this->assertSame('companies/foo', $users->companyPath("foo")); + } + + public function testCompanyGetById() + { + $this->client->method('get')->willReturn('foo'); + + $users = new IntercomCompanies($this->client); + $this->assertSame('foo', $users->getCompany("foo")); + } + + public function testCompanyGetUsers() + { + $this->client->method('get')->willReturn('foo'); + + $companies = new IntercomCompanies($this->client); + $this->assertSame('foo', $companies->getCompanyUsers("foo")); + } + + public function testCompanyUsersPath() + { + $users = new IntercomCompanies($this->client); + $this->assertSame('companies/foo/users', $users->companyUsersPath("foo")); + } +} diff --git a/tests/Legacy/IntercomContactsTest.php b/tests/Legacy/IntercomContactsTest.php new file mode 100644 index 00000000..9d1578d5 --- /dev/null +++ b/tests/Legacy/IntercomContactsTest.php @@ -0,0 +1,82 @@ +client->method('post')->willReturn('foo'); + + $contacts = new IntercomContacts($this->client); + $this->assertSame('foo', $contacts->create([])); + } + + public function testContactUpdate() + { + $this->client->method('put')->willReturn('foo'); + + $contacts = new IntercomContacts($this->client); + $this->assertSame('foo', $contacts->update('', [])); + } + + public function testContactsGet() + { + $this->client->method('get')->willReturn('foo'); + + $contacts = new IntercomContacts($this->client); + $this->assertSame('foo', $contacts->getContacts([])); + } + + public function testContactGet() + { + $this->client->method('get')->willReturn('foo'); + + $contacts = new IntercomContacts($this->client); + $this->assertSame('foo', $contacts->getContact("123")); + } + + public function testContactDelete() + { + $this->client->method('delete')->willReturn('foo'); + + $contacts = new IntercomContacts($this->client); + $this->assertSame('foo', $contacts->deleteContact('')); + } + + public function testContactSearch() + { + $this->client->method('post')->willReturn('foo'); + + $contacts = new IntercomContacts($this->client); + $this->assertSame('foo', $contacts->search([])); + } + + public function testContactNextSearch() + { + $this->client->method('nextSearchPage')->willReturn('foo'); + $query = []; + $pages = new stdClass; + $pages->per_page = "10"; + $pages->next = new stdClass; + $pages->next->starting_after = "abc"; + + $contacts = new IntercomContacts($this->client); + $this->assertSame('foo', $contacts->nextSearch([], $pages)); + } + + public function testConversationNextCursor() + { + $this->client->method('nextCursorPage')->willReturn('foo'); + $query = []; + $pages = new stdClass; + $pages->next = new stdClass; + $pages->next->starting_after = "abc"; + + $contacts = new IntercomContacts($this->client); + $this->assertSame('foo', $contacts->nextCursor($pages)); + } +} diff --git a/tests/Legacy/IntercomConversationsTest.php b/tests/Legacy/IntercomConversationsTest.php new file mode 100644 index 00000000..00c8f9ea --- /dev/null +++ b/tests/Legacy/IntercomConversationsTest.php @@ -0,0 +1,74 @@ +client->method('post')->willReturn('foo'); + + $conversations = new IntercomConversations($this->client); + $this->assertSame('foo', $conversations->create([])); + } + + public function testConversationsList() + { + $this->client->method('get')->willReturn('foo'); + + $users = new IntercomConversations($this->client); + $this->assertSame('foo', $users->getConversations([])); + } + + public function testConversationPath() + { + $users = new IntercomConversations($this->client); + $this->assertSame('conversations/foo', $users->conversationPath("foo")); + } + + public function testGetConversation() + { + $this->client->method('get')->willReturn('foo'); + + $users = new IntercomConversations($this->client); + $this->assertSame('foo', $users->getConversation("foo")); + } + + public function testConversationSearch() + { + $this->client->method('post')->willReturn('foo'); + + $conversations = new IntercomConversations($this->client); + $this->assertSame('foo', $conversations->search([])); + } + + public function testConversationNextSearch() + { + $this->client->method('nextSearchPage')->willReturn('foo'); + $query = []; + $pages = new stdClass; + $pages->per_page = "10"; + $pages->next = new stdClass; + $pages->next->starting_after = "abc"; + + $conversations = new IntercomConversations($this->client); + $this->assertSame('foo', $conversations->nextSearch([], $pages)); + } + + public function testConversationReplyPath() + { + $users = new IntercomConversations($this->client); + $this->assertSame('conversations/foo/reply', $users->conversationReplyPath("foo")); + } + + public function testReplyToConversation() + { + $this->client->method('post')->willReturn('foo'); + + $users = new IntercomConversations($this->client); + $this->assertSame('foo', $users->replyToConversation("bar", [])); + } +} diff --git a/tests/Legacy/IntercomCountsTest.php b/tests/Legacy/IntercomCountsTest.php new file mode 100644 index 00000000..6ef9a1ae --- /dev/null +++ b/tests/Legacy/IntercomCountsTest.php @@ -0,0 +1,16 @@ +client->method('get')->willReturn('foo'); + + $counts = new IntercomCounts($this->client); + $this->assertSame('foo', $counts->getCounts([])); + } +} diff --git a/tests/Legacy/IntercomEventsTest.php b/tests/Legacy/IntercomEventsTest.php new file mode 100644 index 00000000..d3d9d035 --- /dev/null +++ b/tests/Legacy/IntercomEventsTest.php @@ -0,0 +1,24 @@ +client->method('post')->willReturn('foo'); + + $users = new IntercomEvents($this->client); + $this->assertSame('foo', $users->create([])); + } + + public function testEventsGet() + { + $this->client->method('get')->willReturn('foo'); + + $users = new IntercomEvents($this->client); + $this->assertSame('foo', $users->getEvents([])); + } +} diff --git a/tests/Legacy/IntercomLeadsTest.php b/tests/Legacy/IntercomLeadsTest.php new file mode 100644 index 00000000..092b8799 --- /dev/null +++ b/tests/Legacy/IntercomLeadsTest.php @@ -0,0 +1,71 @@ +client->method('post')->willReturn('foo'); + + $leads = new IntercomLeads($this->client); + $this->assertSame('foo', $leads->create([])); + } + + public function testLeadUpdate() + { + $this->client->method('post')->willReturn('foo'); + + $leads = new IntercomLeads($this->client); + $this->assertSame('foo', $leads->update([])); + } + + public function testLeadsList() + { + $this->client->method('get')->willReturn('foo'); + + $leads = new IntercomLeads($this->client); + $this->assertSame('foo', $leads->getLeads([])); + } + + public function testLeadPath() + { + + $leads = new IntercomLeads($this->client); + $this->assertSame("contacts/foo", $leads->leadPath("foo")); + } + + public function testLeadsGet() + { + $this->client->method('get')->willReturn('foo'); + + $leads = new IntercomLeads($this->client); + $this->assertSame('foo', $leads->getLead("bar")); + } + + public function testLeadsConvert() + { + $this->client->method('post')->will($this->returnArgument(0)); + + $leads = new IntercomLeads($this->client); + $this->assertSame('contacts/convert', $leads->convertLead([])); + } + + public function testLeadsDelete() + { + $this->client->method('delete')->willReturn('foo'); + + $leads = new IntercomLeads($this->client); + $this->assertSame('foo', $leads->deleteLead("bar")); + } + + public function testLeadsScroll() + { + $this->client->method('get')->willReturn('foo'); + + $leads = new IntercomLeads($this->client); + $this->assertSame('foo', $leads->scrollLeads([])); + } +} diff --git a/tests/Legacy/IntercomMessagesTest.php b/tests/Legacy/IntercomMessagesTest.php new file mode 100644 index 00000000..2e92fdfd --- /dev/null +++ b/tests/Legacy/IntercomMessagesTest.php @@ -0,0 +1,16 @@ +client->method('post')->willReturn('foo'); + + $messages = new IntercomMessages($this->client); + $this->assertSame('foo', $messages->create([])); + } +} diff --git a/tests/Legacy/IntercomNotesTest.php b/tests/Legacy/IntercomNotesTest.php new file mode 100644 index 00000000..5ce61234 --- /dev/null +++ b/tests/Legacy/IntercomNotesTest.php @@ -0,0 +1,32 @@ +client->method('post')->willReturn('foo'); + + $notes = new IntercomNotes($this->client); + $this->assertSame('foo', $notes->create([])); + } + + public function testNotesList() + { + $this->client->method('get')->willReturn('foo'); + + $notes = new IntercomNotes($this->client); + $this->assertSame('foo', $notes->getNotes([])); + } + + public function testNotesGet() + { + $this->client->method('get')->will($this->returnArgument(0)); + + $notes = new IntercomNotes($this->client); + $this->assertSame('notes/foo', $notes->getNote("foo")); + } +} diff --git a/tests/Legacy/IntercomSegmentsTest.php b/tests/Legacy/IntercomSegmentsTest.php new file mode 100644 index 00000000..6110e846 --- /dev/null +++ b/tests/Legacy/IntercomSegmentsTest.php @@ -0,0 +1,16 @@ +client->method('get')->willReturn('foo'); + + $segments = new IntercomSegments($this->client); + $this->assertSame('foo', $segments->getSegments()); + } +} diff --git a/tests/Legacy/IntercomTagsTest.php b/tests/Legacy/IntercomTagsTest.php new file mode 100644 index 00000000..bc79bf35 --- /dev/null +++ b/tests/Legacy/IntercomTagsTest.php @@ -0,0 +1,24 @@ +client->method('post')->willReturn('foo'); + + $tags = new IntercomTags($this->client); + $this->assertSame('foo', $tags->tag([])); + } + + public function testTagsList() + { + $this->client->method('get')->willReturn('foo'); + + $tags = new IntercomTags($this->client); + $this->assertSame('foo', $tags->getTags()); + } +} diff --git a/tests/Legacy/IntercomTeamsTest.php b/tests/Legacy/IntercomTeamsTest.php new file mode 100644 index 00000000..2385cb9a --- /dev/null +++ b/tests/Legacy/IntercomTeamsTest.php @@ -0,0 +1,30 @@ +client->method('get')->willReturn('foo'); + + $teams = new IntercomTeams($this->client); + $this->assertSame('foo', $teams->getTeams()); + } + + public function testTeamsGet() + { + $this->client->method('get')->willReturn('foo'); + + $teams = new IntercomTeams($this->client); + $this->assertSame('foo', $teams->getTeam(1)); + } + + public function testTeamsGetPath() + { + $teams = new IntercomTeams($this->client); + $this->assertSame('teams/1', $teams->teamPath(1)); + } +} diff --git a/tests/Legacy/IntercomUsersTest.php b/tests/Legacy/IntercomUsersTest.php new file mode 100644 index 00000000..ec9aa9e6 --- /dev/null +++ b/tests/Legacy/IntercomUsersTest.php @@ -0,0 +1,56 @@ +client->method('post')->willReturn('foo'); + + $users = new IntercomUsers($this->client); + $this->assertSame('foo', $users->create([])); + } + + public function testUserUpdate() + { + $this->client->method('post')->willReturn('foo'); + + $users = new IntercomUsers($this->client); + $this->assertSame('foo', $users->update([])); + } + + public function testUserGet() + { + $this->client->method('get')->willReturn('foo'); + + $users = new IntercomUsers($this->client); + $this->assertSame('foo', $users->getUsers([])); + } + + public function testArchiveUser() + { + $this->client->method('delete')->willReturn('foo'); + + $users = new IntercomUsers($this->client); + $this->assertSame('foo', $users->archiveUser('')); + } + + public function testDeleteUser() + { + $this->client->method('delete')->willReturn('foo'); + + $users = new IntercomUsers($this->client); + $this->assertSame('foo', $users->deleteUser('')); + } + + public function testPermanentlyDeleteUser() + { + $this->client->method('post')->willReturn('foo'); + + $users = new IntercomUsers($this->client); + $this->assertSame('foo', $users->permanentlyDeleteUser('')); + } +} diff --git a/tests/Legacy/IntercomVisitorsTest.php b/tests/Legacy/IntercomVisitorsTest.php new file mode 100644 index 00000000..26fd0196 --- /dev/null +++ b/tests/Legacy/IntercomVisitorsTest.php @@ -0,0 +1,47 @@ +client->method('put')->willReturn('foo'); + + $visitors = new IntercomVisitors($this->client); + $this->assertSame('foo', $visitors->update([])); + } + + public function testVisitorPath() + { + $visitors = new IntercomVisitors($this->client); + $this->assertSame("visitors/foo", $visitors->visitorPath("foo")); + } + + public function testVisitorsGet() + { + $this->client->method('get')->willReturn('foo'); + + $visitors = new IntercomVisitors($this->client); + $this->assertSame('foo', $visitors->getVisitor("bar")); + } + + public function testVisitorsConvert() + { + + $this->client->method('post')->will($this->returnArgument(0)); + + $visitors = new IntercomVisitors($this->client); + $this->assertSame('visitors/convert', $visitors->convertVisitor([])); + } + + public function testVisitorsDelete() + { + $this->client->method('delete')->willReturn('foo'); + + $visitors = new IntercomVisitors($this->client); + $this->assertSame('foo', $visitors->deleteVisitor("bar")); + } +} diff --git a/tests/Legacy/TestCase.php b/tests/Legacy/TestCase.php new file mode 100644 index 00000000..061b7613 --- /dev/null +++ b/tests/Legacy/TestCase.php @@ -0,0 +1,21 @@ +client = $this->getMockBuilder(IntercomClient::class)->disableOriginalConstructor()->getMock(); + } +} From 6cbb8181cba0982b40f232cfd1ae546f0bca2c69 Mon Sep 17 00:00:00 2001 From: jsklan Date: Tue, 7 Oct 2025 19:01:22 -0400 Subject: [PATCH 4/9] update namespace and use statements --- tests/Legacy/IntercomAdminsTest.php | 4 ++-- tests/Legacy/IntercomBulkTest.php | 4 ++-- tests/Legacy/IntercomClientTest.php | 4 ++-- tests/Legacy/IntercomCompaniesTest.php | 4 ++-- tests/Legacy/IntercomContactsTest.php | 4 ++-- tests/Legacy/IntercomConversationsTest.php | 4 ++-- tests/Legacy/IntercomCountsTest.php | 4 ++-- tests/Legacy/IntercomEventsTest.php | 4 ++-- tests/Legacy/IntercomLeadsTest.php | 4 ++-- tests/Legacy/IntercomMessagesTest.php | 4 ++-- tests/Legacy/IntercomNotesTest.php | 4 ++-- tests/Legacy/IntercomSegmentsTest.php | 4 ++-- tests/Legacy/IntercomTagsTest.php | 4 ++-- tests/Legacy/IntercomTeamsTest.php | 4 ++-- tests/Legacy/IntercomUsersTest.php | 4 ++-- tests/Legacy/IntercomVisitorsTest.php | 4 ++-- tests/Legacy/TestCase.php | 4 ++-- 17 files changed, 34 insertions(+), 34 deletions(-) diff --git a/tests/Legacy/IntercomAdminsTest.php b/tests/Legacy/IntercomAdminsTest.php index 89137993..ac6939fe 100644 --- a/tests/Legacy/IntercomAdminsTest.php +++ b/tests/Legacy/IntercomAdminsTest.php @@ -1,8 +1,8 @@ Date: Tue, 7 Oct 2025 19:07:34 -0400 Subject: [PATCH 5/9] allow php-http discovery --- composer.json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 22c1ba3e..14e29170 100644 --- a/composer.json +++ b/composer.json @@ -48,5 +48,10 @@ "homepage": "https://www.intercom.com" } ], + "config": { + "allow-plugins": { + "php-http/discovery": true + } + }, "homepage": "https://developers.intercom.com/docs" -} \ No newline at end of file +} From 4b28e8c80d0f1896795a5c741288ee756e47b872 Mon Sep 17 00:00:00 2001 From: jsklan Date: Tue, 7 Oct 2025 19:14:43 -0400 Subject: [PATCH 6/9] update phpstan.neon to exclude legacy files from composer analyze --- .fernignore | 1 + phpstan.neon | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.fernignore b/.fernignore index ce0b2661..82321acd 100644 --- a/.fernignore +++ b/.fernignore @@ -1,3 +1,4 @@ # Specify files that shouldn't be modified by Fern src/Legacy composer.json +phpstan.neon \ No newline at end of file diff --git a/phpstan.neon b/phpstan.neon index 780706b8..75f9478e 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,4 +3,7 @@ parameters: reportUnmatchedIgnoredErrors: false paths: - src - - tests \ No newline at end of file + - tests + excludePaths: + - src/Legacy + - tests/Legacy \ No newline at end of file From 2f28ee694bc8a69c04862f731a59f9f61c141470 Mon Sep 17 00:00:00 2001 From: jsklan Date: Tue, 7 Oct 2025 19:20:38 -0400 Subject: [PATCH 7/9] update readme --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 1c214f4f..2afb70d6 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,27 @@ foreach ($items->getPages() as $page) { } ``` +## Legacy SDK + +While the new SDK has a lot of improvements, we at Intercom understand that it takes time to upgrade when there are breaking changes. +To make the migration easier, the new SDK also exports the legacy SDK as `Intercom\Legacy\...`. Here's an example of how you can use the +legacy SDK alongside the new SDK inside a single file: + +```php +use Intercom\IntercomClient; +use Intercom\Legacy\IntercomClient as LegacyIntercomClient; + +$intercom = new IntercomClient(); +$legacyClient = new LegacyIntercomClient(); +``` + +We recommend migrating to the new SDK using the following steps: + +1. Upgrade the package to `^5.0.1` +2. Search and replace all requires and imports from `Intercom\...` to `Intercom\Legacy\...` + +3. Gradually move over to use the new SDK by importing it from the `Intercom\...` import. + ## Advanced From 86ff03f5befbc82b2d1f95be6db1ca83f7bb10e0 Mon Sep 17 00:00:00 2001 From: jsklan Date: Tue, 7 Oct 2025 19:23:35 -0400 Subject: [PATCH 8/9] remove legacy tests --- phpstan.neon | 3 +- tests/Legacy/IntercomAdminsTest.php | 30 ---- tests/Legacy/IntercomBulkTest.php | 24 ---- tests/Legacy/IntercomClientTest.php | 157 --------------------- tests/Legacy/IntercomCompaniesTest.php | 60 -------- tests/Legacy/IntercomContactsTest.php | 82 ----------- tests/Legacy/IntercomConversationsTest.php | 74 ---------- tests/Legacy/IntercomCountsTest.php | 16 --- tests/Legacy/IntercomEventsTest.php | 24 ---- tests/Legacy/IntercomLeadsTest.php | 71 ---------- tests/Legacy/IntercomMessagesTest.php | 16 --- tests/Legacy/IntercomNotesTest.php | 32 ----- tests/Legacy/IntercomSegmentsTest.php | 16 --- tests/Legacy/IntercomTagsTest.php | 24 ---- tests/Legacy/IntercomTeamsTest.php | 30 ---- tests/Legacy/IntercomUsersTest.php | 56 -------- tests/Legacy/IntercomVisitorsTest.php | 47 ------ tests/Legacy/TestCase.php | 21 --- 18 files changed, 1 insertion(+), 782 deletions(-) delete mode 100644 tests/Legacy/IntercomAdminsTest.php delete mode 100644 tests/Legacy/IntercomBulkTest.php delete mode 100644 tests/Legacy/IntercomClientTest.php delete mode 100644 tests/Legacy/IntercomCompaniesTest.php delete mode 100644 tests/Legacy/IntercomContactsTest.php delete mode 100644 tests/Legacy/IntercomConversationsTest.php delete mode 100644 tests/Legacy/IntercomCountsTest.php delete mode 100644 tests/Legacy/IntercomEventsTest.php delete mode 100644 tests/Legacy/IntercomLeadsTest.php delete mode 100644 tests/Legacy/IntercomMessagesTest.php delete mode 100644 tests/Legacy/IntercomNotesTest.php delete mode 100644 tests/Legacy/IntercomSegmentsTest.php delete mode 100644 tests/Legacy/IntercomTagsTest.php delete mode 100644 tests/Legacy/IntercomTeamsTest.php delete mode 100644 tests/Legacy/IntercomUsersTest.php delete mode 100644 tests/Legacy/IntercomVisitorsTest.php delete mode 100644 tests/Legacy/TestCase.php diff --git a/phpstan.neon b/phpstan.neon index 75f9478e..4c0f9626 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -5,5 +5,4 @@ parameters: - src - tests excludePaths: - - src/Legacy - - tests/Legacy \ No newline at end of file + - src/Legacy \ No newline at end of file diff --git a/tests/Legacy/IntercomAdminsTest.php b/tests/Legacy/IntercomAdminsTest.php deleted file mode 100644 index ac6939fe..00000000 --- a/tests/Legacy/IntercomAdminsTest.php +++ /dev/null @@ -1,30 +0,0 @@ -client->method('get')->willReturn('foo'); - - $users = new IntercomAdmins($this->client); - $this->assertSame('foo', $users->getAdmins()); - } - - public function testAdminsGet() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomAdmins($this->client); - $this->assertSame('foo', $users->getAdmin(1)); - } - - public function testAdminsGetPath() - { - $users = new IntercomAdmins($this->client); - $this->assertSame('admins/1', $users->adminPath(1)); - } -} diff --git a/tests/Legacy/IntercomBulkTest.php b/tests/Legacy/IntercomBulkTest.php deleted file mode 100644 index 03f2cea6..00000000 --- a/tests/Legacy/IntercomBulkTest.php +++ /dev/null @@ -1,24 +0,0 @@ -client->method('post')->will($this->returnArgument(0)); - - $bulk = new IntercomBulk($this->client); - $this->assertSame('bulk/users', $bulk->users([])); - } - - public function testBulkEvents() - { - $this->client->method('post')->will($this->returnArgument(0)); - - $bulk = new IntercomBulk($this->client); - $this->assertSame('bulk/events', $bulk->events([])); - } -} diff --git a/tests/Legacy/IntercomClientTest.php b/tests/Legacy/IntercomClientTest.php deleted file mode 100644 index a1a6f71d..00000000 --- a/tests/Legacy/IntercomClientTest.php +++ /dev/null @@ -1,157 +0,0 @@ -addResponse( - new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}") - ); - - $client = new IntercomClient('u', 'p'); - $client->setHttpClient($httpClient); - - $client->users->create([ - 'email' => 'test@intercom.io' - ]); - - foreach ($httpClient->getRequests() as $request) { - $basic = $request->getHeaders()['Authorization'][0]; - $this->assertSame("Basic dTpw", $basic); - } - } - - public function testClientWithExtraHeaders() - { - $httpClient = new Client(); - $httpClient->addResponse( - new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}") - ); - - $client = new IntercomClient('u', 'p', ['Custom-Header' => 'value']); - $client->setHttpClient($httpClient); - - $client->users->create([ - 'email' => 'test@intercom.io' - ]); - - foreach ($httpClient->getRequests() as $request) { - $headers = $request->getHeaders(); - $this->assertSame('application/json', $headers['Accept'][0]); - $this->assertSame('application/json', $headers['Content-Type'][0]); - $this->assertSame('value', $headers['Custom-Header'][0]); - } - } - - public function testClientErrorHandling() - { - $httpClient = new Client(); - $httpClient->addResponse( - new Response(404) - ); - $httpClient = new PluginClient($httpClient, [new ErrorPlugin()]); - - $client = new IntercomClient('u', 'p'); - $client->setHttpClient($httpClient); - - $this->expectException(Exception::class); - $client->users->create([ - 'email' => 'test@intercom.io' - ]); - } - - public function testServerErrorHandling() - { - $httpClient = new Client(); - $httpClient->addResponse( - new Response(500) - ); - $httpClient = new PluginClient($httpClient, [new ErrorPlugin()]); - - $client = new IntercomClient('u', 'p'); - $client->setHttpClient($httpClient); - - $this->expectException(Exception::class); - $client->users->create([ - 'email' => 'test@intercom.io' - ]); - } - - public function testPaginationHelper() - { - $httpClient = new Client(); - $httpClient->addResponse( - new Response(200, ['X-Foo' => 'Bar'], "{\"foo\":\"bar\"}") - ); - - $client = new IntercomClient('u', 'p'); - $client->setHttpClient($httpClient); - - $pages = new stdClass; - $pages->next = 'https://foo.com'; - - $client->nextPage($pages); - - foreach ($httpClient->getRequests() as $request) { - $host = $request->getUri()->getHost(); - $this->assertSame("foo.com", $host); - } - } - - public function testRateLimitDetails() - { - date_default_timezone_set('UTC'); - $time = time() + 7; - - $httpClient = new Client(); - $httpClient->addResponse( - new Response( - 200, - [ - 'X-RateLimit-Limit' => '83', - 'X-RateLimit-Remaining' => '2', - 'X-RateLimit-Reset' => $time - ], - "{\"foo\":\"bar\"}" - ) - ); - - $client = new IntercomClient('u', 'p'); - $client->setHttpClient($httpClient); - - $client->users->create([ - 'email' => 'test@intercom.io' - ]); - - $rateLimitDetails = $client->getRateLimitDetails(); - $this->assertIsArray($rateLimitDetails); - $this->assertArrayHasKey('limit', $rateLimitDetails); - $this->assertArrayHasKey('remaining', $rateLimitDetails); - $this->assertArrayHasKey('reset_at', $rateLimitDetails); - $this->assertSame(83, $rateLimitDetails['limit']); - $this->assertSame(2, $rateLimitDetails['remaining']); - $this->assertSame( - (new DateTimeImmutable)->setTimestamp($time)->getTimestamp(), - $rateLimitDetails['reset_at']->getTimestamp() - ); - } -} diff --git a/tests/Legacy/IntercomCompaniesTest.php b/tests/Legacy/IntercomCompaniesTest.php deleted file mode 100644 index fa889819..00000000 --- a/tests/Legacy/IntercomCompaniesTest.php +++ /dev/null @@ -1,60 +0,0 @@ -client->method('post')->willReturn('foo'); - - $companies = new IntercomCompanies($this->client); - $this->assertSame('foo', $companies->create([])); - } - - public function testCompanyUpdate() - { - $this->client->method('post')->willReturn('foo'); - - $companies = new IntercomCompanies($this->client); - $this->assertSame('foo', $companies->update([])); - } - - public function testCompanyGet() - { - $this->client->method('get')->willReturn('foo'); - - $companies = new IntercomCompanies($this->client); - $this->assertSame('foo', $companies->getCompanies([])); - } - - public function testCompanyPath() - { - $users = new IntercomCompanies($this->client); - $this->assertSame('companies/foo', $users->companyPath("foo")); - } - - public function testCompanyGetById() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomCompanies($this->client); - $this->assertSame('foo', $users->getCompany("foo")); - } - - public function testCompanyGetUsers() - { - $this->client->method('get')->willReturn('foo'); - - $companies = new IntercomCompanies($this->client); - $this->assertSame('foo', $companies->getCompanyUsers("foo")); - } - - public function testCompanyUsersPath() - { - $users = new IntercomCompanies($this->client); - $this->assertSame('companies/foo/users', $users->companyUsersPath("foo")); - } -} diff --git a/tests/Legacy/IntercomContactsTest.php b/tests/Legacy/IntercomContactsTest.php deleted file mode 100644 index 85e28d18..00000000 --- a/tests/Legacy/IntercomContactsTest.php +++ /dev/null @@ -1,82 +0,0 @@ -client->method('post')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->create([])); - } - - public function testContactUpdate() - { - $this->client->method('put')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->update('', [])); - } - - public function testContactsGet() - { - $this->client->method('get')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->getContacts([])); - } - - public function testContactGet() - { - $this->client->method('get')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->getContact("123")); - } - - public function testContactDelete() - { - $this->client->method('delete')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->deleteContact('')); - } - - public function testContactSearch() - { - $this->client->method('post')->willReturn('foo'); - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->search([])); - } - - public function testContactNextSearch() - { - $this->client->method('nextSearchPage')->willReturn('foo'); - $query = []; - $pages = new stdClass; - $pages->per_page = "10"; - $pages->next = new stdClass; - $pages->next->starting_after = "abc"; - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->nextSearch([], $pages)); - } - - public function testConversationNextCursor() - { - $this->client->method('nextCursorPage')->willReturn('foo'); - $query = []; - $pages = new stdClass; - $pages->next = new stdClass; - $pages->next->starting_after = "abc"; - - $contacts = new IntercomContacts($this->client); - $this->assertSame('foo', $contacts->nextCursor($pages)); - } -} diff --git a/tests/Legacy/IntercomConversationsTest.php b/tests/Legacy/IntercomConversationsTest.php deleted file mode 100644 index 027a5044..00000000 --- a/tests/Legacy/IntercomConversationsTest.php +++ /dev/null @@ -1,74 +0,0 @@ -client->method('post')->willReturn('foo'); - - $conversations = new IntercomConversations($this->client); - $this->assertSame('foo', $conversations->create([])); - } - - public function testConversationsList() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomConversations($this->client); - $this->assertSame('foo', $users->getConversations([])); - } - - public function testConversationPath() - { - $users = new IntercomConversations($this->client); - $this->assertSame('conversations/foo', $users->conversationPath("foo")); - } - - public function testGetConversation() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomConversations($this->client); - $this->assertSame('foo', $users->getConversation("foo")); - } - - public function testConversationSearch() - { - $this->client->method('post')->willReturn('foo'); - - $conversations = new IntercomConversations($this->client); - $this->assertSame('foo', $conversations->search([])); - } - - public function testConversationNextSearch() - { - $this->client->method('nextSearchPage')->willReturn('foo'); - $query = []; - $pages = new stdClass; - $pages->per_page = "10"; - $pages->next = new stdClass; - $pages->next->starting_after = "abc"; - - $conversations = new IntercomConversations($this->client); - $this->assertSame('foo', $conversations->nextSearch([], $pages)); - } - - public function testConversationReplyPath() - { - $users = new IntercomConversations($this->client); - $this->assertSame('conversations/foo/reply', $users->conversationReplyPath("foo")); - } - - public function testReplyToConversation() - { - $this->client->method('post')->willReturn('foo'); - - $users = new IntercomConversations($this->client); - $this->assertSame('foo', $users->replyToConversation("bar", [])); - } -} diff --git a/tests/Legacy/IntercomCountsTest.php b/tests/Legacy/IntercomCountsTest.php deleted file mode 100644 index db01e131..00000000 --- a/tests/Legacy/IntercomCountsTest.php +++ /dev/null @@ -1,16 +0,0 @@ -client->method('get')->willReturn('foo'); - - $counts = new IntercomCounts($this->client); - $this->assertSame('foo', $counts->getCounts([])); - } -} diff --git a/tests/Legacy/IntercomEventsTest.php b/tests/Legacy/IntercomEventsTest.php deleted file mode 100644 index 75aaa01a..00000000 --- a/tests/Legacy/IntercomEventsTest.php +++ /dev/null @@ -1,24 +0,0 @@ -client->method('post')->willReturn('foo'); - - $users = new IntercomEvents($this->client); - $this->assertSame('foo', $users->create([])); - } - - public function testEventsGet() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomEvents($this->client); - $this->assertSame('foo', $users->getEvents([])); - } -} diff --git a/tests/Legacy/IntercomLeadsTest.php b/tests/Legacy/IntercomLeadsTest.php deleted file mode 100644 index 0887c6b8..00000000 --- a/tests/Legacy/IntercomLeadsTest.php +++ /dev/null @@ -1,71 +0,0 @@ -client->method('post')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->create([])); - } - - public function testLeadUpdate() - { - $this->client->method('post')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->update([])); - } - - public function testLeadsList() - { - $this->client->method('get')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->getLeads([])); - } - - public function testLeadPath() - { - - $leads = new IntercomLeads($this->client); - $this->assertSame("contacts/foo", $leads->leadPath("foo")); - } - - public function testLeadsGet() - { - $this->client->method('get')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->getLead("bar")); - } - - public function testLeadsConvert() - { - $this->client->method('post')->will($this->returnArgument(0)); - - $leads = new IntercomLeads($this->client); - $this->assertSame('contacts/convert', $leads->convertLead([])); - } - - public function testLeadsDelete() - { - $this->client->method('delete')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->deleteLead("bar")); - } - - public function testLeadsScroll() - { - $this->client->method('get')->willReturn('foo'); - - $leads = new IntercomLeads($this->client); - $this->assertSame('foo', $leads->scrollLeads([])); - } -} diff --git a/tests/Legacy/IntercomMessagesTest.php b/tests/Legacy/IntercomMessagesTest.php deleted file mode 100644 index f7b6520f..00000000 --- a/tests/Legacy/IntercomMessagesTest.php +++ /dev/null @@ -1,16 +0,0 @@ -client->method('post')->willReturn('foo'); - - $messages = new IntercomMessages($this->client); - $this->assertSame('foo', $messages->create([])); - } -} diff --git a/tests/Legacy/IntercomNotesTest.php b/tests/Legacy/IntercomNotesTest.php deleted file mode 100644 index 4d6ba6c3..00000000 --- a/tests/Legacy/IntercomNotesTest.php +++ /dev/null @@ -1,32 +0,0 @@ -client->method('post')->willReturn('foo'); - - $notes = new IntercomNotes($this->client); - $this->assertSame('foo', $notes->create([])); - } - - public function testNotesList() - { - $this->client->method('get')->willReturn('foo'); - - $notes = new IntercomNotes($this->client); - $this->assertSame('foo', $notes->getNotes([])); - } - - public function testNotesGet() - { - $this->client->method('get')->will($this->returnArgument(0)); - - $notes = new IntercomNotes($this->client); - $this->assertSame('notes/foo', $notes->getNote("foo")); - } -} diff --git a/tests/Legacy/IntercomSegmentsTest.php b/tests/Legacy/IntercomSegmentsTest.php deleted file mode 100644 index 19e8ad42..00000000 --- a/tests/Legacy/IntercomSegmentsTest.php +++ /dev/null @@ -1,16 +0,0 @@ -client->method('get')->willReturn('foo'); - - $segments = new IntercomSegments($this->client); - $this->assertSame('foo', $segments->getSegments()); - } -} diff --git a/tests/Legacy/IntercomTagsTest.php b/tests/Legacy/IntercomTagsTest.php deleted file mode 100644 index 6e8daf71..00000000 --- a/tests/Legacy/IntercomTagsTest.php +++ /dev/null @@ -1,24 +0,0 @@ -client->method('post')->willReturn('foo'); - - $tags = new IntercomTags($this->client); - $this->assertSame('foo', $tags->tag([])); - } - - public function testTagsList() - { - $this->client->method('get')->willReturn('foo'); - - $tags = new IntercomTags($this->client); - $this->assertSame('foo', $tags->getTags()); - } -} diff --git a/tests/Legacy/IntercomTeamsTest.php b/tests/Legacy/IntercomTeamsTest.php deleted file mode 100644 index 33a4dbec..00000000 --- a/tests/Legacy/IntercomTeamsTest.php +++ /dev/null @@ -1,30 +0,0 @@ -client->method('get')->willReturn('foo'); - - $teams = new IntercomTeams($this->client); - $this->assertSame('foo', $teams->getTeams()); - } - - public function testTeamsGet() - { - $this->client->method('get')->willReturn('foo'); - - $teams = new IntercomTeams($this->client); - $this->assertSame('foo', $teams->getTeam(1)); - } - - public function testTeamsGetPath() - { - $teams = new IntercomTeams($this->client); - $this->assertSame('teams/1', $teams->teamPath(1)); - } -} diff --git a/tests/Legacy/IntercomUsersTest.php b/tests/Legacy/IntercomUsersTest.php deleted file mode 100644 index dff686ba..00000000 --- a/tests/Legacy/IntercomUsersTest.php +++ /dev/null @@ -1,56 +0,0 @@ -client->method('post')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->create([])); - } - - public function testUserUpdate() - { - $this->client->method('post')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->update([])); - } - - public function testUserGet() - { - $this->client->method('get')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->getUsers([])); - } - - public function testArchiveUser() - { - $this->client->method('delete')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->archiveUser('')); - } - - public function testDeleteUser() - { - $this->client->method('delete')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->deleteUser('')); - } - - public function testPermanentlyDeleteUser() - { - $this->client->method('post')->willReturn('foo'); - - $users = new IntercomUsers($this->client); - $this->assertSame('foo', $users->permanentlyDeleteUser('')); - } -} diff --git a/tests/Legacy/IntercomVisitorsTest.php b/tests/Legacy/IntercomVisitorsTest.php deleted file mode 100644 index 64650707..00000000 --- a/tests/Legacy/IntercomVisitorsTest.php +++ /dev/null @@ -1,47 +0,0 @@ -client->method('put')->willReturn('foo'); - - $visitors = new IntercomVisitors($this->client); - $this->assertSame('foo', $visitors->update([])); - } - - public function testVisitorPath() - { - $visitors = new IntercomVisitors($this->client); - $this->assertSame("visitors/foo", $visitors->visitorPath("foo")); - } - - public function testVisitorsGet() - { - $this->client->method('get')->willReturn('foo'); - - $visitors = new IntercomVisitors($this->client); - $this->assertSame('foo', $visitors->getVisitor("bar")); - } - - public function testVisitorsConvert() - { - - $this->client->method('post')->will($this->returnArgument(0)); - - $visitors = new IntercomVisitors($this->client); - $this->assertSame('visitors/convert', $visitors->convertVisitor([])); - } - - public function testVisitorsDelete() - { - $this->client->method('delete')->willReturn('foo'); - - $visitors = new IntercomVisitors($this->client); - $this->assertSame('foo', $visitors->deleteVisitor("bar")); - } -} diff --git a/tests/Legacy/TestCase.php b/tests/Legacy/TestCase.php deleted file mode 100644 index d1d3ecce..00000000 --- a/tests/Legacy/TestCase.php +++ /dev/null @@ -1,21 +0,0 @@ -client = $this->getMockBuilder(IntercomClient::class)->disableOriginalConstructor()->getMock(); - } -} From de686c3caf752e0ccdd3fd1b4968f31533a85d3d Mon Sep 17 00:00:00 2001 From: jsklan Date: Tue, 7 Oct 2025 19:25:01 -0400 Subject: [PATCH 9/9] update version mentioned in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2afb70d6..21e9f39f 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,7 @@ $legacyClient = new LegacyIntercomClient(); We recommend migrating to the new SDK using the following steps: -1. Upgrade the package to `^5.0.1` +1. Upgrade the package to `^5.1.0` 2. Search and replace all requires and imports from `Intercom\...` to `Intercom\Legacy\...` 3. Gradually move over to use the new SDK by importing it from the `Intercom\...` import.