davidwnek/survey_monkey_api_php_client
PHP client library for the SurveyMonkey API. Install via Composer, regenerate autoload as needed, then use the client in your project to call SurveyMonkey endpoints and work with surveys, collectors, and responses.
page and max_page_size parameters for getResponses), addressing a critical gap in the original assessment. This aligns with Laravel’s need for scalable data fetching (e.g., paginated Eloquent-like queries).page_size in the base class improves maintainability and reduces code duplication, which is valuable for Laravel’s service-oriented architecture.Illuminate\Pagination or custom paginators, reducing manual API response parsing.getResponses is added, but other endpoints (e.g., surveys, contacts) may still lack pagination or modern features like webhooks.page/max_page_size parameters enable Laravel-friendly paginated responses. Example integration with Laravel’s LengthAwarePaginator:
use Illuminate\Pagination\LengthAwarePaginator;
$responses = SurveyMonkey::responses()->getResponses($surveyId, [
'page' => $request->input('page', 1),
'max_page_size' => 50,
]);
$paginator = new LengthAwarePaginator(
$responses['data'],
$responses['total'],
$responses['max_page_size'],
$request->input('page', 1),
['path' => LaravelPagination::resolveCurrentPath()]
);
guzzlehttp/guzzle to v7.x, adding PHP 8.1+ syntax support).surveys, contacts) may need manual pagination implementation or extension.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Deprecated Dependencies | High | Audit composer.json for outdated packages; update or fork. Prioritize guzzlehttp/guzzle and symfony/http-client. |
| API Version Mismatch | Medium | Test pagination against SurveyMonkey API v3 endpoints. Verify max_page_size behavior (e.g., max 100 per API docs). |
| Lack of Testing | High | Write tests for pagination edge cases (e.g., empty pages, page > total_pages). Use Laravel’s HttpTests trait. |
| Performance Overhead | Low | Benchmark paginated requests vs. raw Guzzle calls. Consider caching responses (e.g., Redis) for frequent queries. |
| Maintenance Burden | High | Plan for long-term support or migrate to a maintained alternative if the package stagnates. |
| Breaking Changes | Medium | Refactoring page_size to the base class may break existing code using direct instantiation. Update migration scripts. |
Pagination Scope:
surveys, contacts) that require pagination? If so, will the package extend support, or must they be implemented manually?LengthAwarePaginator handle SurveyMonkey’s pagination metadata (e.g., total, page_size)?API Consistency:
getResponses an exception? Document inconsistencies for developers.Error Handling:
page or max_page_size values (e.g., out-of-bounds pages)? Will it throw exceptions or return empty responses?Performance:
max_page_size for SurveyMonkey API calls? Are there rate-limit implications for large pages?Laravel Integration:
paginate() method on the client), or must developers manually wrap responses?namespace App\Services;
use Davidwnek\SurveyMonkeyApi\SurveyMonkeyClient;
use Illuminate\Pagination\LengthAwarePaginator;
class SurveyMonkeyService {
public function getPaginatedResponses(int $surveyId, int $page = 1, int $perPage = 50) {
$response = SurveyMonkey::responses()->getResponses($surveyId, [
'page' => $page,
'max_page_size' => $perPage,
]);
return new LengthAwarePaginator(
$response['data'],
$response['total'],
$perPage,
$page,
['path' => route('survey.responses')]
);
}
}
SurveyMonkeyService as a singleton in AppServiceProvider:
$this->app->singleton(SurveyMonkeyService::class, function ($app) {
return new SurveyMonkeyService($app->make(SurveyMonkeyClient::class));
});
FetchSurveyResponsesJob) to avoid timeouts:
namespace App\Jobs;
use App\Services\SurveyMonkeyService;
use Illuminate\Bus\Queueable;
class FetchSurveyResponsesJob implements Queueable {
public function handle(SurveyMonkeyService $service) {
$responses = $service->getPaginatedResponses($this->surveyId);
// Process or store responses
}
}
composer.json to require PHP 8.1 and add retroactive fixes for deprecated syntax.guzzlehttp/guzzle to v7.x and symfony/http-client to v5.x for Laravel 10 compatibility.composer validate, phpstan, and pest to identify compatibility issues.page=999, max_page_size=200).LaravelSurveyMonkeyClient) to abstract differences and add Laravel-specific features:
class LaravelSurveyMonkeyClient extends SurveyMonkeyClient {
public function paginateResponses(int $surveyId, int $page = 1, int $perPage = 50) {
return $this->responses()->getResponses($surveyId, [
'page' => $page,
'max_page_size' => min($perPage, 100), // SurveyMonkey max
]);
}
}
surveys) if missing:
// Extend SurveyMonkeyClient to add pagination to surveys
public function paginateSurveys(int $page = 1, int $perPage = 50) {
return $this->surveys()->list(['page_size' => $perPage, 'page' => $page]);
}
SurveyResponsesFetched) for reactivity.config/surveymonkey.php) for pagination defaults and API settings:
'pagination' => [
'default_per_page' => 50,
'max_per_page' => 100,
],
How can I help you explore Laravel packages today?