Skip to content

Dan.c/2.0#307

Merged
GabrielAnca merged 8 commits intointercom:dan.c/2.0from
RaneLafraze:dan.c/2.0
Jul 20, 2020
Merged

Dan.c/2.0#307
GabrielAnca merged 8 commits intointercom:dan.c/2.0from
RaneLafraze:dan.c/2.0

Conversation

@RaneLafraze
Copy link
Contributor

Why?

Fulfills many of the suggestions on the current PR #306

How?

  • Created dedicated methods inside IntercomCompanies for attaching and detaching contacts
  • Replace sendRequest() calls with the respective post() and get() methods
  • Update phpdocs for new methods

@RaneLafraze RaneLafraze reopened this Jun 26, 2020
* @return stdClass
* @throws Exception
*/
public function attachContact($contactId, $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 have mixed feelings about something, so hope to get your view on this too 😄 On one hand, this API wrapper is super-lightweight and we generally just take one parameter for the id and other for the payload (options). In this case, this call requires the options to contain a specific parameter, so I think being more specific here would be helpful, ie

Suggested change
public function attachContact($contactId, $options)
public function attachContact(string $contactId, string $companyId)
{
$options = [ "id" => $companyId ];
...
}

What do you think about that change? I'm happy with keeping it as you did for consistency, but also happy to move to what I proposed 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You raise a good point, and I agree that the function should take a specific parameter for the $companyId. In order to provide as much flexibility as possible, I was thinking of keeping $options as a parameter and using array_merge like so:

Suggested change
public function attachContact($contactId, $options)
public function attachContact(string $contactId, string $companyId, $options)
{
$options = array_merge($options, ["id" => $companyId]);
...
}

What are your thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes total sense! That would definitely make it more flexible in case we add additional parameters in the future 😄 Let's do that, but adding a default for $options:

Suggested change
public function attachContact($contactId, $options)
public function attachContact(string $contactId, string $companyId, array $options = [])
{
$options = array_merge($options, ["id" => $companyId]);
...
}

public function detachContact($contactId, $companyId, $options = [])
{
$path = $this->companyAssociatePath($contactId);
return $this->client->delete($path . '/' . $companyId, $options);
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great to create a method to store the complexity of this path, ie $this->companyDetachPath($contactId, $companyId);

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.

Thank you so much for your contribution @RaneLafraze 🚀 I've made a couple of comments and I think we'd be ready to merge into the main PR 😄

@RaneLafraze
Copy link
Contributor Author

Thank you @GabrielAnca ! I've made the changes discussed above. I'm on board in terms of merging into the main branch, but I'd greatly appreciate your advice and final review. Thanks again!

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.

Thanks for making the changes @RaneLafraze 🎉 I just found one more thing I didn't see before. Other than that, we are ready to merge this into @lloydliyu's branch

Co-authored-by: Gabriel Anca Corral <GabrielAnca@users.noreply.github.com>
@RaneLafraze
Copy link
Contributor Author

Perfect, thanks again @GabrielAnca ! Please let me know if there is anything else I need to do on my end, or if there are any other ways I can help out!

@GabrielAnca
Copy link
Contributor

Looks great @RaneLafraze 🎉 Sorry I was out of the office for the last couple of days. Let's merge this one into the original PR and I'll have a look at it right now 😄

@GabrielAnca GabrielAnca merged commit 8a20228 into intercom:dan.c/2.0 Jul 20, 2020
GabrielAnca added a commit that referenced this pull request Jul 21, 2020
* Adds 2.0 contact methods

* Adds contact methods to readme.

* Corrects search for contacts

* Removes customers endpoint as this is no longer available in the API

* Adds conversation search

* Adds conversation search to Readme.

* Adds in search pagination for contacts and conversations, adds in cursor pagination for contacts.

* Potential fix for tests

* lint fixes

* Dan.c/2.0 (#307)

* 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>

* Apply suggested docs changes

Co-authored-by: Rane Lafraze <lafrazeRL@gmail.com>

* Minor docs and method arguments fixes

Co-authored-by: Rane Lafraze <lafrazeRL@gmail.com>
Co-authored-by: Gabriel Anca Corral <GabrielAnca@users.noreply.github.com>
Co-authored-by: Gabriel Anca <gabrielancacorral@gmail.com>
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.

2 participants