Skip to content

Commit 9460a8d

Browse files
fern-supportjsklan
andauthored
Add Legacy SDK submodule and migration guide #1 (#386)
* initial src file inclusion * add depts to composer.json * raw copy tests * update namespace and use statements * allow php-http discovery * update phpstan.neon to exclude legacy files from composer analyze * update readme * remove legacy tests * update version mentioned in readme --------- Co-authored-by: jsklan <[email protected]>
1 parent fb0f1c4 commit 9460a8d

21 files changed

+1576
-2
lines changed

.fernignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
# Specify files that shouldn't be modified by Fern
2+
src/Legacy
3+
composer.json
4+
phpstan.neon

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,27 @@ foreach ($items->getPages() as $page) {
8787
}
8888
```
8989

90+
## Legacy SDK
91+
92+
While the new SDK has a lot of improvements, we at Intercom understand that it takes time to upgrade when there are breaking changes.
93+
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
94+
legacy SDK alongside the new SDK inside a single file:
95+
96+
```php
97+
use Intercom\IntercomClient;
98+
use Intercom\Legacy\IntercomClient as LegacyIntercomClient;
99+
100+
$intercom = new IntercomClient();
101+
$legacyClient = new LegacyIntercomClient();
102+
```
103+
104+
We recommend migrating to the new SDK using the following steps:
105+
106+
1. Upgrade the package to `^5.1.0`
107+
2. Search and replace all requires and imports from `Intercom\...` to `Intercom\Legacy\...`
108+
109+
3. Gradually move over to use the new SDK by importing it from the `Intercom\...` import.
110+
90111

91112
## Advanced
92113

composer.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
"require": {
1212
"php": "^8.1",
1313
"ext-json": "*",
14+
"php-http/client-common": "^2.0",
15+
"php-http/discovery": "^1.0",
16+
"php-http/message": "^1.0",
17+
"psr/http-client": "^1.0",
18+
"psr/http-message": "^1.0 || ^2.0",
19+
"nyholm/psr7": "^1.0",
1420
"guzzlehttp/guzzle": "^7.4"
1521
},
1622
"require-dev": {
@@ -42,5 +48,10 @@
4248
"homepage": "https://www.intercom.com"
4349
}
4450
],
51+
"config": {
52+
"allow-plugins": {
53+
"php-http/discovery": true
54+
}
55+
},
4556
"homepage": "https://developers.intercom.com/docs"
46-
}
57+
}

phpstan.neon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ parameters:
33
reportUnmatchedIgnoredErrors: false
44
paths:
55
- src
6-
- tests
6+
- tests
7+
excludePaths:
8+
- src/Legacy

src/Legacy/IntercomAdmins.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Intercom\Legacy;
4+
5+
use Http\Client\Exception;
6+
use stdClass;
7+
8+
class IntercomAdmins extends IntercomResource
9+
{
10+
/**
11+
* Returns list of Admins.
12+
*
13+
* @see https://developers.intercom.io/reference#list-admins
14+
* @param array $options
15+
* @return stdClass
16+
* @throws Exception
17+
*/
18+
public function getAdmins($options = [])
19+
{
20+
return $this->client->get("admins", $options);
21+
}
22+
23+
/**
24+
* Gets a single Admin based on the Intercom ID.
25+
*
26+
* @see https://developers.intercom.com/v2.0/reference#view-an-admin
27+
* @param integer $id
28+
* @param array $options
29+
* @return stdClass
30+
* @throws Exception
31+
*/
32+
public function getAdmin($id, $options = [])
33+
{
34+
$path = $this->adminPath($id);
35+
return $this->client->get($path, $options);
36+
}
37+
38+
/**
39+
* Returns endpoint path to Admin with given ID.
40+
*
41+
* @param string $id
42+
* @return string
43+
*/
44+
public function adminPath($id)
45+
{
46+
return 'admins/' . $id;
47+
}
48+
}

src/Legacy/IntercomBulk.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Intercom\Legacy;
4+
5+
use Http\Client\Exception;
6+
use stdClass;
7+
8+
class IntercomBulk extends IntercomResource
9+
{
10+
/**
11+
* Creates Users in bulk.
12+
*
13+
* @param array $options
14+
* @return stdClass
15+
* @throws Exception
16+
*/
17+
public function users($options)
18+
{
19+
return $this->client->post("bulk/users", $options);
20+
}
21+
22+
/**
23+
* Creates Events in bulk.
24+
*
25+
* @param array $options
26+
* @return stdClass
27+
* @throws Exception
28+
*/
29+
public function events($options)
30+
{
31+
return $this->client->post("bulk/events", $options);
32+
}
33+
}

0 commit comments

Comments
 (0)