innobrain / laravel-onoffice-adapter
This is my package laravel-onoffice-adapter
Fund package maintenance!
Innobraingmbh
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- guzzlehttp/guzzle: ^7.8
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
- phpstan/extension-installer: ^1.3
- phpstan/phpstan-deprecation-rules: ^1.1
- phpstan/phpstan-phpunit: ^1.3
- dev-main
- v1.5.5
- v1.5.4
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- v0.13.6
- v0.13.5
- v0.13.4
- v0.13.3
- v0.13.2
- v0.13.1
- v0.13.0
- v0.12.4
- v0.12.3
- v0.12.2
- v0.12.1
- v0.12.0
- v0.11.0
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.1
- v0.9.0
- v0.8.6
- v0.8.5
- v0.8.4
- v0.8.3
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.7
- v0.7.6
- v0.7.5
- v0.7.4
- v0.7.3
- v0.7.2
- v0.7.1
- v0.7.0
- v0.6.0
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.0
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.0
- dev-feat/docs
- dev-feat/macro-resolve
- dev-feat/multi-connected-activities
- dev-feat/with-credentials
- dev-feat/allow-strings-as-resourcetype
- dev-default-fields-estates
- dev-feature/credential-validation
This package is auto-updated.
Last update: 2024-11-07 13:42:39 UTC
README
An onOffice adapter for Laravel
Installation
You can install the package via composer:
composer require innobrain/laravel-onoffice-adapter
You can publish the config file with:
php artisan vendor:publish --tag="laravel-onoffice-adapter-config"
This is the contents of the published config file:
return [ /** * The base URL of the OnOffice API. * Change that if you are using a different version of the API. */ 'base_url' => 'https://api.onoffice.de/api/stable/api.php', /** * The headers to be sent with the request. * Override this if you need to send additional headers. */ 'headers' => [ 'Content-Type' => 'application/json', 'Accept' => 'application/json', ], /** * Retry */ 'retry' => [ 'count' => 3, 'delay' => 200, 'only_on_connection_error' => true, ], /** * The token and secret to be used for authentication with the OnOffice API. */ 'token' => env('ON_OFFICE_TOKEN', ''), 'secret' => env('ON_OFFICE_SECRET', ''), ];
Usage
Repositories
- ActivityRepository
- AddressRepository
- EstateRepository
- FieldRepository
- FileRepository
- MarketplaceRepository
- RelationRepository
- SearchCriteriaRepository
- SettingRepository
Syntax for typical queries
$estates = EstateRepository::query() ->select('Id') ->where('status', 1) ->where('kaufpreis', '<', 30_000) ->orderBy('kaufpreis') ->orderByDesc('warmmiete') ->get(); $users = UserRepository::query() ->select([ 'Anrede', 'Vorname', 'Nachname', 'Mobil', ]) ->where('Nr', $this->userId) ->get();
Unusual queries
$success = MarketplaceRepository::query() ->unlockProvider($parameterCacheId, $extendedClaim);
$tmpUploadId = FileRepository::upload() ->save(base64_encode($fileContent)); $success = FileRepository::upload()->link($tmpUploadId, [ 'module' => 'estate', 'relatedRecordId' => '12345', ]); // or $success = FileRepository::upload() ->uploadInBlocks() ->saveAndLink(base64_encode($fileContent), [ 'module' => 'estate', 'relatedRecordId' => '12345', ]);
ActivityRepository::query() ->addressIds($recordIds) ->estateId($estateId) ->create([ 'datetime' => $event->getDateFormatted(), 'actionkind' => 'Newsletter', 'actiontype' => 'Hard Bounce', 'note' => $message, ]);
Config::set('onoffice.token', 'token'); Config::set('onoffice.secret', 'secret'); Config::set('onoffice.api_claim', 'api_claim');
Middlewares
use Illuminate\Support\Facades\Log; use Innobrain\OnOfficeAdapter\Facades\BaseRepository; BaseRepository::query() ->before(static function (OnOfficeRequest $request) { Log::info('About to send request', [ 'request' => $request->toArray(), ]); }) ->call(new OnOfficeRequest( OnOfficeAction::Read, OnOfficeResourceType::Estate, ));
Debugging
use Innobrain\OnOfficeAdapter\Facades\BaseRepository; BaseRepository::query() ->dd() ->call(new OnOfficeRequest( OnOfficeAction::Read, OnOfficeResourceType::Estate, ));
use Innobrain\OnOfficeAdapter\Facades\BaseRepository; BaseRepository::record(); BaseRepository::query() ->call(new OnOfficeRequest( OnOfficeAction::Read, OnOfficeResourceType::Estate, )); $result = BaseRepository::lastRecorded(); /* $result = [ OnOfficeRequest, OnOfficeResponse, ]; */
Default Fields
Sometimes, it can be useful to have default fields for your queries to quickly glance at data. You can find a selection of default fields in the OnOfficeService.
use Innobrain\OnOfficeAdapter\Facades\EstateRepository; use Innobrain\OnOfficeAdapter\Services\OnOfficeService; $estates = EstateRepository::query() ->select(OnOfficeService::DEFAULT_ESTATE_INFO_FIELDS) ->get();
Helpers
When using default fields, you might find it helpful to hide all
empty fields. To do so, use the clean_elements
helper.
It will work with both find
and get
responses.
use Innobrain\OnOfficeAdapter\Facades\EstateRepository; use Innobrain\OnOfficeAdapter\Services\OnOfficeService; $estates = EstateRepository::query() ->select(OnOfficeService::DEFAULT_ESTATE_INFO_FIELDS) ->get(); // will leave out fields with empty values like "", "0.00", [], or null. $estates = clean_elements($estates);
Usage in tests
use Innobrain\OnOfficeAdapter\Facades\EstateRepository; EstateRepository::fake(EstateRepository::response([ EstateRepository::page(recordFactories: [ EstateFactory::make() ->id(1), ]), ])); $response = EstateRepository::query()->get(); expect($response->count())->toBe(1) ->and($response->first()['id'])->toBe(1); EstateRepository::assertSentCount(1);
use Innobrain\OnOfficeAdapter\Facades\EstateRepository; EstateRepository::fake(EstateRepository::response([ EstateRepository::page(recordFactories: [ EstateFactory::make() ->id(1), ]), EstateRepository::page(recordFactories: [ EstateFactory::make() ->id(2), ]), ])); $response = EstateRepository::query()->get(); expect($response->count())->toBe(2) ->and($response->first()['id'])->toBe(1) ->and($response->last()['id'])->toBe(2); EstateRepository::assertSentCount(2);
use Innobrain\OnOfficeAdapter\Facades\EstateRepository; EstateRepository::preventStrayRequests(); EstateRepository::fake([ EstateRepository::response([ EstateRepository::page(recordFactories: [ EstateFactory::make() ->id(1), ]), EstateRepository::page(recordFactories: [ EstateFactory::make() ->id(2), ]), ]), EstateRepository::response([ EstateRepository::page(recordFactories: [ EstateFactory::make() ->id(3), ]), EstateRepository::page(recordFactories: [ EstateFactory::make() ->id(4), ]), ]), ]); $response = EstateRepository::query()->get(); expect($response->count())->toBe(2) ->and($response->first()['id'])->toBe(1) ->and($response->last()['id'])->toBe(2); $response = EstateRepository::query()->get(); expect($response->count())->toBe(2) ->and($response->first()['id'])->toBe(3) ->and($response->last()['id'])->toBe(4); EstateRepository::assertSentCount(4); $response = EstateRepository::query()->get(); // throws StrayRequestException
use Innobrain\OnOfficeAdapter\Facades\EstateRepository; EstateRepository::preventStrayRequests(); EstateRepository::fake(EstateRepository::sequence( EstateRepository::response([ EstateRepository::page(recordFactories: EstateFactory::times(20)), ]), times: 30, )); for ($i = 0; $i < 30; ++$i) { $response = EstateRepository::query()->get(); expect($response->count())->toBe(20); }
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.