Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 4 additions & 3 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"cliVersion": "3.0.2",
"cliVersion": "5.187.0",
"generatorName": "fernapi/fern-php-sdk",
"generatorVersion": "1.25.0",
"generatorVersion": "2.30.12",
"generatorConfig": {
"namespace": "Intercom",
"clientName": "IntercomClient",
"packageName": "intercom/intercom-php",
"propertyAccess": "private",
"inlinePathParameters": true,
"encode-path-params": true,
"composerJson": {
"description": "Intercom API client.",
"author": {
Expand All @@ -17,4 +18,4 @@
"homepage": "https://developers.intercom.com/docs"
}
}
}
}
120 changes: 120 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Contributing

Thanks for your interest in contributing to this SDK! This document provides guidelines for contributing to the project.

## Getting Started

### Prerequisites

- PHP 8.1+
- Composer

### Installation

Install the project dependencies:

```bash
composer install
```

### Testing

Run the test suite:

```bash
composer test
```

Or run PHPUnit directly:

```bash
./vendor/bin/phpunit
```

### Linting & Formatting

Fix code style issues:

```bash
./vendor/bin/php-cs-fixer fix
```

### Static Analysis

Run static analysis:

```bash
./vendor/bin/phpstan analyse
```

## About Generated Code

**Important**: Most files in this SDK are automatically generated by [Fern](https://buildwithfern.com) from the API definition. Direct modifications to generated files will be overwritten the next time the SDK is generated.

### Generated Files

The following directories contain generated code:
- `src/` - API client classes and types
- Most PHP files in the project

### How to Customize

If you need to customize the SDK, you have two options:

#### Option 1: Use `.fernignore`

For custom code that should persist across SDK regenerations:

1. Create a `.fernignore` file in the project root
2. Add file patterns for files you want to preserve (similar to `.gitignore` syntax)
3. Add your custom code to those files

Files listed in `.fernignore` will not be overwritten when the SDK is regenerated.

For more information, see the [Fern documentation on custom code](https://buildwithfern.com/learn/sdks/overview/custom-code).

#### Option 2: Contribute to the Generator

If you want to change how code is generated for all users of this SDK:

1. The PHP SDK generator lives in the [Fern repository](https://github.com/fern-api/fern)
2. Generator code is located at `generators/php/`
3. Follow the [Fern contributing guidelines](https://github.com/fern-api/fern/blob/main/CONTRIBUTING.md)
4. Submit a pull request with your changes to the generator

This approach is best for:
- Bug fixes in generated code
- New features that would benefit all users
- Improvements to code generation patterns

## Making Changes

### Workflow

1. Create a new branch for your changes
2. Make your modifications
3. Run tests to ensure nothing breaks: `composer test`
4. Run formatting: `./vendor/bin/php-cs-fixer fix`
5. Run static analysis: `./vendor/bin/phpstan analyse`
6. Commit your changes with a clear commit message
7. Push your branch and create a pull request

### Commit Messages

Write clear, descriptive commit messages that explain what changed and why.

### Code Style

This project uses PHP CS Fixer for automated code formatting. Run `./vendor/bin/php-cs-fixer fix` before committing to ensure your code meets the project's style guidelines.

## Questions or Issues?

If you have questions or run into issues:

1. Check the [Fern documentation](https://buildwithfern.com)
2. Search existing [GitHub issues](https://github.com/fern-api/fern/issues)
3. Open a new issue if your question hasn't been addressed

## License

By contributing to this project, you agree that your contributions will be licensed under the same license as the project.
88 changes: 47 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Intercom PHP Library

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fintercom%2Fintercom-php)
[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=Intercom%2FPHP)
[![php shield](https://img.shields.io/badge/php-packagist-pink)](https://packagist.org/packages/intercom/intercom-php)

The Intercom PHP library provides convenient access to the Intercom APIs from PHP.
Expand All @@ -10,9 +10,9 @@ The Intercom PHP library provides convenient access to the Intercom APIs from PH
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Environments](#environments)
- [Exception Handling](#exception-handling)
- [Pagination](#pagination)
- [Legacy Sdk](#legacy-sdk)
- [Advanced](#advanced)
- [Custom Client](#custom-client)
- [Retries](#retries)
Expand Down Expand Up @@ -53,6 +53,31 @@ $client->aiContent->createContentImportSource(

```

## Environments

This SDK allows you to configure different environments for API requests.

```php
The SDK defaults to the `UsProduction` environment. To use a different environment, pass it to the client constructor:

```php
use Intercom\IntercomClient;
use Intercom\Environments;

$client = new IntercomClient(
token: '<YOUR_TOKEN>',
options: [
'baseUrl' => Environments::Staging->value
]
);
```

Available environments:
- `Environments::UsProduction`
- `Environments::EuProduction`
- `Environments::AuProduction`
```

## Exception Handling

When the API returns a non-success status code (4xx or 5xx response), an exception will be thrown.
Expand All @@ -79,7 +104,7 @@ List endpoints return a `Pager<T>` which lets you loop over all items and the SD
use Intercom\IntercomClient;

$client = new IntercomClient(
'<token>',
'<YOUR_TOKEN>',
['baseUrl' => 'https://api.example.com'],
);

Expand All @@ -100,58 +125,34 @@ 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.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.


## Advanced

### Custom Client

This SDK is built to work with any HTTP client that implements Guzzle's `ClientInterface`.
By default, if no client is provided, the SDK will use Guzzle's default HTTP client.
This SDK is built to work with any HTTP client that implements the [PSR-18](https://www.php-fig.org/psr/psr-18/) `ClientInterface`.
By default, if no client is provided, the SDK will use `php-http/discovery` to find an installed HTTP client.
However, you can pass your own client that adheres to `ClientInterface`:

```php
use Intercom\IntercomClient;

// Create a custom Guzzle client with specific configuration.
// Pass any PSR-18 compatible HTTP client implementation.
// For example, using Guzzle:
$customClient = new \GuzzleHttp\Client([
'timeout' => 5.0,
]);

// Pass the custom client when creating an instance of the class.
$client = new IntercomClient(options: [
'client' => $customClient
]);

// You can also utilize the same technique to leverage advanced customizations to the client such as adding middleware
$handlerStack = \GuzzleHttp\HandlerStack::create();
$handlerStack->push(MyCustomMiddleware::create());
$customClient = new \GuzzleHttp\Client(['handler' => $handlerStack]);

// Pass the custom client when creating an instance of the class.
$client = new IntercomClient(options: [
'client' => $customClient
]);
// Or using Symfony HttpClient:
// $customClient = (new \Symfony\Component\HttpClient\Psr18Client())
// ->withOptions(['timeout' => 5.0]);
//
// $client = new IntercomClient(options: [
// 'client' => $customClient
// ]);
```

### Retries
Expand All @@ -164,7 +165,12 @@ A request is deemed retryable when any of the following HTTP status codes is ret

- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (Internal Server Error)

The `retryStatusCodes` configuration controls which [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) status codes are retried:

- `legacy` (default): Retries `408`, `429`, and all `>= 500`
- `recommended`: Retries `408`, `429`, `502`, `503`, `504` only (excludes `500 Internal Server Error` to avoid retrying non-idempotent failures)

Use the `maxRetries` request option to configure this behavior.

Expand All @@ -185,7 +191,7 @@ The SDK defaults to a 30 second timeout. Use the `timeout` option to configure t
$response = $client->aiContent->createContentImportSource(
...,
options: [
'timeout' => 3.0 // Override timeout to 3 seconds
'timeout' => 3.0 // Override timeout at the request level
]
);
```
Expand All @@ -198,4 +204,4 @@ otherwise they would be overwritten upon the next generated release. Feel free t
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!
On the other hand, contributions to the README are always very welcome!
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
"php-http/client-common": "^2.0",
"php-http/discovery": "^1.0",
"php-http/message": "^1.0",
"php-http/multipart-stream-builder": "^1.4",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0 || ^2.0",
"nyholm/psr7": "^1.0",
"guzzlehttp/guzzle": "^7.4"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^12.5",
"friendsofphp/php-cs-fixer": "3.5.0",
"phpstan/phpstan": "^1.12"
},
Expand Down
Loading
Loading