{"id":22140615,"url":"https://github.com/athlan/press-server-api-client","last_synced_at":"2025-03-24T11:18:10.140Z","repository":{"id":62489157,"uuid":"77252217","full_name":"athlan/press-server-api-client","owner":"athlan","description":"PressServer API Client","archived":false,"fork":false,"pushed_at":"2016-12-30T21:16:44.000Z","size":44,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-29T16:26:01.867Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/athlan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-12-23T21:48:05.000Z","updated_at":"2016-12-23T21:48:45.000Z","dependencies_parsed_at":"2022-11-02T11:15:21.380Z","dependency_job_id":null,"html_url":"https://github.com/athlan/press-server-api-client","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athlan%2Fpress-server-api-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athlan%2Fpress-server-api-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athlan%2Fpress-server-api-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athlan%2Fpress-server-api-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/athlan","download_url":"https://codeload.github.com/athlan/press-server-api-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245258215,"owners_count":20585977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-01T21:06:45.942Z","updated_at":"2025-03-24T11:18:10.120Z","avatar_url":"https://github.com/athlan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PressServer API Client\n\n![travis](https://img.shields.io/travis/athlan/press-server-api-client/master.svg)\n![license](https://img.shields.io/packagist/l/athlan/press-server-api-client.svg)\n![version](https://img.shields.io/packagist/v/athlan/press-server-api-client.svg)\n\nThis library allows you to receive callback request from [Press Server](http://www.press-server.pl/).\n\n## Recommendations\n\n* **Keep in mind that order of events matters.**\n  Try to retreive operations, reverse it order and store/process in correct order because of occuring dependencies. For example an announcement add event depends on category creation event.\n\n* **Store events locally for further processing.**\n\n  Try to retreive events data from Press Server and store them locally for futher processing to not cause Press Server wait for your    processing. Just store event content to your local event sotre (files, database) and process them in separate thread or in scheduled task (for example cron).\n  \n  The example with simple filestore is included in `/example` directory.\n\n## Example usage\n\nExample usage is in `/example` directory.\n\n```php\n\nuse GuzzleHttp\\Psr7\\ServerRequest;\nuse PressServerApi\\Callback\\OperationInterface;\nuse PressServerApi\\Callback\\Operation\\Factory\\Psr7Request\\OperationsFromRequestFactory;\nuse PressServerApi\\Callback\\Operation\\Factory\\OperationFactoryInterface;\nuse PressServerApi\\Callback\\Operation\\Factory\\AnnouncementOperationFactory;\nuse PressServerApi\\Callback\\Operation\\Factory\\AnnouncementDeleteOperationFactory;\nuse PressServerApi\\Callback\\Operation\\Factory\\AnnouncementPhotoOperationFactory;\nuse PressServerApi\\Callback\\Operation\\Factory\\AnnouncementPhotoDeleteOperationFactory;\nuse PressServerApi\\Callback\\Operation\\Factory\\CategoryOperationFactory;\nuse PressServerApi\\Callback\\Operation\\Factory\\CategoryDeleteOperationFactory;\nuse PressServerApi\\Callback\\Operation\\Factory\\UnknownOperationFactory;\nuse PressServerApi\\Callback\\OperationGroupProcessingResult;\nuse PressServerApi\\Callback\\OperationProcessingResult;\nuse PressServerApi\\Callback\\Response\\ProcessingResultResponseFactory;\nuse PressServerApi\\Callback\\Response\\Psr7Response\\ProcessingResultResponseFactory as ProcessingResultPsr7ResponseFactory;\n\nuse Example\\EventStore\\Event;\nuse Example\\EventStore\\EventStoreInterface;\nuse Example\\EventStore\\SimpleFilesystemEventStore;\nuse Example\\EventStore\\Exception\\EventAlreadyInStoreException;\n\nuse function QuimCalpe\\ResponseSender\\send AS send_response;\n\ninclude 'vendor/autoload.php';\n\n// Step 1. Configure Context (components).\n$responseFactory = new ProcessingResultResponseFactory();\n$responseFactoryPsr7 = new ProcessingResultPsr7ResponseFactory($responseFactory);\n\n/* @var $factories OperationFactoryInterface[] */\n$factories = [\n    new AnnouncementOperationFactory(),\n    new AnnouncementDeleteOperationFactory(),\n    new AnnouncementPhotoOperationFactory(),\n    new AnnouncementPhotoDeleteOperationFactory(),\n    new CategoryOperationFactory(),\n    new CategoryDeleteOperationFactory(),\n    new UnknownOperationFactory(),\n];\n\n$operationsFromRequestFactory = new OperationsFromRequestFactory($factories);\n\n// Step 2. Receive HTTP Request and get operations.\n$request = ServerRequest::fromGlobals();\n\n// validate\nif($request-\u003egetMethod() != \"POST\") {\n    return send_response(new \\GuzzleHttp\\Psr7\\Response(401));\n}\n\n/* @var $eventStore EventStoreInterface */\n$eventStore = new SimpleFilesystemEventStore('./eventstore');\n\n/* @var $operations OperationInterface[] */\n$operations = $operationsFromRequestFactory-\u003ecreateOperations($request);\n$operations = array_reverse($operations);\n\n$results = new OperationGroupProcessingResult();\n\nforeach($operations as $operation) {\n    // TODO process operation here...\n    // here there is storing events for further processing, which is recommended way\n    // to fast and reliable retrieve events from 3rd party callback\n    try {\n        $eventStore-\u003estore(new Event($operation-\u003egetOperationKey(), $operation));\n    }\n    catch(EventAlreadyInStoreException $e) {\n    }\n\n    // after processing, create the OperarionProcessingResult (success or failure)\n    $result = OperationProcessingResult::createResultSuccess($operation);\n    $results-\u003eaddResult($result);\n}\n\n// Step 3. Prepare response.\n$response = $responseFactoryPsr7-\u003ecreateProcessingResultResponse($results);\n\n// Step 4. Send response.\nreturn send_response($response);\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathlan%2Fpress-server-api-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fathlan%2Fpress-server-api-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathlan%2Fpress-server-api-client/lists"}