Skip to content

Implements 2.0 Contacts Endpoint methods and Conversation Search#306

Merged
GabrielAnca merged 12 commits intomasterfrom
dan.c/2.0
Jul 21, 2020
Merged

Implements 2.0 Contacts Endpoint methods and Conversation Search#306
GabrielAnca merged 12 commits intomasterfrom
dan.c/2.0

Conversation

@lloydliyu
Copy link
Contributor

@lloydliyu lloydliyu commented May 27, 2020

Why?

Brings Contacts and Conversation support in SDK up to 2.0.

Closes #293

How?

  • Removed IntercomCustomers resource which is no longer accessible.
  • Added new IntercomContacts resource.
  • Updated IntercomConversation resource with search method.
  • Added new nextSearch and nextCursor methods to IntercomClient.
  • Updated readme.

Copy link
Contributor

@GabrielAnca GabrielAnca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @lloydliyu! Very happy to see this happening in the PHP SDK! Lots of people will be very happy.

Made a first pass on the code itself and left some feedback 🙌

README.md Outdated
$client->contacts->getContact("570680a8a1bcbca8a90001b9");

/** Add companies to a contact */
$client->contacts->create([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though technically it's also a call to POST /contacts, I would prefer to have two explicit methods in the IntercomCompanies resource to make this more straightforward, ie $client->companies->attachContact($id) & $client->companies->detachContact($id). I think that would make using this SDK more straightforward, even though they could also do it this way. It would also make the SDK more similar to our API docs 😃

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I believe aligning it as close to the API documentation is ideal, plus the additional ease-of-use. On the API documentation, both a contact_id and id (for the company) are required, so should the method incorporate both parameters? In the example you gave, only $id is specified. (I apologize if I'm missing something, I'm relatively new to this repository)

* @return stdClass
* @throws Exception
*/
public function getContacts(array $options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a default here so we don't need to pass empty arrays when we want to make a full list request 😄

Suggested change
public function getContacts(array $options)
public function getContacts(array $options = [])

* @return stdClass
* @throws Exception
*/
public function getContact($id, $options = [])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a strongly typing fan 😅

Suggested change
public function getContact($id, $options = [])
public function getContact($id, array $options = [])

return $this->client->nextSearchPage($path, $query, $pages);
}

/** Returns next page of a Contacts list.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** Returns next page of a Contacts list.
/**
* Returns next page of a Contacts list.

* Returns next page of Contacts that match search query.
*
* @see https://developers.intercom.com/intercom-api-reference/reference#pagination-search
* @param array $options
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From here to the end of the file there are some methods where the phpdocs don't match the method params 😃

"starting_after" => $pages->next->starting_after,
]
];
$response = $this->sendRequest('POST', "https://api.intercom.io/$path", $options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to avoid hardcoding the URL in multiple places, why don't we call $this->post here?

Suggested change
$response = $this->sendRequest('POST', "https://api.intercom.io/$path", $options);
$response = $this->post($path, $options);

Same for the next method

@GabrielAnca GabrielAnca mentioned this pull request Jun 6, 2020
Copy link
Contributor

@RaneLafraze RaneLafraze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started to explore this SDK repository today and was disappointed to see it has fallen behind in terms of compatibility. I plan to invest some time in helping update this repository, and I'm happy to help in whatever way I can!

README.md Outdated
$client->contacts->getContact("570680a8a1bcbca8a90001b9");

/** Add companies to a contact */
$client->contacts->create([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, I believe aligning it as close to the API documentation is ideal, plus the additional ease-of-use. On the API documentation, both a contact_id and id (for the company) are required, so should the method incorporate both parameters? In the example you gave, only $id is specified. (I apologize if I'm missing something, I'm relatively new to this repository)

@RaneLafraze RaneLafraze mentioned this pull request Jun 26, 2020
RaneLafraze and others added 2 commits July 20, 2020 11:35
* Create dedicated attach and detach methods

* Use post and get methods instead of sendRequest()

* Add default value and update phpdocs

* Lint fixes

* Change string concatenation for consistency

Co-authored-by: Gabriel Anca Corral <GabrielAnca@users.noreply.github.com>

* Add companyId parameter and add types

* Add method to generate detach contact request path

* Add typing for parameter

Co-authored-by: Gabriel Anca Corral <GabrielAnca@users.noreply.github.com>

Co-authored-by: Gabriel Anca Corral <GabrielAnca@users.noreply.github.com>
Co-authored-by: Rane Lafraze <lafrazeRL@gmail.com>
Copy link
Contributor

@GabrielAnca GabrielAnca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, thank you so much for your effort @lloydliyu and @RaneLafraze 🚀 Let's wait for @lloydliyu to have a look at the latest changes and we'll be ready to ship 😄

@GabrielAnca
Copy link
Contributor

Got Daniel's approval separately and we are good to go. I'll be merging this PR. Before releasing a new version, I will make a separate PR that will update the README

@GabrielAnca GabrielAnca merged commit 0b0f27b into master Jul 21, 2020
@GabrielAnca GabrielAnca deleted the dan.c/2.0 branch July 21, 2020 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API 2.0 Support?

3 participants